Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,13 @@ public enum Permission {
ESSENTIALS_ITEM_LORE_SET,
ESSENTIALS_PAY_TOGGLE,
ESSENTIALS_PAY_TOGGLE_OTHER,
ESSENTIALS_PAY_NOTIFICATION_TOGGLE("Toggle receiving pay notifications"),
ESSENTIALS_PAY_NOTIFICATION_TOGGLE_OTHER("Toggle receiving pay notifications for other players"),
ESSENTIALS_MESSAGE_TOGGLE_OTHER,
ESSENTIALS_TP_TOGGLE("Toggle receiving teleport requests"),
ESSENTIALS_TP_TOGGLE_OTHER("Toggle receiving teleport requests for other players"),
ESSENTIALS_TPA_HERE_TOGGLE("Toggle receiving tpahere requests"),
ESSENTIALS_TPA_HERE_TOGGLE_OTHER("Toggle receiving tpahere requests for other players"),
ESSENTIALS_GIVE,
ESSENTIALS_GIVE_ALL,
ESSENTIALS_ITEM_LORE_CLEAR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public enum Message {
DESCRIPTION_ECO_SHOW("Show player money"),
DESCRIPTION_PAY("Pays another player from your balance"),
DESCRIPTION_PAY_TOGGLE("Activate or not the receipt of money"),
DESCRIPTION_PAY_NOTIFICATION_TOGGLE("Toggle receiving pay notifications"),
DESCRIPTION_SET_SPAWN("Set server spawn"),
DESCRIPTION_SET_FIRST_SPAWN("Set server first spawn"),
DESCRIPTION_SPAWN("Teleport to spawn"),
Expand Down Expand Up @@ -282,6 +283,7 @@ public enum Message {
DESCRIPTION_REPLY("Reply to a private message"),
DESCRIPTION_MESSAGE_TOGGLE("Toggle private message"),
DESCRIPTION_TP_TOGGLE("Toggle receiving teleport requests"),
DESCRIPTION_TPA_HERE_TOGGLE("Toggle receiving tpahere requests"),
DESCRIPTION_POWER_TOOLS_TOGGLE("Toggle power tools"),
DESCRIPTION_SOCIALSPY("Display private messages of players"),
DESCRIPTION_COMPACT_ALL("Compact items in your inventories"),
Expand Down Expand Up @@ -690,11 +692,16 @@ public enum Message {
COMMAND_SOCIAL_SPY_DISABLE("&7Social spy <error>disable &7for &f%player%<error>."),
COMMAND_PAY_TOGGLE_ENABLE("&7Pay <success>enable &7for &f%player%<success>."),
COMMAND_PAY_TOGGLE_DISABLE("<error>All of your power tools have been disabled &7for &f%player%<error>."),
COMMAND_PAY_NOTIFICATION_TOGGLE_ENABLE("&7Pay notifications <success>enabled &7for &f%player%<success>."),
COMMAND_PAY_NOTIFICATION_TOGGLE_DISABLE("&7Pay notifications <error>disabled &7for &f%player%<error>."),
COMMAND_POWER_TOOLS_TOGGLE_ENABLE("<success>All of your power tools have been enabled &7for &f%player%<success>."),
COMMAND_POWER_TOOLS_TOGGLE_DISABLE("&7Pay <error>disable &7for &f%player%<error>."),
COMMAND_TELEPORT_REQUEST_DISABLED("<error>The player &f%player%<error> has disabled teleport requests."),
COMMAND_TP_TOGGLE_ENABLE("&7Teleport requests <success>enabled &7for &f%player%<success>."),
COMMAND_TP_TOGGLE_DISABLE("&7Teleport requests <error>disabled &7for &f%player%<error>."),
COMMAND_TELEPORT_HERE_REQUEST_DISABLED("<error>The player &f%player%<error> has disabled tpahere requests."),
COMMAND_TPA_HERE_TOGGLE_ENABLE("&7Tpahere requests <success>enabled &7for &f%player%<success>."),
COMMAND_TPA_HERE_TOGGLE_DISABLE("&7Tpahere requests <error>disabled &7for &f%player%<error>."),

COMMAND_FURNACE_TYPE("<error>Impossible to smelt the material &f%material%<error>."),
COMMAND_FURNACE_ERROR("<error>You have no &f%item%<error> in your inventory."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ public enum Option {
WORLDEDIT_BOSSBAR_DISABLE,
TELEPORT_REQUEST_DISABLE,
DEATH_MESSAGE_DISABLE,
PAY_NOTIFICATION_DISABLE,
TELEPORT_HERE_REQUEST_DISABLE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import fr.maxlego08.essentials.commands.commands.economy.CommandEconomy;
import fr.maxlego08.essentials.commands.commands.economy.CommandMoney;
import fr.maxlego08.essentials.commands.commands.economy.CommandPay;
import fr.maxlego08.essentials.commands.commands.economy.CommandPayNotificationToggle;
import fr.maxlego08.essentials.commands.commands.economy.CommandPayToggle;
import fr.maxlego08.essentials.commands.commands.enderchest.CommandEnderChest;
import fr.maxlego08.essentials.commands.commands.enderchest.CommandEnderSee;
Expand Down Expand Up @@ -50,6 +51,7 @@
import fr.maxlego08.essentials.commands.commands.messages.CommandMessageToggle;
import fr.maxlego08.essentials.commands.commands.messages.CommandReply;
import fr.maxlego08.essentials.commands.commands.messages.CommandSocialSpy;
import fr.maxlego08.essentials.commands.commands.teleport.CommandTpaHereToggle;
import fr.maxlego08.essentials.commands.commands.teleport.CommandTpToggle;
import fr.maxlego08.essentials.commands.commands.sanction.CommandBan;
import fr.maxlego08.essentials.commands.commands.sanction.CommandFreeze;
Expand Down Expand Up @@ -196,6 +198,7 @@ public void loadCommands(CommandManager commandManager) {
register("money", CommandMoney.class, "balance");
register("pay", CommandPay.class);
register("paytoggle", CommandPayToggle.class);
register("paynotificationtoggle", CommandPayNotificationToggle.class, "paynotify");

register("setfirstspawn", CommandSetFirstSpawn.class);
register("setspawn", CommandSetSpawn.class);
Expand Down Expand Up @@ -236,6 +239,7 @@ public void loadCommands(CommandManager commandManager) {
register("reply", CommandReply.class, "r");
register("messagetoggle", CommandMessageToggle.class, "msgtoggle", "mtg");
register("tptoggle", CommandTpToggle.class);
register("tpaheretoggle", CommandTpaHereToggle.class);
register("socialspy", CommandSocialSpy.class);

register("repair", CommandRepair.class, "fix");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package fr.maxlego08.essentials.commands.commands.economy;

import fr.maxlego08.essentials.api.EssentialsPlugin;
import fr.maxlego08.essentials.api.commands.CommandResultType;
import fr.maxlego08.essentials.api.commands.Permission;
import fr.maxlego08.essentials.api.messages.Message;
import fr.maxlego08.essentials.api.user.Option;
import fr.maxlego08.essentials.api.user.User;
import fr.maxlego08.essentials.module.modules.economy.EconomyModule;
import fr.maxlego08.essentials.zutils.utils.commands.VCommand;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class CommandPayNotificationToggle extends VCommand {

public CommandPayNotificationToggle(EssentialsPlugin plugin) {
super(plugin);
this.setModule(EconomyModule.class);
this.setPermission(Permission.ESSENTIALS_PAY_NOTIFICATION_TOGGLE);
this.setDescription(Message.DESCRIPTION_PAY_NOTIFICATION_TOGGLE);
this.onlyPlayers();
this.addOptionalArg("player");
}

@Override
protected CommandResultType perform(EssentialsPlugin plugin) {

Player player = this.argAsPlayer(0, this.player);

if (player == null) {
return CommandResultType.SYNTAX_ERROR;
}

if (player.equals(this.player) || !hasPermission(sender, Permission.ESSENTIALS_PAY_NOTIFICATION_TOGGLE_OTHER)) {
togglePayNotification(player, this.user, sender);
} else {
User otherUser = getUser(player);
if (otherUser == null) return CommandResultType.SYNTAX_ERROR;
togglePayNotification(player, otherUser, sender);
}

return CommandResultType.SUCCESS;
}

private void togglePayNotification(Player player, User user, CommandSender sender) {

user.setOption(Option.PAY_NOTIFICATION_DISABLE, !user.getOption(Option.PAY_NOTIFICATION_DISABLE));
boolean isPayNotificationDisable = user.getOption(Option.PAY_NOTIFICATION_DISABLE);

Message messageKey = isPayNotificationDisable ? Message.COMMAND_PAY_NOTIFICATION_TOGGLE_DISABLE : Message.COMMAND_PAY_NOTIFICATION_TOGGLE_ENABLE;
message(sender, messageKey, "%player%", user == this.user ? Message.YOU.getMessageAsString() : player.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/**
* Command to toggle receiving teleport requests.
* Allows players to enable/disable receiving TPA and TPAHERE requests from other players.
* Allows players to enable/disable receiving TPA requests from other players.
*/
public class CommandTpToggle extends VCommand {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package fr.maxlego08.essentials.commands.commands.teleport;

import fr.maxlego08.essentials.api.EssentialsPlugin;
import fr.maxlego08.essentials.api.commands.CommandResultType;
import fr.maxlego08.essentials.api.commands.Permission;
import fr.maxlego08.essentials.api.messages.Message;
import fr.maxlego08.essentials.api.user.Option;
import fr.maxlego08.essentials.api.user.User;
import fr.maxlego08.essentials.module.modules.TeleportationModule;
import fr.maxlego08.essentials.zutils.utils.commands.VCommand;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class CommandTpaHereToggle extends VCommand {

public CommandTpaHereToggle(EssentialsPlugin plugin) {
super(plugin);
this.setModule(TeleportationModule.class);
this.setPermission(Permission.ESSENTIALS_TPA_HERE_TOGGLE);
this.setDescription(Message.DESCRIPTION_TPA_HERE_TOGGLE);
this.addOptionalArg("player");
}

@Override
protected CommandResultType perform(EssentialsPlugin plugin) {

Player player = this.argAsPlayer(0, this.player);

if (player == null) {
return CommandResultType.SYNTAX_ERROR;
}

if (player.equals(this.player) || !hasPermission(sender, Permission.ESSENTIALS_TPA_HERE_TOGGLE_OTHER)) {
toggleTeleportHereRequest(player, this.user, sender);
} else {
User otherUser = getUser(player);
if (otherUser == null) return CommandResultType.SYNTAX_ERROR;
toggleTeleportHereRequest(player, otherUser, sender);
}

return CommandResultType.SUCCESS;
}

private void toggleTeleportHereRequest(Player player, User user, CommandSender sender) {

user.setOption(Option.TELEPORT_HERE_REQUEST_DISABLE, !user.getOption(Option.TELEPORT_HERE_REQUEST_DISABLE));
boolean isTeleportHereRequestDisable = user.getOption(Option.TELEPORT_HERE_REQUEST_DISABLE);

Message messageKey = isTeleportHereRequestDisable ? Message.COMMAND_TPA_HERE_TOGGLE_DISABLE : Message.COMMAND_TPA_HERE_TOGGLE_ENABLE;
message(sender, messageKey, "%player%", user == this.user ? Message.YOU.getMessageAsString() : player.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ private CommandResultType strikeSinglePlayer() {
}

private void strike(Location location, boolean visual) {
if (visual) {
location.getWorld().strikeLightning(location);
} else {
location.getWorld().strikeLightningEffect(location);
}
this.plugin.getScheduler().runAtLocation(location, wrappedTask -> {
if (visual) {
location.getWorld().strikeLightning(location);
} else {
location.getWorld().strikeLightningEffect(location);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public CommandRepair(EssentialsPlugin plugin) {
super(plugin);
this.setPermission(Permission.ESSENTIALS_REPAIR);
this.setDescription(Message.DESCRIPTION_REPAIR);
onlyPlayers();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected CommandResultType perform(EssentialsPlugin plugin) {
if (smooth) {
TimeTransition.transitionWorldTime(plugin, world, dayTime);
} else {
world.setFullTime(dayTime);
plugin.getScheduler().runNextTick(wrappedTask -> world.setFullTime(dayTime));
}

message(sender, Message.COMMAND_DAY, "%world%", world.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected CommandResultType perform(EssentialsPlugin plugin) {
if (smooth) {
TimeTransition.transitionWorldTime(plugin, world, nightTime);
} else {
world.setFullTime(nightTime);
plugin.getScheduler().runNextTick(wrappedTask -> world.setFullTime(nightTime));
}

message(sender, Message.COMMAND_NIGHT, "%world%", world.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ protected CommandResultType perform(EssentialsPlugin plugin) {
World world = this.argAsWorld(0, isPlayer() ? this.player.getWorld() : null);
if (world == null) return CommandResultType.SYNTAX_ERROR;

world.setStorm(false);
world.setThunderDuration(0);
world.setThundering(false);
plugin.getScheduler().runNextTick(wrappedTask -> {
world.setStorm(false);
world.setThunderDuration(0);
world.setThundering(false);
});

message(this.sender, Message.COMMAND_SUN, "%world%", world.getName());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package fr.maxlego08.essentials.commands.commands.weather;

import com.tcoded.folialib.wrapper.task.WrappedTask;
import fr.maxlego08.essentials.api.EssentialsPlugin;
import org.bukkit.World;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;

/**
* Utility class for smooth time transitions in worlds and for players
Expand All @@ -23,25 +24,28 @@ static void transitionWorldTime(EssentialsPlugin plugin, World world, long targe
UUID worldId = world.getUID();
TIME_CHANGING_WORLDS.add(worldId);

long startTime = world.getFullTime();
long diff = (targetTime - startTime + 24000) % 24000;

new BukkitRunnable() {
plugin.getScheduler().runTimer(new Consumer<>() {
long progressed = 0;
long diff = -1;

@Override
public void run() {
public void accept(WrappedTask wrappedTask) {
if (diff == -1) {
long startTime = world.getFullTime();
diff = (targetTime - startTime + 24000) % 24000;
}

if (progressed >= diff) {
world.setFullTime(targetTime);
TIME_CHANGING_WORLDS.remove(worldId);
cancel();
wrappedTask.cancel();
return;
}

world.setFullTime(world.getFullTime() + WORLD_TIME_STEP);
progressed += WORLD_TIME_STEP;
}
}.runTaskTimer(plugin, 0L, 1L);
}, 1L, 1L);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import fr.maxlego08.essentials.api.event.events.user.UserQuitEvent;
import fr.maxlego08.essentials.api.messages.Message;
import fr.maxlego08.essentials.api.storage.IStorage;
import fr.maxlego08.essentials.api.user.Option;
import fr.maxlego08.essentials.api.user.User;
import fr.maxlego08.essentials.module.ZModule;
import fr.maxlego08.menu.api.engine.Pagination;
Expand Down Expand Up @@ -362,7 +363,11 @@ public void pay(UUID fromUuid, String fromName, UUID toUuid, String toName, Econ
perform(toUuid, user -> user.deposit(fromUuid, economy, amount, this.payDepositReason.replace("%player%", fromName)));

message(fromUuid, Message.COMMAND_PAY_SENDER, "%amount%", this.format(economy, amount), "%player%", toName);
message(toUuid, Message.COMMAND_PAY_RECEIVER, "%amount%", this.format(economy, amount), "%player%", fromName);
this.plugin.getStorageManager().getStorage().getOption(toUuid, Option.PAY_NOTIFICATION_DISABLE, isDisable -> {
if (!isDisable) {
message(toUuid, Message.COMMAND_PAY_RECEIVER, "%amount%", this.format(economy, amount), "%player%", fromName);
}
});
}

@Override
Expand Down
30 changes: 17 additions & 13 deletions src/main/java/fr/maxlego08/essentials/user/ZUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,8 @@ public void sendTeleportHereRequest(User targetUser) {
return;
}

// Check if target user has disabled teleport requests
if (targetUser.getOption(Option.TELEPORT_REQUEST_DISABLE)) {
message(this, Message.COMMAND_TELEPORT_REQUEST_DISABLED, targetUser);
if (targetUser.getOption(Option.TELEPORT_HERE_REQUEST_DISABLE)) {
message(this, Message.COMMAND_TELEPORT_HERE_REQUEST_DISABLED, targetUser);
return;
}

Expand Down Expand Up @@ -394,18 +393,23 @@ private void teleport(TeleportationModule teleportationModule, Location toLocati
Player player = this.getPlayer();
if (player == null) return;

Location location = player.isFlying() ? toLocation : teleportationModule.isTeleportSafety() ? toSafeLocation(toLocation) : toLocation;
boolean isFlying = player.isFlying();

if (teleportationModule.isTeleportToCenter()) {
location = location.getBlock().getLocation().add(0.5, 0, 0.5);
location.setYaw(toLocation.getYaw());
location.setPitch(toLocation.getPitch());
}
this.plugin.getScheduler().runAtLocation(toLocation, wrappedTask -> {

this.teleportNow(location);
if (message != null) {
message(this, message, args);
}
Location location = isFlying ? toLocation : teleportationModule.isTeleportSafety() ? toSafeLocation(toLocation) : toLocation;

if (teleportationModule.isTeleportToCenter()) {
location = location.getBlock().getLocation().add(0.5, 0, 0.5);
location.setYaw(toLocation.getYaw());
location.setPitch(toLocation.getPitch());
}

this.teleportNow(location);
if (message != null) {
message(this, message, args);
}
});
}

@Override
Expand Down
Loading
Loading