mirror of
https://github.com/rockyhawk64/CommandPanels.git
synced 2025-11-18 07:14:17 +01:00
Various bug fixes after refactoring
This commit is contained in:
parent
2315daf735
commit
b3da83447a
@ -22,10 +22,12 @@ public class ItemPlacer {
|
||||
public void placeEmptyItems(Panel panel, Player p, PanelPosition pos, Inventory inv) {
|
||||
ConfigurationSection config = panel.getConfig();
|
||||
|
||||
if (!config.contains("empty")) return;
|
||||
|
||||
String materialName = bld.ctx.text.placeholdersNoColour(panel, pos, p, config.getString("empty"));
|
||||
if (materialName.equals("AIR")) return;
|
||||
String materialName;
|
||||
if (config.contains("empty")){
|
||||
materialName = bld.ctx.text.placeholdersNoColour(panel, pos, p, config.getString("empty"));
|
||||
}else{
|
||||
materialName = "AIR";
|
||||
}
|
||||
|
||||
ItemStack empty;
|
||||
try {
|
||||
|
||||
@ -11,6 +11,7 @@ public class PanelBuilder {
|
||||
protected final PanelFactory factory;
|
||||
protected final SlotManager slotManager;
|
||||
protected final ItemPlacer itemPlacer;
|
||||
protected boolean isFirstBuild;
|
||||
|
||||
public PanelBuilder(Context ctx) {
|
||||
this.ctx = ctx;
|
||||
@ -20,6 +21,7 @@ public class PanelBuilder {
|
||||
}
|
||||
|
||||
public void openInv(Panel panel, Player p, PanelPosition position, int animateValue) {
|
||||
isFirstBuild = true;
|
||||
Inventory inv = buildInv(panel, p, position, animateValue);
|
||||
if (position == PanelPosition.Top) {
|
||||
p.openInventory(inv);
|
||||
@ -28,6 +30,7 @@ public class PanelBuilder {
|
||||
}
|
||||
|
||||
public void refreshInv(Panel panel, Player p, PanelPosition position, int animateValue) {
|
||||
isFirstBuild = false;
|
||||
Inventory inv = buildInv(panel, p, position, animateValue);
|
||||
if (ctx.version.isAtLeast("1.21.5") && position == PanelPosition.Top) {
|
||||
p.getOpenInventory().setTitle(TitleHandler.getTitle(ctx, panel, p, position, animateValue));
|
||||
@ -38,6 +41,7 @@ public class PanelBuilder {
|
||||
}
|
||||
|
||||
public Inventory getInv(Panel panel, Player p, PanelPosition position, int animateValue) {
|
||||
isFirstBuild = true;
|
||||
return buildInv(panel, p, position, animateValue);
|
||||
}
|
||||
|
||||
|
||||
@ -34,6 +34,15 @@ public class SlotManager {
|
||||
|
||||
ItemStack item = bld.ctx.itemBuilder.buildItem(panel, position, config.getConfigurationSection("item." + itemKey + section), p, true);
|
||||
int slot = Integer.parseInt(bld.ctx.text.placeholdersNoColour(panel, position, p, itemKey));
|
||||
|
||||
if (config.contains("item." + itemKey + section + ".itemType") && config.getStringList("item." + itemKey + section + ".itemType").contains("placeable")) {
|
||||
if(!bld.isFirstBuild){
|
||||
setItem(p.getOpenInventory().getItem(slot), slot, inv, p, position);
|
||||
takenSlots.add(slot);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
setItem(item, slot, inv, p, position);
|
||||
takenSlots.add(slot);
|
||||
|
||||
|
||||
@ -110,7 +110,9 @@ public class ReloadCommand implements CommandExecutor {
|
||||
}
|
||||
}else{
|
||||
//error in the file, was not a valid commandpanels file and/or could not be converted
|
||||
ctx.plugin.getServer().getConsoleSender().sendMessage("[CommandPanels]" + ChatColor.RED + " Error in: " + fileName);
|
||||
Bukkit.getScheduler().runTask(ctx.plugin, () -> {
|
||||
ctx.plugin.getServer().getConsoleSender().sendMessage("[CommandPanels]" + ChatColor.RED + " Error in: " + fileName);
|
||||
});
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -27,10 +27,9 @@ public class ClickHandler {
|
||||
|
||||
if(e.getSlotType() == InventoryType.SlotType.OUTSIDE) return;
|
||||
|
||||
PanelPosition position = slotResolver.resolveSlotPosition(e, panel, p, clickedSlot);
|
||||
PanelPosition position = slotResolver.resolveSlotPosition(e, panel, p);
|
||||
if(position == PanelPosition.Middle) clickedSlot -= 9;
|
||||
if (position == null) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ public class ClickSlotResolver {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
protected PanelPosition resolveSlotPosition(InventoryClickEvent e, Panel panel, Player p, int clickedSlot) {
|
||||
protected PanelPosition resolveSlotPosition(InventoryClickEvent e, Panel panel, Player p) {
|
||||
if (e.getClickedInventory().getType() == InventoryType.PLAYER) {
|
||||
if (e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
|
||||
e.setCancelled(true);
|
||||
|
||||
@ -32,11 +32,13 @@ public class CommandRunner {
|
||||
if (command.equals("")) continue;
|
||||
}
|
||||
|
||||
if (runPaywalls(panel, position, p, command, true) == PaywallOutput.Blocked) {
|
||||
PaywallOutput output = runPaywalls(panel, position, p, command, true);
|
||||
if (output == PaywallOutput.Blocked) {
|
||||
break;
|
||||
}else if(output == PaywallOutput.NotApplicable){
|
||||
//Run the command as this is not a paywall
|
||||
runCommand(panel, position, p, command);
|
||||
}
|
||||
|
||||
runCommand(panel, position, p, command);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ public class DataPaywall implements PaywallResolver {
|
||||
}
|
||||
|
||||
// Strip prefix and split args
|
||||
String[] args = command.substring("data-paywall=".length()).trim().split(" ");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command.substring("data-paywall=".length()).trim()).split(" ");
|
||||
if (args.length < 2) {
|
||||
ctx.text.sendString(player, ctx.tag + "Invalid data-paywall usage. Not enough arguments.");
|
||||
return PaywallOutput.Blocked;
|
||||
|
||||
@ -14,9 +14,9 @@ public class HasPerm implements PaywallResolver {
|
||||
String[] args;
|
||||
boolean normal = false;
|
||||
if (command.toLowerCase().startsWith("hasperm=")) {
|
||||
args = command.substring("hasperm=".length()).trim().split(" ");
|
||||
args = ctx.text.attachPlaceholders(panel, pos, player, command.substring("hasperm=".length()).trim()).split(" ");
|
||||
}else if(command.toLowerCase().startsWith("hasnoperm=")){
|
||||
args = command.substring("hasnoperm=".length()).trim().split(" ");
|
||||
args = ctx.text.attachPlaceholders(panel, pos, player, command.substring("hasnoperm=".length()).trim()).split(" ");
|
||||
normal = true;
|
||||
}else{
|
||||
return PaywallOutput.NotApplicable;
|
||||
|
||||
@ -19,7 +19,7 @@ public class Paywall implements PaywallResolver {
|
||||
|
||||
try {
|
||||
if (ctx.econ != null) {
|
||||
String[] args = command.substring("paywall=".length()).trim().split(" ");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command.substring("paywall=".length()).trim()).split(" ");
|
||||
if (args.length < 1) {
|
||||
ctx.text.sendString(player, ctx.tag + "Invalid paywall usage. Missing amount.");
|
||||
return PaywallOutput.Blocked;
|
||||
|
||||
@ -20,7 +20,7 @@ public class TokenPaywall implements PaywallResolver {
|
||||
return PaywallOutput.NotApplicable;
|
||||
}
|
||||
|
||||
String[] args = command.substring("tokenpaywall=".length()).trim().split(" ");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command.substring("tokenpaywall=".length()).trim()).split(" ");
|
||||
if (args.length < 1) {
|
||||
ctx.text.sendString(player, ctx.tag + "Invalid tokenpaywall usage. Not enough arguments.");
|
||||
return PaywallOutput.Blocked;
|
||||
|
||||
@ -16,7 +16,7 @@ public class XpPaywall implements PaywallResolver {
|
||||
}
|
||||
|
||||
// Split command arguments (price and level/points)
|
||||
String[] args = command.substring("xp-paywall=".length()).trim().split(" ");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command.substring("xp-paywall=".length()).trim()).split(" ");
|
||||
if (args.length < 2) {
|
||||
ctx.text.sendString(player, ctx.tag + "Invalid xp-paywall usage. Not enough arguments.");
|
||||
return PaywallOutput.Blocked;
|
||||
|
||||
@ -25,7 +25,7 @@ public class ItemPaywall implements PaywallResolver {
|
||||
}
|
||||
|
||||
try {
|
||||
String[] args = command.substring("item-paywall=".length()).trim().split(" ");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command.substring("item-paywall=".length()).trim()).split(" ");
|
||||
if (args.length < 2) {
|
||||
ctx.text.sendString(player, ctx.tag + "Invalid item-paywall usage. Not enough arguments.");
|
||||
return PaywallOutput.Blocked;
|
||||
|
||||
@ -13,7 +13,7 @@ public class BasicTags implements TagResolver {
|
||||
|
||||
@Override
|
||||
public boolean handle(Context ctx, Panel panel, PanelPosition pos, Player player, String command) {
|
||||
String[] args = command.split("\\s+"); // Arguments are space-separated
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command).split("\\s+"); // Arguments are space-separated
|
||||
args = Arrays.copyOfRange(args, 1, args.length); // Remove first element from args
|
||||
if (command.startsWith("console=")) {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), String.join(" ", args));
|
||||
|
||||
@ -11,7 +11,7 @@ import org.bukkit.entity.Player;
|
||||
public class BungeeTag implements TagResolver {
|
||||
@Override
|
||||
public boolean handle(Context ctx, Panel panel, PanelPosition pos, Player player, String command) {
|
||||
String[] args = command.split("\\s+"); // Arguments are space-separated
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command).split("\\s+"); // Arguments are space-separated
|
||||
if(command.startsWith("force-server=")){
|
||||
//this contacts bungee and tells it to send the server change command without checking permissions
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
|
||||
@ -12,7 +12,7 @@ public class CloseTag implements TagResolver {
|
||||
public boolean handle(Context ctx, Panel panel, PanelPosition pos, Player player, String command) {
|
||||
if (!command.startsWith("close=")) return false;
|
||||
|
||||
String[] args = command.split("\\s");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command).split("\\s+");
|
||||
PanelPosition position = PanelPosition.valueOf(args[1]);
|
||||
|
||||
if (position == PanelPosition.Middle && ctx.openPanels.hasPanelOpen(player.getName(), position)) {
|
||||
|
||||
@ -14,12 +14,12 @@ public class DataAddTag implements TagResolver {
|
||||
public boolean handle(Context ctx, Panel panel, PanelPosition pos, Player player, String command) {
|
||||
if (!command.startsWith("add-data=")) return false;
|
||||
|
||||
String[] args = command.split("\\s");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command).split("\\s+");
|
||||
args = Arrays.copyOfRange(args, 1, args.length); // Remove the tag name
|
||||
|
||||
if (args.length == 3) {
|
||||
ctx.panelData.setUserData(
|
||||
ctx.panelDataPlayers.getOffline(ctx.text.placeholdersNoColour(panel, pos, player, args[2])),
|
||||
ctx.panelDataPlayers.getOffline(args[2]),
|
||||
ctx.text.placeholdersNoColour(panel, pos, player, args[0]),
|
||||
ctx.text.placeholdersNoColour(panel, pos, player, args[1]), false
|
||||
);
|
||||
|
||||
@ -14,10 +14,10 @@ public class DataClearTag implements TagResolver {
|
||||
public boolean handle(Context ctx, Panel panel, PanelPosition pos, Player player, String command) {
|
||||
if (!command.startsWith("clear-data=")) return false;
|
||||
|
||||
String[] args = command.split("\\s");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command).split("\\s+");
|
||||
args = Arrays.copyOfRange(args, 1, args.length); // Remove the tag name
|
||||
|
||||
ctx.panelData.clearData(ctx.panelDataPlayers.getOffline(ctx.text.placeholdersNoColour(panel, pos, player, args[0])));
|
||||
ctx.panelData.clearData(ctx.panelDataPlayers.getOffline(args[0]));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,12 +14,12 @@ public class DataDelTag implements TagResolver {
|
||||
public boolean handle(Context ctx, Panel panel, PanelPosition pos, Player player, String command) {
|
||||
if (!command.startsWith("del-data=")) return false;
|
||||
|
||||
String[] args = command.split("\\s");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command).split("\\s+");
|
||||
args = Arrays.copyOfRange(args, 1, args.length); // Remove the tag name
|
||||
|
||||
if (args.length == 2) {
|
||||
ctx.panelData.delUserData(
|
||||
ctx.panelDataPlayers.getOffline(ctx.text.placeholdersNoColour(panel, pos, player, args[1])),
|
||||
ctx.panelDataPlayers.getOffline(args[1]),
|
||||
ctx.text.placeholdersNoColour(panel, pos, player, args[0])
|
||||
);
|
||||
return true;
|
||||
|
||||
@ -14,12 +14,12 @@ public class DataMathTag implements TagResolver {
|
||||
public boolean handle(Context ctx, Panel panel, PanelPosition pos, Player player, String command) {
|
||||
if (!command.startsWith("math-data=")) return false;
|
||||
|
||||
String[] args = command.split("\\s");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command).split("\\s+");
|
||||
args = Arrays.copyOfRange(args, 1, args.length); // Remove the tag name
|
||||
|
||||
if (args.length == 3) {
|
||||
ctx.panelData.doDataMath(
|
||||
ctx.panelDataPlayers.getOffline(ctx.text.placeholdersNoColour(panel, pos, player, args[2])),
|
||||
ctx.panelDataPlayers.getOffline(args[2]),
|
||||
ctx.text.placeholdersNoColour(panel, pos, player, args[0]),
|
||||
ctx.text.placeholdersNoColour(panel, pos, player, args[1])
|
||||
);
|
||||
|
||||
@ -14,12 +14,12 @@ public class DataSetTag implements TagResolver {
|
||||
public boolean handle(Context ctx, Panel panel, PanelPosition pos, Player player, String command) {
|
||||
if (!command.startsWith("set-data=")) return false;
|
||||
|
||||
String[] args = command.split("\\s");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command).split("\\s+");
|
||||
args = Arrays.copyOfRange(args, 1, args.length); // Remove the tag name
|
||||
|
||||
if (args.length == 3) {
|
||||
ctx.panelData.setUserData(
|
||||
ctx.panelDataPlayers.getOffline(ctx.text.placeholdersNoColour(panel, pos, player, args[2])),
|
||||
ctx.panelDataPlayers.getOffline(args[2]),
|
||||
ctx.text.placeholdersNoColour(panel, pos, player, args[0]),
|
||||
ctx.text.placeholdersNoColour(panel, pos, player, args[1]), true
|
||||
);
|
||||
|
||||
@ -15,7 +15,7 @@ public class DelayTag implements TagResolver {
|
||||
public boolean handle(Context ctx, Panel panel, PanelPosition pos, Player player, String command) {
|
||||
if (!command.startsWith("delay=")) return false;
|
||||
|
||||
String[] args = command.split("\\s");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command).split("\\s+");
|
||||
args = Arrays.copyOfRange(args, 1, args.length); // Remove the tag name
|
||||
|
||||
final int delayTicks = Integer.parseInt(args[0]);
|
||||
|
||||
@ -15,7 +15,7 @@ public class EnchantTag implements TagResolver {
|
||||
public boolean handle(Context ctx, Panel panel, PanelPosition pos, Player player, String command) {
|
||||
if (!command.startsWith("enchant=")) return false;
|
||||
|
||||
String[] args = command.split("\\s+");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command).split("\\s+");
|
||||
PanelPosition position = PanelPosition.valueOf(args[2]);
|
||||
ItemStack editItem;
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ public class EvalDelayTag implements TagResolver {
|
||||
public boolean handle(Context ctx, Panel panel, PanelPosition pos, Player player, String command) {
|
||||
if (!command.startsWith("eval-delay=")) return false;
|
||||
|
||||
String[] args = command.split("\\s");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command).split("\\s+");
|
||||
args = Arrays.copyOfRange(args, 1, args.length); // Remove the tag name
|
||||
|
||||
final int delayTicks = Integer.parseInt(args[0]);
|
||||
|
||||
@ -13,7 +13,7 @@ public class GiveItemTag implements TagResolver {
|
||||
public boolean handle(Context ctx, Panel panel, PanelPosition pos, Player player, String command) {
|
||||
if (!command.startsWith("give-item=")) return false;
|
||||
|
||||
String[] args = command.split("\\s+");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command).split("\\s+");
|
||||
ItemStack itm = ctx.itemBuilder.buildItem(null, pos, panel.getConfig().getConfigurationSection("custom-item." + args[1]), player, false);
|
||||
|
||||
if (args.length == 3) {
|
||||
|
||||
@ -13,7 +13,7 @@ public class OpenTag implements TagResolver {
|
||||
if (!command.startsWith("open=")) return false;
|
||||
|
||||
String[] args = command.split("\\s");
|
||||
String panelName = args[1];
|
||||
String panelName = ctx.text.placeholders(panel, pos, player, args[1]);
|
||||
|
||||
String cmd = command.replace("open=","").replace(panelName,"").trim();
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ public class SetCustomDataTag implements TagResolver {
|
||||
public boolean handle(Context ctx, Panel panel, PanelPosition pos, Player player, String command) {
|
||||
if (!command.startsWith("setcustomdata=")) return false;
|
||||
|
||||
String[] args = command.split("\\s+");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command).split("\\s+");
|
||||
PanelPosition position = PanelPosition.valueOf(args[2]);
|
||||
ItemStack editItem;
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ public class SetItemTag implements TagResolver {
|
||||
public boolean handle(Context ctx, Panel panel, PanelPosition pos, Player player, String command) {
|
||||
if (!command.startsWith("setitem=")) return false;
|
||||
|
||||
String[] args = command.split("\\s+");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command).split("\\s+");
|
||||
ItemStack item = ctx.itemBuilder.buildItem(null, pos, panel.getConfig().getConfigurationSection("custom-item." + args[1]), player, false);
|
||||
PanelPosition position = PanelPosition.valueOf(args[3]);
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ import org.bukkit.entity.Player;
|
||||
public class SoundTag implements TagResolver {
|
||||
@Override
|
||||
public boolean handle(Context ctx, Panel panel, PanelPosition pos, Player player, String command) {
|
||||
String[] args = command.split("\\s+"); // Arguments are space-separated
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command).split("\\s+"); // Arguments are space-separated
|
||||
if (command.startsWith("sound=")) {
|
||||
try {
|
||||
if (args.length == 4) {
|
||||
|
||||
@ -17,7 +17,7 @@ public class TeleportTag implements TagResolver {
|
||||
public boolean handle(Context ctx, Panel panel, PanelPosition pos, Player player, String command) {
|
||||
if (!command.startsWith("teleport=")) return false;
|
||||
|
||||
String[] args = command.split("\\s");
|
||||
String[] args = ctx.text.attachPlaceholders(panel, pos, player, command).split("\\s+");
|
||||
args = Arrays.copyOfRange(args, 1, args.length); // Remove the tag name
|
||||
|
||||
float x, y, z, yaw = 0, pitch = 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user