diff --git a/lang/en-us.yml b/lang/en-us.yml index feb81df..c6a9493 100644 --- a/lang/en-us.yml +++ b/lang/en-us.yml @@ -226,6 +226,7 @@ actions: p: mounted n: unmounted msg: messaged + nametag: name tagged nationbank: p: deposited n: withdrew diff --git a/lang/ru-ru.yml b/lang/ru-ru.yml index a652bb1..823fc27 100644 --- a/lang/ru-ru.yml +++ b/lang/ru-ru.yml @@ -210,6 +210,7 @@ actions: townbank: p: внёс n: снял + nametag: имя помечено nationcreate: создал нацию nationrename: переменовал нацию nationdelete: удалил нацию diff --git a/pom.xml b/pom.xml index 87066d3..ce264fa 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 AuxProtect AuxProtect - 1.2.5.2 + 1.2.6-pre1 AuxProtect ${project.artifactId}-${project.version} diff --git a/src/main/java/dev/heliosares/auxprotect/database/EntryAction.java b/src/main/java/dev/heliosares/auxprotect/database/EntryAction.java index 60a3c75..4cec6c2 100644 --- a/src/main/java/dev/heliosares/auxprotect/database/EntryAction.java +++ b/src/main/java/dev/heliosares/auxprotect/database/EntryAction.java @@ -1,7 +1,7 @@ package dev.heliosares.auxprotect.database; -import dev.heliosares.auxprotect.api.AuxProtectAPI; import dev.heliosares.auxprotect.adapters.sender.SenderAdapter; +import dev.heliosares.auxprotect.api.AuxProtectAPI; import dev.heliosares.auxprotect.core.APPermission; import dev.heliosares.auxprotect.core.IAuxProtect; import dev.heliosares.auxprotect.core.Language; @@ -19,13 +19,14 @@ public class EntryAction { public static final EntryAction SESSION = new EntryAction("session", 4, 5); public static final EntryAction KICK = new EntryAction("kick", 6); public static final EntryAction SHOP = new EntryAction("shop", 8, 9); - public static final EntryAction BUCKET = new EntryAction("bucket", 10, 11); + // SKIPPED 10/11 public static final EntryAction MOUNT = new EntryAction("mount", 12, 13); public static final EntryAction PLUGINLOAD = new EntryAction("pluginload", 14, 15); public static final EntryAction ALERT = new EntryAction("alert", 128); public static final EntryAction RESPAWN = new EntryAction("respawn", 129); - // public static final EntryAction XRAYCHECK = new EntryAction("xraycheck", 130); + // SKIPPED 130 + // SKIPPED 131 public static final EntryAction CENSOR = new EntryAction("censor", 132); public static final EntryAction MSG = new EntryAction("msg", 133); public static final EntryAction CONSUME = new EntryAction("consume", 134); @@ -39,6 +40,7 @@ public class EntryAction { public static final EntryAction PAY = new EntryAction("pay", 141); public static final EntryAction LIGHTNING = new EntryAction("lightning", 142); public static final EntryAction EXPLODE = new EntryAction("explode", 143); + public static final EntryAction NAMETAG = new EntryAction("nametag", 144); // END MAIN (255) // START SPAM(256) @@ -83,6 +85,7 @@ public class EntryAction { public static final EntryAction ENCHANT = new EntryAction("enchant", 1156); public static final EntryAction SMITH = new EntryAction("smith", 1157); + public static final EntryAction BUCKET = new EntryAction("bucket", 1158, 1159); // END INVENTORY(1279) // COMMANDS (1280) diff --git a/src/main/java/dev/heliosares/auxprotect/database/MigrationManager.java b/src/main/java/dev/heliosares/auxprotect/database/MigrationManager.java index 1305ded..f8a91b4 100644 --- a/src/main/java/dev/heliosares/auxprotect/database/MigrationManager.java +++ b/src/main/java/dev/heliosares/auxprotect/database/MigrationManager.java @@ -10,7 +10,7 @@ import java.sql.*; import java.util.*; public class MigrationManager { - public static final int TARGET_DB_VERSION = 11; + public static final int TARGET_DB_VERSION = 12; private final SQLManager sql; private final Connection connection; private final IAuxProtect plugin; @@ -381,6 +381,20 @@ public class MigrationManager { tryExecute("UPDATE " + Table.AUXPROTECT_POSITION + " set increment=0 where increment is null"); })); + + // + // 12 + // + + migrationActions.put(12, new MigrationAction(plugin.getPlatform() == PlatformType.SPIGOT, () -> { + }, () -> { + String buckets = Table.AUXPROTECT_MAIN + " WHERE action_id IN (10,11)"; + sql.execute("INSERT INTO " + Table.AUXPROTECT_INVENTORY + " (time, uid, action_id, world_id, x, y, z, target_id, data) SELECT time, uid, action_id, world_id, x, y, z, target_id, data FROM " + buckets, connection); + sql.execute("UPDATE " + Table.AUXPROTECT_INVENTORY + " SET action_id=1158 WHERE action_id=10", connection); + sql.execute("UPDATE " + Table.AUXPROTECT_INVENTORY + " SET action_id=1159 WHERE action_id=11", connection); + sql.execute("DELETE FROM " + buckets, connection); + })); + // // Finalizing // diff --git a/src/main/java/dev/heliosares/auxprotect/spigot/listeners/EntityListener.java b/src/main/java/dev/heliosares/auxprotect/spigot/listeners/EntityListener.java index 06316f6..16c5fbd 100644 --- a/src/main/java/dev/heliosares/auxprotect/spigot/listeners/EntityListener.java +++ b/src/main/java/dev/heliosares/auxprotect/spigot/listeners/EntityListener.java @@ -280,4 +280,5 @@ public class EntityListener implements Listener { e.getEntity().getLocation(), AuxProtectSpigot.getLabel(e.getEntity()), ""); plugin.add(entry); } + } diff --git a/src/main/java/dev/heliosares/auxprotect/spigot/listeners/PlayerListener.java b/src/main/java/dev/heliosares/auxprotect/spigot/listeners/PlayerListener.java index e2b0d9c..fc2b684 100644 --- a/src/main/java/dev/heliosares/auxprotect/spigot/listeners/PlayerListener.java +++ b/src/main/java/dev/heliosares/auxprotect/spigot/listeners/PlayerListener.java @@ -29,23 +29,22 @@ import org.bukkit.event.entity.PlayerLeashEntityEvent; import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.Damageable; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.scheduler.BukkitRunnable; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Objects; +import java.util.*; public class PlayerListener implements Listener { - private final ArrayList buckets; - private final ArrayList mobs; + private final Set buckets; + private final Set mobs; private final AuxProtectSpigot plugin; public PlayerListener(AuxProtectSpigot plugin) { this.plugin = plugin; - buckets = new ArrayList<>(); + Set buckets = new HashSet<>(); if (plugin.getCompatabilityVersion() >= 17) { buckets.add(Material.AXOLOTL_BUCKET); } @@ -53,7 +52,8 @@ public class PlayerListener implements Listener { buckets.add(Material.SALMON_BUCKET); buckets.add(Material.TROPICAL_FISH_BUCKET); buckets.add(Material.PUFFERFISH_BUCKET); - mobs = new ArrayList<>(); + this.buckets = Collections.unmodifiableSet(buckets); + Set mobs = new HashSet<>(); mobs.add(EntityType.PUFFERFISH); if (plugin.getCompatabilityVersion() >= 17) { mobs.add(EntityType.AXOLOTL); @@ -64,6 +64,7 @@ public class PlayerListener implements Listener { mobs.add(EntityType.TROPICAL_FISH); mobs.add(EntityType.COD); mobs.add(EntityType.SALMON); + this.mobs = Collections.unmodifiableSet(mobs); } public static void logMoney(AuxProtectSpigot plugin, Player player, String reason) { @@ -90,17 +91,29 @@ public class PlayerListener implements Listener { public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent e) { plugin.getAPPlayer(e.getPlayer()).addActivity(1); - ItemStack mainhand = e.getPlayer().getInventory().getItemInMainHand(); - ItemStack offhand = e.getPlayer().getInventory().getItemInOffHand(); - if (mainhand.getType() == Material.WATER_BUCKET || offhand.getType() == Material.WATER_BUCKET) { - if (mobs.contains(e.getRightClicked().getType())) { - DbEntry entry = new DbEntry(AuxProtectSpigot.getLabel(e.getPlayer()), EntryAction.BUCKET, true, - e.getRightClicked().getLocation(), AuxProtectSpigot.getLabel(e.getRightClicked()), ""); - plugin.add(entry); + ItemStack item = e.getPlayer().getInventory().getItem(e.getHand()); + + if (item != null) { + if (item.getType() == Material.NAME_TAG) { + ItemMeta meta = item.getItemMeta(); + if (meta != null && meta.hasDisplayName()) { + plugin.add(new DbEntry(AuxProtectSpigot.getLabel(e.getPlayer()), EntryAction.NAMETAG, true, + e.getRightClicked().getLocation(), AuxProtectSpigot.getLabel(e.getRightClicked()), meta.getDisplayName())); + } + } + if (item.getType() == Material.WATER_BUCKET) { + if (mobs.contains(e.getRightClicked().getType())) { + plugin.getServer().getScheduler().runTaskLater(plugin, () -> { + ItemStack newBucket = e.getPlayer().getInventory().getItem(e.getHand()); + if (newBucket != null && !buckets.contains(newBucket.getType())) newBucket = null; + plugin.add(new SingleItemEntry(AuxProtectSpigot.getLabel(e.getPlayer()), EntryAction.BUCKET, true, + e.getRightClicked().getLocation(), AuxProtectSpigot.getLabel(e.getRightClicked()), "", newBucket)); + }, 1); + } } } - if (e.getRightClicked() instanceof final ItemFrame item) { - if (item.getItem().getType() == Material.AIR) { + if (e.getRightClicked() instanceof final ItemFrame itemFrame) { + if (itemFrame.getItem().getType() == Material.AIR) { ItemStack added = e.getPlayer().getInventory().getItemInMainHand(); if (added.getType() == Material.AIR) { added = e.getPlayer().getInventory().getItemInOffHand(); @@ -108,7 +121,7 @@ public class PlayerListener implements Listener { if (added.getType() != Material.AIR) { String data = ""; DbEntry entry = new SingleItemEntry(AuxProtectSpigot.getLabel(e.getPlayer()), EntryAction.ITEMFRAME, true, - item.getLocation(), added.getType().toString().toLowerCase(), data, added); + itemFrame.getLocation(), added.getType().toString().toLowerCase(), data, added); plugin.add(entry); } } @@ -125,9 +138,8 @@ public class PlayerListener implements Listener { if (e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock() != null) { if ((e.getItem() != null && buckets.contains(e.getItem().getType()))) { - DbEntry entry = new DbEntry(AuxProtectSpigot.getLabel(e.getPlayer()), EntryAction.BUCKET, false, - e.getClickedBlock().getLocation(), e.getItem().getType().toString().toLowerCase(), ""); - plugin.add(entry); + plugin.add(new SingleItemEntry(AuxProtectSpigot.getLabel(e.getPlayer()), EntryAction.BUCKET, false, + e.getClickedBlock().getLocation(), e.getItem().getType().toString().toLowerCase(), "", e.getItem())); } } }