From 2cb203c38d6f148a546d9f378a8605a69913b5b8 Mon Sep 17 00:00:00 2001 From: Zrips Date: Tue, 27 Jun 2017 15:19:44 +0300 Subject: [PATCH] Include itemframe, painting and armor stand as regular blocks --- src/main/java/com/gamingmesh/jobs/Jobs.java | 2 - .../gamingmesh/jobs/commands/list/top.java | 56 ++----- .../gamingmesh/jobs/config/ConfigManager.java | 22 ++- .../jobs/listeners/JobsPaymentListener.java | 142 ++++++++++++++++++ .../jobs/stuff/CMIScoreboardManager.java | 3 +- 5 files changed, 181 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 34e4ece2..dbe522ad 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -35,7 +35,6 @@ import org.bukkit.ChatColor; import org.bukkit.block.Block; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -87,7 +86,6 @@ import com.gamingmesh.jobs.listeners.McMMOlistener; import com.gamingmesh.jobs.listeners.PistonProtectionListener; import com.gamingmesh.jobs.selection.SelectionManager; import com.gamingmesh.jobs.stuff.ActionBar; -import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.JobsClassLoader; import com.gamingmesh.jobs.stuff.Loging; import com.gamingmesh.jobs.stuff.TabComplete; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/top.java b/src/main/java/com/gamingmesh/jobs/commands/list/top.java index f73aadfc..2006c124 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/top.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/top.java @@ -18,6 +18,7 @@ import com.gamingmesh.jobs.commands.JobCommand; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.TopList; import com.gamingmesh.jobs.stuff.ChatColor; +import com.gamingmesh.jobs.stuff.RawMessage; public class top implements Cmd { @@ -42,22 +43,22 @@ public class top implements Cmd { return true; } - int start = 0; + int page = 1; if (args.length == 2) try { - start = Integer.parseInt(args[1]); + page = Integer.parseInt(args[1]); } catch (NumberFormatException e) { return true; } - if (start < 0) - start = 0; + if (page < 1) + page = 1; if (Jobs.getJob(args[0]) == null) { player.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("command.top.error.nojob")); return false; } - List FullList = Jobs.getJobsDAO().toplist(args[0], start); + List FullList = Jobs.getJobsDAO().toplist(args[0], page * 15); if (FullList.size() <= 0) { player.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.noinfo")); return false; @@ -70,7 +71,7 @@ public class top implements Cmd { if (!Jobs.getGCManager().ShowToplistInScoreboard) { player.sendMessage(Jobs.getLanguage().getMessage("command.top.output.topline", "%jobname%", jobName)); - int i = start; + int i = (page * 15) - 15; for (TopList One : FullList) { i++; String PlayerName = One.getPlayerName() != null ? One.getPlayerName() : "Unknown"; @@ -82,7 +83,7 @@ public class top implements Cmd { List ls = new ArrayList(); - int i = (start + 1) * 15 - 15; + int i = (page * 15) - 15; for (TopList one : FullList) { i++; String playername = one.getPlayerName() != null ? one.getPlayerName() : "Unknown"; @@ -93,40 +94,15 @@ public class top implements Cmd { plugin.getCMIScoreboardManager().addNew(player); -// Scoreboard board = player.getScoreboard(); -// Objective objective = board.getObjective("JobsTopPlayers"); -// if (objective == null) -// objective = board.registerNewObjective("JobsTopPlayers", "dummy"); -// objective.setDisplaySlot(DisplaySlot.SIDEBAR); -// objective.setDisplayName(Jobs.getLanguage().getMessage("scoreboard.topline", "%jobname%", jobName)); -// int i = start; -// int line = 16; -// for (TopList One : FullList) { -// i++; -// line--; -// String playername = One.getPlayerName() != null ? One.getPlayerName() : "Unknown"; -// -// Score score = objective.getScore(Jobs.getLanguage().getMessage("scoreboard.line", "%number%", i, "%playername%", playername, "%level%", One.getLevel())); -// score.setScore(line); -// -// } -// player.setScoreboard(board); + int prev = page < 2 ? 1 : page - 1; + int next = page + 1; - int from = start; - if (start >= 15) - from = start - 15; - int until = start + 15; - - String prev = "[\"\",{\"text\":\"" + Jobs.getLanguage().getMessage("command.top.output.prev") - + "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/jobs top " - + jobName + " " + from + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + Jobs.getLanguage().getMessage( - "command.top.output.show", "[from]", from, "[until]", (from + 15)) + "\"}]}}}"; - String next = " {\"text\":\"" + Jobs.getLanguage().getMessage("command.top.output.next") - + "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/jobs top " - + jobName + " " + until + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + Jobs.getLanguage().getMessage( - "command.top.output.show", "[from]", (until + 1), "[until]", (until + 15)) + "\"}]}}}]"; - - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + player.getName() + " " + prev + "," + next); + RawMessage rm = new RawMessage(); + rm.add(Jobs.getLanguage().getMessage("command.gtop.output.prev"), + Jobs.getLanguage().getMessage("command.gtop.output.show", "[from]", prev * 15 - 15, "[until]", (prev * 15)), "jobs top " + jobName + " " + prev); + rm.add(Jobs.getLanguage().getMessage("command.gtop.output.next"), + Jobs.getLanguage().getMessage("command.gtop.output.show", "[from]", (next * 15), "[until]", (next * 15 + 15)), "jobs top " + jobName + " " + next); + rm.show(player); } return true; } diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index fc59482e..8e6a6ae3 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -462,7 +462,27 @@ public class ConfigManager { if (actionType == ActionType.EXPLORE) material = null; - if (material != null) { + c: if (material != null) { + + // Need to include thos ones and count as regular blocks + switch (key.replace("_", "").toLowerCase()) { + case "itemframe": + type = "ITEM_FRAME"; + id = 18; + meta = "1"; + break c; + case "painting": + type = "PAINTING"; + id = 9; + meta = "1"; + break c; + case "armorstand": + type = "ARMOR_STAND"; + id = 30; + meta = "1"; + break c; + } + // Break and Place actions MUST be blocks if (actionType == ActionType.BREAK || actionType == ActionType.PLACE) { if (!material.isBlock()) { diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 3e0fb66a..ac06aa25 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -19,6 +19,7 @@ package com.gamingmesh.jobs.listeners; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -51,10 +52,15 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.EntityTameEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.SlimeSplitEvent; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.hanging.HangingBreakEvent; +import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause; +import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.inventory.BrewEvent; import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.FurnaceSmeltEvent; @@ -925,6 +931,142 @@ public class JobsPaymentListener implements Listener { } } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onHangingPlaceEvent(HangingPlaceEvent event) { + + //disabling plugin in world + if (!Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld())) + return; + + // make sure plugin is enabled + if (!this.plugin.isEnabled()) + return; + + Player player = event.getPlayer(); + + if (!player.isOnline()) + return; + + // check if in creative + if (player.getGameMode().equals(GameMode.CREATIVE) && !Jobs.getGCManager().payInCreative()) + return; + + if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName())) + return; + + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); + if (jPlayer == null) + return; + Jobs.action(jPlayer, new EntityActionInfo(event.getEntity(), ActionType.PLACE)); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onHangingBreakEvent(HangingBreakByEntityEvent event) { + + //disabling plugin in world + if (!Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld())) + return; + + // make sure plugin is enabled + if (!this.plugin.isEnabled()) + return; + + if (!(event.getRemover() instanceof Player)) + return; + + Player player = (Player) event.getRemover(); + + if (!player.isOnline()) + return; + + // check if in creative + if (player.getGameMode().equals(GameMode.CREATIVE) && !Jobs.getGCManager().payInCreative()) + return; + + if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName())) + return; + + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); + if (jPlayer == null) + return; + Jobs.action(jPlayer, new EntityActionInfo(event.getEntity(), ActionType.BREAK)); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onArmorstandPlace(EntitySpawnEvent event) { + Entity ent = event.getEntity(); + + if (!ent.getType().toString().equalsIgnoreCase("ARMOR_STAND")) + return; + + Location loc = event.getLocation(); + Collection ents = loc.getWorld().getNearbyEntities(loc, 4, 4, 4); + double dis = Double.MAX_VALUE; + Player player = null; + for (Entity one : ents) { + if (!(one instanceof Player)) + continue; + Player p = (Player) one; + if (!Jobs.getNms().getItemInMainHand(p).getType().toString().equalsIgnoreCase("ARMOR_STAND")) + continue; + double d = p.getLocation().distance(loc); + if (d < dis) { + dis = d; + player = p; + } + } + + if (player == null || !player.isOnline()) + return; + // check if in creative + if (player.getGameMode().equals(GameMode.CREATIVE) && !Jobs.getGCManager().payInCreative()) + return; + + if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName())) + return; + + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); + if (jPlayer == null) + return; + Jobs.action(jPlayer, new EntityActionInfo(ent, ActionType.PLACE)); + + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onArmorstandBreak(EntityDeathEvent event) { + Entity ent = event.getEntity(); + + if (!ent.getType().toString().equalsIgnoreCase("ARMOR_STAND")) + return; + + if (!(event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent)) + return; + + EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause(); + + //extra check for Citizens 2 sentry kills + if (e.getDamager() instanceof Player) + if (e.getDamager().hasMetadata("NPC")) + return; + + Player pDamager = (Player) e.getDamager(); + + // check if in creative + if (pDamager.getGameMode().equals(GameMode.CREATIVE) && !Jobs.getGCManager().payInCreative()) + return; + + if (!Jobs.getPermissionHandler().hasWorldPermission(pDamager, pDamager.getLocation().getWorld().getName())) + return; + + // pay + JobsPlayer jDamager = Jobs.getPlayerManager().getJobsPlayer(pDamager); + + if (jDamager == null) + return; + + Jobs.action(jDamager, new EntityActionInfo(ent, ActionType.BREAK), e.getDamager()); + } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onCreatureSpawn(SlimeSplitEvent event) { //disabling plugin in world diff --git a/src/main/java/com/gamingmesh/jobs/stuff/CMIScoreboardManager.java b/src/main/java/com/gamingmesh/jobs/stuff/CMIScoreboardManager.java index f339bae0..04bfb1db 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/CMIScoreboardManager.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/CMIScoreboardManager.java @@ -126,9 +126,10 @@ public class CMIScoreboardManager { if (i >= lines.size()) break; + String ln = ChatColor.translateAlternateColorCodes('&', lines.get(i)); Class ScoreboardScoreClass = getNMSClass("ScoreboardScore"); Constructor packetConstructor2 = ScoreboardScoreClass.getConstructor(getNMSClass("Scoreboard"), getNMSClass("ScoreboardObjective"), String.class); - Object packet2 = packetConstructor2.newInstance(boards, obj, lines.get(i)); + Object packet2 = packetConstructor2.newInstance(boards, obj, ln); Method mc = packet2.getClass().getMethod("setScore", int.class); mc.invoke(packet2, 15 - i);