Add command/event feedback

This commit is contained in:
Gabriel Tofvesson 2021-04-25 00:11:55 +02:00
parent 7665618c22
commit 7a0fd842c9
2 changed files with 28 additions and 6 deletions

View File

@ -1,5 +1,6 @@
package dev.w1zzrd.invtweaks.command; package dev.w1zzrd.invtweaks.command;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -11,10 +12,18 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.logging.Logger;
import static dev.w1zzrd.invtweaks.InvTweaksPlugin.LOG_PLUGIN_NAME;
public class MagnetCommandExecutor implements CommandExecutor { public class MagnetCommandExecutor implements CommandExecutor {
private static final Logger logger = Bukkit.getLogger();
/** /**
* List of players with magnet mode active * List of players with magnet mode active
*/ */
@ -53,7 +62,10 @@ public class MagnetCommandExecutor implements CommandExecutor {
if (!(sender instanceof Player)) if (!(sender instanceof Player))
return false; return false;
toggleMagnet((Player) sender); final boolean isMagnetActive = toggleMagnet((Player) sender);
logger.fine(LOG_PLUGIN_NAME + " Player " + sender.getName() + (isMagnetActive ? " " : " de-") + "activated magnet");
sender.spigot().sendMessage(new TextComponent((isMagnetActive ? "Enabled" : "Disabled") + " magnetism"));
return true; return true;
} }
@ -180,13 +192,16 @@ public class MagnetCommandExecutor implements CommandExecutor {
* disabled. * disabled.
*/ */
private void updateMagnetismTask() { private void updateMagnetismTask() {
if (refreshTask == null && activeMagnets.size() > 0 && plugin.isEnabled()) if (refreshTask == null && activeMagnets.size() > 0 && plugin.isEnabled()) {
refreshTask = Bukkit.getScheduler().runTaskTimer(plugin, this::taskApplyMagnetism, 0, interval); refreshTask = Bukkit.getScheduler().runTaskTimer(plugin, this::taskApplyMagnetism, 0, interval);
logger.info(LOG_PLUGIN_NAME + " Activated magnetism check task");
}
else if (refreshTask != null && (activeMagnets.size() == 0 || !plugin.isEnabled())) { else if (refreshTask != null && (activeMagnets.size() == 0 || !plugin.isEnabled())) {
Bukkit.getScheduler().cancelTask(refreshTask.getTaskId()); Bukkit.getScheduler().cancelTask(refreshTask.getTaskId());
refreshTask = null; refreshTask = null;
activeMagnets.clear(); activeMagnets.clear();
divIndex = 0; divIndex = 0;
logger.info(LOG_PLUGIN_NAME + " De-activated magnetism check task");
} }
} }

View File

@ -1,5 +1,6 @@
package dev.w1zzrd.invtweaks.command; package dev.w1zzrd.invtweaks.command;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.*; import org.bukkit.block.*;
@ -46,12 +47,18 @@ public class SortCommandExecutor implements CommandExecutor {
final BlockState target = targetBlock.getState(); final BlockState target = targetBlock.getState();
// Sort appropriate inventory holder // Sort appropriate inventory holder
if (target instanceof Chest) if (target instanceof Chest) {
sortChest((Chest) target); sortChest((Chest) target);
else if (target instanceof ShulkerBox) player.spigot().sendMessage(new TextComponent("Sorted chest"));
}
else if (target instanceof ShulkerBox) {
sortShulkerBox((ShulkerBox) target); sortShulkerBox((ShulkerBox) target);
else player.spigot().sendMessage(new TextComponent("Sorted shulker box"));
}
else {
sortPlayer(player); sortPlayer(player);
player.spigot().sendMessage(new TextComponent("Sorted inventory"));
}
return true; return true;
} }