mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 14:05:25 +01:00
Correct tabcomplete for give command
Getting rid of less efficient adventure String processing Huge boost for limited item recognition process which can be up to 100x faster than original one
This commit is contained in:
parent
84be2eba79
commit
c18916bd56
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@ -213,7 +214,8 @@ public class GuiManager {
|
||||
}
|
||||
|
||||
public void openJobsBrowseGUI(Player player, Job job, boolean fromCommand) {
|
||||
Inventory tempInv = plugin.getComplement().createInventory(player, 54, "");
|
||||
|
||||
Inventory tempInv = Bukkit.createInventory(player, 54, "");
|
||||
|
||||
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
|
||||
Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, job);
|
||||
@ -369,7 +371,7 @@ public class GuiManager {
|
||||
}
|
||||
|
||||
private void openJobsBrowseGUI(Player player, Job job, List<ActionType> jobsRemained) {
|
||||
Inventory tempInv = plugin.getComplement().createInventory(player, 54, "");
|
||||
Inventory tempInv = Bukkit.createInventory(player, 54, "");
|
||||
|
||||
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
|
||||
Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, job);
|
||||
|
@ -59,6 +59,7 @@ import net.Zrips.CMILib.Equations.ParseError;
|
||||
import net.Zrips.CMILib.Equations.Parser;
|
||||
import net.Zrips.CMILib.FileHandler.ConfigReader;
|
||||
import net.Zrips.CMILib.Items.CMIMaterial;
|
||||
import net.Zrips.CMILib.Logs.CMIDebug;
|
||||
import net.Zrips.CMILib.Version.Version;
|
||||
|
||||
public class ConfigManager {
|
||||
|
@ -343,7 +343,7 @@ public class LanguageManager {
|
||||
|
||||
c.get("command.give.help.info", "Gives item by jobs name and item category name. Player name is optional");
|
||||
c.get("command.give.help.args", "[playername] [jobname] [items/limiteditems] [jobitemname]");
|
||||
Jobs.getGCManager().getCommandArgs().put("give", Arrays.asList("[playername]", "[jobname]%%[jobitemname]", "[jobitemname]"));
|
||||
Jobs.getGCManager().getCommandArgs().put("give", Arrays.asList("[playername]", "[jobname]", "items%%limiteditems","[jobitemname]"));
|
||||
c.get("command.give.output.notonline", "&4Player with that name is not online!");
|
||||
c.get("command.give.output.noitem", "&4Can't find any item by given name!");
|
||||
|
||||
|
@ -59,6 +59,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@ -85,6 +86,7 @@ import net.Zrips.CMILib.Colors.CMIChatColor;
|
||||
import net.Zrips.CMILib.Items.ArmorTypes;
|
||||
import net.Zrips.CMILib.Items.CMIItemStack;
|
||||
import net.Zrips.CMILib.Items.CMIMaterial;
|
||||
import net.Zrips.CMILib.NBT.CMINBT;
|
||||
import net.Zrips.CMILib.Version.Version;
|
||||
|
||||
public class JobsListener implements Listener {
|
||||
@ -383,14 +385,23 @@ public class JobsListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onLimitedItemInteract(PlayerInteractEvent event) {
|
||||
|
||||
if(!Jobs.hasLimitedItems())
|
||||
{
|
||||
return;
|
||||
if (!Jobs.hasLimitedItems()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
ItemStack iih = CMIItemStack.getItemInMainHand(player);
|
||||
if (iih.getType() == Material.AIR)
|
||||
ItemStack iih = null;
|
||||
try {
|
||||
if (Version.isCurrentHigher(Version.v1_8_R3) && event.getHand() != EquipmentSlot.HAND) {
|
||||
iih = CMIItemStack.getItemInOffHand(player);
|
||||
} else {
|
||||
iih = CMIItemStack.getItemInMainHand(player);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
iih = CMIItemStack.getItemInMainHand(player);
|
||||
}
|
||||
|
||||
if (iih == null || iih.getType() == Material.AIR)
|
||||
return;
|
||||
|
||||
if (event.getClickedBlock() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getClickedBlock().getWorld()))
|
||||
@ -401,29 +412,54 @@ public class JobsListener implements Listener {
|
||||
return;
|
||||
|
||||
Map<Enchantment, Integer> enchants = new HashMap<>(iih.getEnchantments());
|
||||
if (enchants.isEmpty())
|
||||
if (enchants.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String name = null;
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
CMINBT nbt = new CMINBT(iih);
|
||||
Integer i = nbt.getInt("JobsLimited");
|
||||
if (i != null) {
|
||||
Job job = Jobs.getJob(i);
|
||||
if (job != null) {
|
||||
JobProgression prog = jPlayer.getJobProgression(job);
|
||||
if (prog != null) {
|
||||
String node = nbt.getString("JobsLimitedNode");
|
||||
if (node != null) {
|
||||
for (JobLimitedItems oneItem : job.getLimitedItems().values()) {
|
||||
if (prog.getLevel() >= oneItem.getLevel() || !oneItem.getNode().equalsIgnoreCase(node))
|
||||
continue;
|
||||
event.setCancelled(true);
|
||||
CMIActionBar.send(player, Jobs.getLanguage().getMessage("limitedItem.error.levelup", "[jobname]", job.getDisplayName()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (iih.hasItemMeta()) {
|
||||
ItemMeta meta = iih.getItemMeta();
|
||||
if (meta.hasDisplayName())
|
||||
name = plugin.getComplement().getDisplayName(meta);
|
||||
name = meta.getDisplayName();
|
||||
if (meta.hasLore())
|
||||
lore = plugin.getComplement().getLore(meta);
|
||||
lore = meta.getLore();
|
||||
}
|
||||
|
||||
String meinOk = null;
|
||||
String itemNode = null;
|
||||
CMIMaterial mat = CMIMaterial.get(iih);
|
||||
|
||||
Integer jobId = null;
|
||||
mein: for (JobProgression one : jPlayer.getJobProgression()) {
|
||||
for (JobLimitedItems oneItem : one.getJob().getLimitedItems().values()) {
|
||||
if (one.getLevel() >= oneItem.getLevel() || !isThisItem(oneItem, mat, name, lore, enchants))
|
||||
continue;
|
||||
|
||||
meinOk = one.getJob().getName();
|
||||
jobId = one.getJob().getId();
|
||||
meinOk = one.getJob().getDisplayName();
|
||||
itemNode = oneItem.getNode();
|
||||
break mein;
|
||||
}
|
||||
}
|
||||
@ -431,6 +467,19 @@ public class JobsListener implements Listener {
|
||||
if (meinOk != null) {
|
||||
event.setCancelled(true);
|
||||
CMIActionBar.send(player, Jobs.getLanguage().getMessage("limitedItem.error.levelup", "[jobname]", meinOk));
|
||||
|
||||
nbt = new CMINBT(iih);
|
||||
nbt.setInt("JobsLimited", jobId);
|
||||
iih = (ItemStack) nbt.setString("JobsLimitedNode", itemNode);
|
||||
try {
|
||||
if (Version.isCurrentHigher(Version.v1_8_R3) && event.getHand() != EquipmentSlot.HAND) {
|
||||
CMIItemStack.setItemInOffHand(player, iih);
|
||||
} else {
|
||||
CMIItemStack.setItemInMainHand(player, iih);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CMIItemStack.setItemInMainHand(player, iih);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,6 @@ import net.Zrips.CMILib.Entities.CMIEntityType;
|
||||
import net.Zrips.CMILib.Items.CMIItemStack;
|
||||
import net.Zrips.CMILib.Items.CMIMaterial;
|
||||
import net.Zrips.CMILib.Locale.LC;
|
||||
import net.Zrips.CMILib.Logs.CMIDebug;
|
||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||
import net.Zrips.CMILib.Version.Version;
|
||||
|
||||
@ -214,8 +213,7 @@ public final class JobsPaymentListener implements Listener {
|
||||
ItemStack currentItem = event.getCurrentItem();
|
||||
|
||||
if (resultStack.hasItemMeta() && resultStack.getItemMeta().hasDisplayName()) {
|
||||
Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(plugin
|
||||
.getComplement().getDisplayName(resultStack.getItemMeta())), ActionType.VTRADE));
|
||||
Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(resultStack.getItemMeta().getDisplayName()), ActionType.VTRADE));
|
||||
} else if (currentItem != null) {
|
||||
Jobs.action(jPlayer, new ItemActionInfo(currentItem, ActionType.VTRADE));
|
||||
}
|
||||
@ -237,8 +235,7 @@ public final class JobsPaymentListener implements Listener {
|
||||
while (newItemsCount >= 1) {
|
||||
newItemsCount--;
|
||||
if (resultStack.hasItemMeta() && resultStack.getItemMeta().hasDisplayName())
|
||||
Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(plugin
|
||||
.getComplement().getDisplayName(resultStack.getItemMeta())), ActionType.VTRADE));
|
||||
Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(resultStack.getItemMeta().getDisplayName()), ActionType.VTRADE));
|
||||
else
|
||||
Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.VTRADE));
|
||||
}
|
||||
@ -749,8 +746,7 @@ public final class JobsPaymentListener implements Listener {
|
||||
PotionMeta potion = (PotionMeta) currentItem.getItemMeta();
|
||||
Jobs.action(jPlayer, new PotionItemActionInfo(currentItem, ActionType.CRAFT, potion.getBasePotionData().getType()));
|
||||
} else if (resultStack.hasItemMeta() && resultStack.getItemMeta().hasDisplayName()) {
|
||||
Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(plugin
|
||||
.getComplement().getDisplayName(resultStack.getItemMeta())), ActionType.CRAFT));
|
||||
Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(resultStack.getItemMeta().getDisplayName()), ActionType.CRAFT));
|
||||
} else if (currentItem != null) {
|
||||
Jobs.action(jPlayer, new ItemActionInfo(currentItem, ActionType.CRAFT));
|
||||
}
|
||||
@ -776,8 +772,7 @@ public final class JobsPaymentListener implements Listener {
|
||||
org.bukkit.inventory.meta.ItemMeta resultItemMeta = resultStack.getItemMeta();
|
||||
|
||||
if (resultItemMeta != null && resultItemMeta.hasDisplayName())
|
||||
Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(plugin
|
||||
.getComplement().getDisplayName(resultItemMeta)), ActionType.CRAFT));
|
||||
Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(resultItemMeta.getDisplayName()), ActionType.CRAFT));
|
||||
else
|
||||
Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.CRAFT));
|
||||
}
|
||||
@ -967,10 +962,10 @@ public final class JobsPaymentListener implements Listener {
|
||||
String originalName = null;
|
||||
String newName = null;
|
||||
if (firstSlot.hasItemMeta())
|
||||
originalName = plugin.getComplement().getDisplayName(firstSlot.getItemMeta());
|
||||
originalName = firstSlot.getItemMeta().getDisplayName();
|
||||
|
||||
if (resultStack.hasItemMeta())
|
||||
newName = plugin.getComplement().getDisplayName(resultStack.getItemMeta());
|
||||
newName = resultStack.getItemMeta().getDisplayName();
|
||||
|
||||
if (originalName != null && !originalName.equals(newName) && inv.getItem(1) == null && !Jobs.getGCManager().PayForRenaming)
|
||||
return;
|
||||
|
@ -108,7 +108,7 @@ public final class TabComplete implements TabCompleter {
|
||||
}
|
||||
|
||||
if (args.length > 3 && args[3].equalsIgnoreCase("limiteditems")) {
|
||||
Job oneJob = Jobs.getJob(args[i - 1]);
|
||||
Job oneJob = Jobs.getJob(args[i - 2]);
|
||||
|
||||
if (oneJob != null)
|
||||
for (JobLimitedItems limitedItem : oneJob.getLimitedItems().values()) {
|
||||
|
@ -6,15 +6,11 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import net.Zrips.CMILib.Colors.CMIChatColor;
|
||||
|
||||
public interface Complement {
|
||||
|
||||
String getDisplayName(ItemMeta meta);
|
||||
|
||||
String getDisplayName(Player player);
|
||||
|
||||
String getLine(SignChangeEvent event, int line);
|
||||
@ -25,14 +21,6 @@ public interface Complement {
|
||||
|
||||
void setLine(Sign sign, int line, String text);
|
||||
|
||||
org.bukkit.inventory.Inventory createInventory(InventoryHolder owner, int size, String title);
|
||||
|
||||
void setLore(ItemMeta meta, List<String> lore);
|
||||
|
||||
List<String> getLore(ItemMeta meta);
|
||||
|
||||
void setDisplayName(ItemMeta meta, String name);
|
||||
|
||||
default void broadcastMessage(String message) {
|
||||
message = CMIChatColor.translate(message);
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
|
@ -1,23 +1,12 @@
|
||||
package com.gamingmesh.jobs.stuff.complement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public final class Complement1 implements Complement {
|
||||
|
||||
@Override
|
||||
public String getDisplayName(ItemMeta meta) {
|
||||
return meta.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLine(SignChangeEvent event, int line) {
|
||||
return event.getLine(line);
|
||||
@ -33,21 +22,6 @@ public final class Complement1 implements Complement {
|
||||
return sign.getLine(line);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder owner, int size, String title) {
|
||||
return Bukkit.createInventory(owner, size, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLore(ItemMeta meta, List<String> lore) {
|
||||
meta.setLore(lore);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplayName(ItemMeta meta, String name) {
|
||||
meta.setDisplayName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName(Player player) {
|
||||
return player.getDisplayName();
|
||||
@ -57,9 +31,4 @@ public final class Complement1 implements Complement {
|
||||
public void setLine(Sign sign, int line, String text) {
|
||||
sign.setLine(line, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLore(ItemMeta meta) {
|
||||
return meta.getLore();
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,8 @@
|
||||
package com.gamingmesh.jobs.stuff.complement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
@ -25,18 +18,6 @@ public class Complement2 implements Complement {
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName(ItemMeta meta) {
|
||||
Component dName = null;
|
||||
|
||||
try {
|
||||
dName = meta.displayName();
|
||||
} catch (NoSuchMethodError e) {
|
||||
}
|
||||
|
||||
return dName == null ? "" : serialize(dName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLine(SignChangeEvent event, int line) {
|
||||
Component l = event.line(line);
|
||||
@ -53,27 +34,6 @@ public class Complement2 implements Complement {
|
||||
return serialize(sign.line(line));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder owner, int size, String title) {
|
||||
return Bukkit.createInventory(owner, size, deserialize(title));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLore(ItemMeta meta, List<String> lore) {
|
||||
List<Component> l = new ArrayList<>();
|
||||
|
||||
for (String e : lore) {
|
||||
l.add(deserialize(e));
|
||||
}
|
||||
|
||||
meta.lore(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplayName(ItemMeta meta, String name) {
|
||||
meta.displayName(deserialize(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName(Player player) {
|
||||
return serialize(player.displayName());
|
||||
@ -84,16 +44,4 @@ public class Complement2 implements Complement {
|
||||
sign.line(line, deserialize(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLore(ItemMeta meta) {
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
if (meta.hasLore()) {
|
||||
for (Component comp : meta.lore()) {
|
||||
lore.add(serialize(comp));
|
||||
}
|
||||
}
|
||||
|
||||
return lore;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user