1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 14:05:25 +01:00

Include itemframe, painting and armor stand as regular blocks

This commit is contained in:
Zrips 2017-06-27 15:19:44 +03:00
parent 9a46ada423
commit 2cb203c38d
5 changed files with 181 additions and 44 deletions

View File

@ -35,7 +35,6 @@ import org.bukkit.ChatColor;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; 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.listeners.PistonProtectionListener;
import com.gamingmesh.jobs.selection.SelectionManager; import com.gamingmesh.jobs.selection.SelectionManager;
import com.gamingmesh.jobs.stuff.ActionBar; import com.gamingmesh.jobs.stuff.ActionBar;
import com.gamingmesh.jobs.stuff.Debug;
import com.gamingmesh.jobs.stuff.JobsClassLoader; import com.gamingmesh.jobs.stuff.JobsClassLoader;
import com.gamingmesh.jobs.stuff.Loging; import com.gamingmesh.jobs.stuff.Loging;
import com.gamingmesh.jobs.stuff.TabComplete; import com.gamingmesh.jobs.stuff.TabComplete;

View File

@ -18,6 +18,7 @@ import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.TopList; import com.gamingmesh.jobs.container.TopList;
import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.RawMessage;
public class top implements Cmd { public class top implements Cmd {
@ -42,22 +43,22 @@ public class top implements Cmd {
return true; return true;
} }
int start = 0; int page = 1;
if (args.length == 2) if (args.length == 2)
try { try {
start = Integer.parseInt(args[1]); page = Integer.parseInt(args[1]);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
return true; return true;
} }
if (start < 0) if (page < 1)
start = 0; page = 1;
if (Jobs.getJob(args[0]) == null) { if (Jobs.getJob(args[0]) == null) {
player.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("command.top.error.nojob")); player.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("command.top.error.nojob"));
return false; return false;
} }
List<TopList> FullList = Jobs.getJobsDAO().toplist(args[0], start); List<TopList> FullList = Jobs.getJobsDAO().toplist(args[0], page * 15);
if (FullList.size() <= 0) { if (FullList.size() <= 0) {
player.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.noinfo")); player.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.noinfo"));
return false; return false;
@ -70,7 +71,7 @@ public class top implements Cmd {
if (!Jobs.getGCManager().ShowToplistInScoreboard) { if (!Jobs.getGCManager().ShowToplistInScoreboard) {
player.sendMessage(Jobs.getLanguage().getMessage("command.top.output.topline", "%jobname%", jobName)); player.sendMessage(Jobs.getLanguage().getMessage("command.top.output.topline", "%jobname%", jobName));
int i = start; int i = (page * 15) - 15;
for (TopList One : FullList) { for (TopList One : FullList) {
i++; i++;
String PlayerName = One.getPlayerName() != null ? One.getPlayerName() : "Unknown"; String PlayerName = One.getPlayerName() != null ? One.getPlayerName() : "Unknown";
@ -82,7 +83,7 @@ public class top implements Cmd {
List<String> ls = new ArrayList<String>(); List<String> ls = new ArrayList<String>();
int i = (start + 1) * 15 - 15; int i = (page * 15) - 15;
for (TopList one : FullList) { for (TopList one : FullList) {
i++; i++;
String playername = one.getPlayerName() != null ? one.getPlayerName() : "Unknown"; String playername = one.getPlayerName() != null ? one.getPlayerName() : "Unknown";
@ -93,40 +94,15 @@ public class top implements Cmd {
plugin.getCMIScoreboardManager().addNew(player); plugin.getCMIScoreboardManager().addNew(player);
// Scoreboard board = player.getScoreboard(); int prev = page < 2 ? 1 : page - 1;
// Objective objective = board.getObjective("JobsTopPlayers"); int next = page + 1;
// 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 from = start; RawMessage rm = new RawMessage();
if (start >= 15) rm.add(Jobs.getLanguage().getMessage("command.gtop.output.prev"),
from = start - 15; Jobs.getLanguage().getMessage("command.gtop.output.show", "[from]", prev * 15 - 15, "[until]", (prev * 15)), "jobs top " + jobName + " " + prev);
int until = start + 15; 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);
String prev = "[\"\",{\"text\":\"" + Jobs.getLanguage().getMessage("command.top.output.prev") rm.show(player);
+ "\",\"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);
} }
return true; return true;
} }

View File

@ -462,7 +462,27 @@ public class ConfigManager {
if (actionType == ActionType.EXPLORE) if (actionType == ActionType.EXPLORE)
material = null; 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 // Break and Place actions MUST be blocks
if (actionType == ActionType.BREAK || actionType == ActionType.PLACE) { if (actionType == ActionType.BREAK || actionType == ActionType.PLACE) {
if (!material.isBlock()) { if (!material.isBlock()) {

View File

@ -19,6 +19,7 @@
package com.gamingmesh.jobs.listeners; package com.gamingmesh.jobs.listeners;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; 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.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityTameEvent; import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.SlimeSplitEvent; 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.BrewEvent;
import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent; 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<Entity> 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) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCreatureSpawn(SlimeSplitEvent event) { public void onCreatureSpawn(SlimeSplitEvent event) {
//disabling plugin in world //disabling plugin in world

View File

@ -126,9 +126,10 @@ public class CMIScoreboardManager {
if (i >= lines.size()) if (i >= lines.size())
break; break;
String ln = ChatColor.translateAlternateColorCodes('&', lines.get(i));
Class<?> ScoreboardScoreClass = getNMSClass("ScoreboardScore"); Class<?> ScoreboardScoreClass = getNMSClass("ScoreboardScore");
Constructor<?> packetConstructor2 = ScoreboardScoreClass.getConstructor(getNMSClass("Scoreboard"), getNMSClass("ScoreboardObjective"), String.class); 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); Method mc = packet2.getClass().getMethod("setScore", int.class);
mc.invoke(packet2, 15 - i); mc.invoke(packet2, 15 - i);