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

Added smoker and blast furnace placeholders

Closes #1066
This commit is contained in:
montlikadani 2021-01-24 10:11:21 +01:00
parent 9aa07160eb
commit 1170086166
8 changed files with 74 additions and 152 deletions

View File

@ -292,82 +292,6 @@ public class CMIChatColor {
} }
} }
// if (text.contains(colorCodePrefix)) {
// String t = text;
// Matcher match = postGradientPattern.matcher(t);
// double prevDist = Double.MAX_VALUE;
// StringBuilder endTest = new StringBuilder();
// String prevG9 = "";
// while (match.find()) {
// String g1 = match.group(1);
//
// if (!t.startsWith(g1)) {
// CMIDebug.d("Not start ", t, g1);
// prevDist = Double.MAX_VALUE;
// }
//
// String g9 = match.group(9);
// String g8 = match.group(8);
// CMIChatColor h1 = getColor(g1);
// CMIChatColor h2 = getColor(g9);
//
//
// if (h1.getHex() == null || h2.getHex() == null)
// continue;
//
// java.awt.Color c1 = null;
// try {
// c1 = new java.awt.Color(
// Integer.valueOf(h1.getHex().substring(0, 2), 16),
// Integer.valueOf(h1.getHex().substring(2, 4), 16),
// Integer.valueOf(h1.getHex().substring(4, 6), 16));
// } catch (Throwable e) {
// break;
// }
//
// java.awt.Color c2 = null;
// try {
// c2 = new java.awt.Color(
// Integer.valueOf(h2.getHex().substring(0, 2), 16),
// Integer.valueOf(h2.getHex().substring(2, 4), 16),
// Integer.valueOf(h2.getHex().substring(4, 6), 16));
// } catch (Throwable e) {
// break;
// }
//
// int red1 = c1.getRed();
// int red2 = c2.getRed();
// int rmean = (red1 + red2) >> 1;
// int r = red1 - red2;
// int g = c1.getGreen() - c2.getGreen();
// int b = c1.getBlue() - c2.getBlue();
// double dist = Math.sqrt((((512 + rmean) * r * r) >> 8) + 4 * g * g + (((767 - rmean) * b * b) >> 8));
//
// String[] split = t.split(escape(g1) + match.group(8).replace("|", "\\|"), 2);
// t = split[1];
//
// endTest.append(split[0]);
// if (prevDist == Double.MAX_VALUE)
// endTest.append(g1 + match.group(8));
// else {
// if (prevDist - dist <= 3)
// endTest.append(match.group(8));
// else
// endTest.append(g1 + match.group(8));
// }
// prevG9 = g9;
//
// prevDist = dist;
//
// match = postGradientPattern.matcher(t);
//
// CMIDebug.d("Distance ", g8, g1, g9, (int) (dist * 100) / 100D, prevDist - dist <= 2 ? "OK" : "FAIL");
// }
// endTest.append(prevG9);
//
// CMIDebug.d("endString: " + endTest);
// }
return text; return text;
} }

View File

