diff --git a/build.gradle b/build.gradle index d8c16ea..5d11fdb 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'me.redtea' -version = '1.0.3a-SNAPSHOT' +version = '1.0.3b-SNAPSHOT' repositories { mavenCentral() diff --git a/src/main/java/me/redtea/nodropx/NoDropX.java b/src/main/java/me/redtea/nodropx/NoDropX.java index 5382a57..d5d72d0 100644 --- a/src/main/java/me/redtea/nodropx/NoDropX.java +++ b/src/main/java/me/redtea/nodropx/NoDropX.java @@ -105,6 +105,7 @@ public final class NoDropX extends JavaPlugin { noDropCosmeticService.add(textContext.getLoreStrategy()); noDropCosmeticService.load(YamlConfiguration.loadConfiguration(textContext.getCosmetics())); + dropConfirmService = getConfig().getBoolean("confirmThrowNoDropItem") ? new DropConfirmServiceImpl() : new DropConfirmNull(); NBTService nbtService = new Tr7zwNBTServiceImpl(); noDropService = new NoDropServiceImpl(nbtService, noDropCosmeticService); NoDropItemFactory noDropItemFactory = new NoDropItemFactoryImpl(noDropService); @@ -123,7 +124,6 @@ public final class NoDropX extends JavaPlugin { .build(); itemStackService = initItemStackService(); - dropConfirmService = getConfig().getBoolean("confirmThrowNoDropItem") ? new DropConfirmServiceImpl() : new DropConfirmNull(); menuFacade = initMenus(); StorageService storageService = new StorageServiceImpl(menuFacade, personalStorageRepo, noDropService); @@ -147,7 +147,7 @@ public final class NoDropX extends JavaPlugin { commandManager.getMessageHandler().register("cmd.no.exists", sender -> messages.get("noExists").send(sender)); commandManager.getMessageHandler().register("cmd.wrong.usage", sender -> messages.get("usage").send(sender)); commandManager.getCompletionHandler().register("#materials", input -> itemStackService.allMaterials()); - commandManager.register(new NoDropCommand(messages, noDropAPI, menuFacade, this, itemStackService)); + commandManager.register(new NoDropCommand(messages, noDropAPI, menuFacade, this, itemStackService, dropConfirmService)); bStatsInit(); printCredits(); checkUpdates(); diff --git a/src/main/java/me/redtea/nodropx/command/NoDropCommand.java b/src/main/java/me/redtea/nodropx/command/NoDropCommand.java index 5c20568..8b5fc31 100644 --- a/src/main/java/me/redtea/nodropx/command/NoDropCommand.java +++ b/src/main/java/me/redtea/nodropx/command/NoDropCommand.java @@ -8,8 +8,10 @@ import me.redtea.nodropx.NoDropX; import me.redtea.nodropx.api.facade.NoDropAPI; import me.redtea.nodropx.menu.facade.MenuFacade; import me.redtea.nodropx.libs.message.container.Messages; +import me.redtea.nodropx.service.dropconfirm.DropConfirmService; import me.redtea.nodropx.service.material.ItemStackService; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -30,6 +32,7 @@ public class NoDropCommand extends CommandBase { private final MenuFacade menuFacade; private final NoDropX plugin; private final ItemStackService itemStackService; + private final DropConfirmService confirmService; @Default public void onDefault(final CommandSender sender) { @@ -90,6 +93,60 @@ public class NoDropCommand extends CommandBase { } + @SubCommand("ignoreConfirm") + @Permission("nodropx.ignoreConfirm") + public void onIgnoreConfirm(final CommandSender sender, @Optional Player target) { + if(target == null) { + if(!(sender instanceof Player)) { + sender.sendMessage("player only"); + return; + } else { + confirmService.forceConfirm((Player) sender); + } + } else { + confirmService.forceConfirm(target); + } + } + + @SubCommand("ignoreConfirmTimed") + @Permission("nodropx.ignoreConfirm.timed") + public void onIgnoreConfirmTimed(final CommandSender sender, Integer sec, @Optional Player target) { + if(target == null) { + if(!(sender instanceof Player)) { + sender.sendMessage("player only"); + return; + } else { + confirmService.forceConfirm((Player) sender); + try { + Bukkit.getScheduler().runTaskLater(plugin,() -> confirmService.removeForceConfirm((Player) sender),20L*sec); + } catch (UnsupportedOperationException e) { + sender.sendMessage(ChatColor.RED + "This operation didn't supports on your environment"); + } + } + } else { + confirmService.forceConfirm(target); + try { + Bukkit.getScheduler().runTaskLater(plugin,() -> confirmService.removeForceConfirm(target),20L*sec); + } catch (UnsupportedOperationException e) { + sender.sendMessage(ChatColor.RED + "This operation didn't supports on your environment"); + } + } + } + + @SubCommand("noIgnoreConfirm") + @Permission("nodropx.noIgnoreConfirm") + public void onNoIgnoreConfirm(final CommandSender sender, @Optional Player target) { + if(target == null) { + if(!(sender instanceof Player)) { + sender.sendMessage("player only"); + return; + } else { + confirmService.removeForceConfirm((Player) sender); + } + } else { + confirmService.removeForceConfirm(target); + } + } @SubCommand("applyHand") @Permission("nodropx.applyhand") public void onApplyHand(final Player sender) { diff --git a/src/main/java/me/redtea/nodropx/listener/PlayerHandler.java b/src/main/java/me/redtea/nodropx/listener/PlayerHandler.java index 8ad8bfb..313b4cb 100644 --- a/src/main/java/me/redtea/nodropx/listener/PlayerHandler.java +++ b/src/main/java/me/redtea/nodropx/listener/PlayerHandler.java @@ -3,6 +3,7 @@ package me.redtea.nodropx.listener; import lombok.RequiredArgsConstructor; import me.redtea.nodropx.api.event.NoDropItemThrownEvent; import me.redtea.nodropx.menu.facade.MenuFacade; +import me.redtea.nodropx.service.dropconfirm.DropConfirmService; import me.redtea.nodropx.service.event.EventService; import me.redtea.nodropx.service.nodrop.NoDropService; import me.redtea.nodropx.service.respawn.RespawnService; @@ -14,7 +15,10 @@ import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; +import java.util.HashSet; import java.util.Optional; +import java.util.Set; +import java.util.UUID; @RequiredArgsConstructor public class PlayerHandler implements Listener { diff --git a/src/main/java/me/redtea/nodropx/service/dropconfirm/DropConfirmService.java b/src/main/java/me/redtea/nodropx/service/dropconfirm/DropConfirmService.java index d5def24..595aeee 100644 --- a/src/main/java/me/redtea/nodropx/service/dropconfirm/DropConfirmService.java +++ b/src/main/java/me/redtea/nodropx/service/dropconfirm/DropConfirmService.java @@ -6,4 +6,7 @@ public interface DropConfirmService { boolean isConfirmed(Player player); void confirm(Player player); void resetConfirm(Player player); + + void forceConfirm(Player player); + void removeForceConfirm(Player player); } diff --git a/src/main/java/me/redtea/nodropx/service/dropconfirm/impl/DropConfirmNull.java b/src/main/java/me/redtea/nodropx/service/dropconfirm/impl/DropConfirmNull.java index b52cb0b..dc92291 100644 --- a/src/main/java/me/redtea/nodropx/service/dropconfirm/impl/DropConfirmNull.java +++ b/src/main/java/me/redtea/nodropx/service/dropconfirm/impl/DropConfirmNull.java @@ -18,4 +18,14 @@ public class DropConfirmNull implements DropConfirmService { public void resetConfirm(Player player) { } + + @Override + public void forceConfirm(Player player) { + + } + + @Override + public void removeForceConfirm(Player player) { + + } } diff --git a/src/main/java/me/redtea/nodropx/service/dropconfirm/impl/DropConfirmServiceImpl.java b/src/main/java/me/redtea/nodropx/service/dropconfirm/impl/DropConfirmServiceImpl.java index aa470b8..2734b6f 100644 --- a/src/main/java/me/redtea/nodropx/service/dropconfirm/impl/DropConfirmServiceImpl.java +++ b/src/main/java/me/redtea/nodropx/service/dropconfirm/impl/DropConfirmServiceImpl.java @@ -9,8 +9,10 @@ import java.util.UUID; public class DropConfirmServiceImpl implements DropConfirmService { private Set confirmed = new HashSet<>(); + private Set force = new HashSet<>(); @Override public boolean isConfirmed(Player player) { + if(force.contains(player.getUniqueId()) || player.isDead()) return true; return confirmed.contains(player.getUniqueId()); } @@ -24,4 +26,14 @@ public class DropConfirmServiceImpl implements DropConfirmService { confirmed.remove(player.getUniqueId()); } + @Override + public void forceConfirm(Player player) { + force.add(player.getUniqueId()); + } + + @Override + public void removeForceConfirm(Player player) { + force.remove(player.getUniqueId()); + } + } diff --git a/src/main/java/me/redtea/nodropx/service/respawn/impl/RespawnServiceImpl.java b/src/main/java/me/redtea/nodropx/service/respawn/impl/RespawnServiceImpl.java index c91fe94..64ce01f 100644 --- a/src/main/java/me/redtea/nodropx/service/respawn/impl/RespawnServiceImpl.java +++ b/src/main/java/me/redtea/nodropx/service/respawn/impl/RespawnServiceImpl.java @@ -7,6 +7,7 @@ import lombok.ToString; import me.redtea.nodropx.api.event.NoDropItemDropOnDeathEvent; import me.redtea.nodropx.libs.carcadex.repo.Repo; import me.redtea.nodropx.service.capasity.CapacityService; +import me.redtea.nodropx.service.dropconfirm.DropConfirmService; import me.redtea.nodropx.service.nodrop.NoDropService; import me.redtea.nodropx.service.respawn.RespawnService; import org.bukkit.Bukkit; @@ -31,7 +32,6 @@ public class RespawnServiceImpl implements RespawnService { for(Pair pair : pairs) player.getInventory().setItem(pair.slot, pair.item); toRespawn.remove(player.getName()); } - player.updateInventory(); } @Override diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index de43bdc..57240af 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -4,8 +4,10 @@ forceUseFoliaPatches: false checkForUpdates: true -confirmThrowNoDropItem: true +# Not recommended on Forge servers! +# Use it on your own risk +confirmThrowNoDropItem: false #Single did not supports minimessages! -#Can be SINGLE_PAGE or MULTI_PAGES +#Can be SINGLE_PAGE or MULTI_PAGES (Use MULTI_PAGES on your own risk) personalStorageType: SINGLE_PAGE