@ -45,6 +45,10 @@ public class Placeholder {
user_maxbstandcount, user_maxbstandcount,
user_furncount, user_furncount,
user_maxfurncount, user_maxfurncount,
user_smokercount,
user_maxsmokercount,
user_blastcount,
user_maxblastcount,
user_doneq, user_doneq,
user_dailyquests_pending, user_dailyquests_pending,
user_dailyquests_completed, user_dailyquests_completed,
@ -422,6 +426,16 @@ public class Placeholder {
return Integer.toString(user.getFurnaceCount()); return Integer.toString(user.getFurnaceCount());
case user_maxfurncount: case user_maxfurncount:
return Integer.toString(user.getMaxOwnerShipAllowed(BlockTypes.FURNACE)); return Integer.toString(user.getMaxOwnerShipAllowed(BlockTypes.FURNACE));
case user_smokercount:
return !plugin.getBlockOwnerShip(BlockTypes.SMOKER).isPresent() ? "0"
: Integer.toString(plugin.getBlockOwnerShip(BlockTypes.SMOKER).get().getTotal(uuid));
case user_maxsmokercount:
return Integer.toString(user.getMaxOwnerShipAllowed(BlockTypes.SMOKER));
case user_blastcount:
return !plugin.getBlockOwnerShip(BlockTypes.BLAST_FURNACE).isPresent() ? "0"
: Integer.toString(plugin.getBlockOwnerShip(BlockTypes.BLAST_FURNACE).get().getTotal(uuid));
case user_maxblastcount:
return Integer.toString(user.getMaxOwnerShipAllowed(BlockTypes.BLAST_FURNACE));
case user_doneq: case user_doneq:
return Integer.toString(user.getDoneQuests()); return Integer.toString(user.getDoneQuests());
case user_seen: case user_seen:

View File

@ -50,6 +50,9 @@ public class JobItems {
item = mat.newItemStack(); item = mat.newItemStack();
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
if (meta == null) {
return;
}
if (name != null) if (name != null)
meta.setDisplayName(CMIChatColor.translate(name)); meta.setDisplayName(CMIChatColor.translate(name));
@ -88,6 +91,10 @@ public class JobItems {
ItemStack item = this.item.clone(); ItemStack item = this.item.clone();
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
if (meta == null) {
return item;
}
if (meta.hasDisplayName()) if (meta.hasDisplayName())
meta.setDisplayName(CMIChatColor.translate(meta.getDisplayName().replace("[player]", player.getName()))); meta.setDisplayName(CMIChatColor.translate(meta.getDisplayName().replace("[player]", player.getName())));

View File

@ -60,30 +60,35 @@ public class JobLimitedItems {
} }
public ItemStack getItemStack(Player player) { public ItemStack getItemStack(Player player) {
try { mat = CMIMaterial.get(id, data);
mat = CMIMaterial.get(id, data);
ItemStack item = mat.newItemStack();
item.setAmount(amount);
ItemMeta meta = item.getItemMeta();
if (this.name != null)
meta.setDisplayName(CMIChatColor.translate(name));
if (lore != null && !lore.isEmpty()) {
List<String> TranslatedLore = new ArrayList<>();
for (String oneLore : lore) {
TranslatedLore.add(CMIChatColor.translate(oneLore.replace("[player]", player.getName())));
}
meta.setLore(TranslatedLore);
}
if (enchants != null)
for (Entry<Enchantment, Integer> OneEnchant : enchants.entrySet()) {
meta.addEnchant(OneEnchant.getKey(), OneEnchant.getValue(), true);
}
item.setItemMeta(meta);
ItemStack item = mat.newItemStack();
item.setAmount(amount);
ItemMeta meta = item.getItemMeta();
if (meta == null) {
return item; return item;
} catch (Throwable e) {
} }
return null;
if (this.name != null)
meta.setDisplayName(CMIChatColor.translate(name));
if (lore != null && !lore.isEmpty()) {
List<String> translatedLore = new ArrayList<>();
for (String oneLore : lore) {
translatedLore.add(CMIChatColor.translate(oneLore.replace("[player]", player.getName())));
}
meta.setLore(translatedLore);
}
if (enchants != null)
for (Entry<Enchantment, Integer> oneEnchant : enchants.entrySet()) {
meta.addEnchant(oneEnchant.getKey(), oneEnchant.getValue(), true);
}
item.setItemMeta(meta);
return item;
} }
@Deprecated @Deprecated

View File

@ -189,8 +189,7 @@ public class JobsPlayer {
public double percentOverLimit(CurrencyType type) { public double percentOverLimit(CurrencyType type) {
Integer value = limits.get(type); Integer value = limits.get(type);
PaymentData data = getPaymentLimit(); return getPaymentLimit().percentOverLimit(type, value == null ? 0 : value);
return data.percentOverLimit(type, value == null ? 0 : value);
} }
public void loadLogFromDao() { public void loadLogFromDao() {

View File

@ -241,8 +241,8 @@ public class JobsListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
Sign sign = (Sign) block.getState(); Sign sign = (Sign) block.getState();
String FirstLine = sign.getLine(0); String firstLine = sign.getLine(0);
if (FirstLine.contains(Jobs.getLanguage().getMessage("signs.topline")) && !player.hasPermission("jobs.command.signs")) { if (firstLine.contains(Jobs.getLanguage().getMessage("signs.topline")) && !player.hasPermission("jobs.command.signs")) {
event.setCancelled(true); event.setCancelled(true);
player.sendMessage(Jobs.getLanguage().getMessage("signs.cantdestroy")); player.sendMessage(Jobs.getLanguage().getMessage("signs.cantdestroy"));
return; return;
@ -276,8 +276,7 @@ public class JobsListener implements Listener {
if (!CMIChatColor.stripColor(event.getLine(0)).equalsIgnoreCase("[Jobs]")) if (!CMIChatColor.stripColor(event.getLine(0)).equalsIgnoreCase("[Jobs]"))
return; return;
final String signtype = CMIChatColor.stripColor(event.getLine(1)); final SignTopType type = SignTopType.getType(CMIChatColor.stripColor(event.getLine(1)));
final SignTopType type = SignTopType.getType(signtype);
if (type == null) if (type == null)
return; return;
@ -337,7 +336,7 @@ public class JobsListener implements Listener {
if (CMIChatColor.stripColor(event.getLine(0)).equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline"))) && !CMIChatColor.stripColor(event if (CMIChatColor.stripColor(event.getLine(0)).equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline"))) && !CMIChatColor.stripColor(event
.getLine(1)) .getLine(1))
.equalsIgnoreCase("toplist")) .equalsIgnoreCase("toplist"))
event.setLine(0, Convert(Jobs.getLanguage().getMessage("signs.topline"))); event.setLine(0, convert(Jobs.getLanguage().getMessage("signs.topline")));
else else
return; return;
@ -350,7 +349,7 @@ public class JobsListener implements Listener {
String command = CMIChatColor.stripColor(event.getLine(1)).toLowerCase(); String command = CMIChatColor.stripColor(event.getLine(1)).toLowerCase();
for (String key : Jobs.getGCManager().keys) { for (String key : Jobs.getGCManager().keys) {
if (command.equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.secondline." + key)))) { if (command.equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.secondline." + key)))) {
event.setLine(1, Convert(Jobs.getLanguage().getMessage("signs.secondline." + key))); event.setLine(1, convert(Jobs.getLanguage().getMessage("signs.secondline." + key)));
break; break;
} }
} }
@ -360,12 +359,11 @@ public class JobsListener implements Listener {
return; return;
String color = Jobs.getGCManager().SignsColorizeJobName ? job.getChatColor().toString() : ""; String color = Jobs.getGCManager().SignsColorizeJobName ? job.getChatColor().toString() : "";
event.setLine(2, Convert(color + job.getName())); event.setLine(2, convert(color + job.getName()));
} }
private static String Convert(String line) { private String convert(String line) {
Pattern ReplacePatern = Pattern.compile("&([0-9a-fk-or])"); return Pattern.compile("&([0-9a-fk-or])").matcher(CMIChatColor.translate(line)).replaceAll("\u00a7$1");
return ReplacePatern.matcher(CMIChatColor.translate(line)).replaceAll("\u00a7$1");
} }
// Adding to chat prefix job name // Adding to chat prefix job name
@ -379,9 +377,7 @@ public class JobsListener implements Listener {
if (honorific.equals(" ")) if (honorific.equals(" "))
honorific = ""; honorific = "";
String format = event.getFormat(); event.setFormat(event.getFormat().replace("%1$s", honorific + "%1$s"));
format = format.replace("%1$s", honorific + "%1$s");
event.setFormat(format);
} }
// Changing chat prefix variable to job name // Changing chat prefix variable to job name
@ -396,11 +392,9 @@ public class JobsListener implements Listener {
honorific = ""; honorific = "";
String format = event.getFormat(); String format = event.getFormat();
if (!format.contains("{jobs}")) if (format.contains("{jobs}")) {
return; event.setFormat(format.replace("{jobs}", honorific));
}
format = format.replace("{jobs}", honorific);
event.setFormat(format);
} }
// Changing chat prefix variable to job name // Changing chat prefix variable to job name
@ -415,11 +409,9 @@ public class JobsListener implements Listener {
honorific = ""; honorific = "";
String format = event.getFormat(); String format = event.getFormat();
if (!format.contains("{jobs}")) if (format.contains("{jobs}")) {
return; event.setFormat(format.replace("{jobs}", honorific));
}
format = format.replace("{jobs}", honorific);
event.setFormat(format);
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@ -432,11 +424,9 @@ public class JobsListener implements Listener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onCropGrown(final BlockGrowEvent event) { public void onCropGrown(final BlockGrowEvent event) {
//disabling plugin in world if (Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld())) {
if (!Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld())) plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> Jobs.getBpManager().remove(event.getBlock()), 1L);
return; }
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> Jobs.getBpManager().remove(event.getBlock()), 1L);
} }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
@ -524,8 +514,7 @@ public class JobsListener implements Listener {
if (from == to) if (from == to)
return; return;
JobsChunkChangeEvent jobsChunkChangeEvent = new JobsChunkChangeEvent(event.getPlayer(), from, to); plugin.getServer().getPluginManager().callEvent(new JobsChunkChangeEvent(event.getPlayer(), from, to));
plugin.getServer().getPluginManager().callEvent(jobsChunkChangeEvent);
} }
@EventHandler @EventHandler
@ -724,7 +713,6 @@ public class JobsListener implements Listener {
@EventHandler @EventHandler
public void PlayerItemBreakEvent(InventoryClickEvent event) { public void PlayerItemBreakEvent(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked(); Jobs.getPlayerManager().resetiItemBonusCache(((Player) event.getWhoClicked()).getUniqueId());
Jobs.getPlayerManager().resetiItemBonusCache(player.getUniqueId());
} }
} }

View File

@ -876,8 +876,7 @@ public class JobsPaymentListener implements Listener {
break; break;
} }
// Fix money dupping issue when clicking continuously in the result item, but if in the // Possible payment exploit when clicking continuously in the result item #438
// cursor have item, then dupping the money, #438
if (event.isLeftClick() && event.getCursor().getType() != Material.AIR) if (event.isLeftClick() && event.getCursor().getType() != Material.AIR)
return; return;
@ -1519,9 +1518,7 @@ public class JobsPaymentListener implements Listener {
if (jPlayer == null) if (jPlayer == null)
return; return;
// Item in hand Jobs.action(jPlayer, new ItemActionInfo(Jobs.getNms().getItemInMainHand(player), ActionType.EAT));
ItemStack item = Jobs.getNms().getItemInMainHand(player);
Jobs.action(jPlayer, new ItemActionInfo(item, ActionType.EAT));
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)

View File

@ -17,14 +17,8 @@ public class PistonProtectionListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void OnBlockMove(BlockPistonExtendEvent event) { public void OnBlockMove(BlockPistonExtendEvent event) {
if (event.isCancelled()) if (event.isCancelled() || !Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld())
return; || !Jobs.getGCManager().useBlockProtection)
//disabling plugin in world
if (!Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld()))
return;
if (!Jobs.getGCManager().useBlockProtection)
return; return;
BlockFace dir = event.getDirection(); BlockFace dir = event.getDirection();
@ -46,14 +40,8 @@ public class PistonProtectionListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void OnBlockRetractMove(BlockPistonRetractEvent event) { public void OnBlockRetractMove(BlockPistonRetractEvent event) {
if (event.isCancelled()) if (event.isCancelled() || !Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld())
return; || !Jobs.getGCManager().useBlockProtection)
//disabling plugin in world
if (!Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld()))
return;
if (!Jobs.getGCManager().useBlockProtection)
return; return;
BlockFace dir = event.getDirection(); BlockFace dir = event.getDirection();