Merge pull request 'Minor DT Rework' (#208) from dt_rework into master
Reviewed-on: #208 Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Commit
929adac747
@ -33,7 +33,7 @@ public class CommandDetonator implements CommandExecutor {
|
|||||||
|
|
||||||
private void help(Player player) {
|
private void help(Player player) {
|
||||||
player.sendMessage("§8/§edetonator wand §8- §7Legt den Fernzünder ins Inventar");
|
player.sendMessage("§8/§edetonator wand §8- §7Legt den Fernzünder ins Inventar");
|
||||||
player.sendMessage("§8/§edetonator detonate §8- §7Benutzt den Fernzünder");
|
player.sendMessage("§8/§edetonator detonate §8- §7Benutzt den nächst besten Fernzünder");
|
||||||
player.sendMessage("§8/§edetonator reset §8- §7Löscht alle markierten Positionen");
|
player.sendMessage("§8/§edetonator reset §8- §7Löscht alle markierten Positionen");
|
||||||
player.sendMessage("§8/§edetonator remove §8- §7Entfernt den Fernzünder");
|
player.sendMessage("§8/§edetonator remove §8- §7Entfernt den Fernzünder");
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,11 @@ public class Detonator implements Listener {
|
|||||||
|
|
||||||
im.setDisplayName("§eFernzünder");
|
im.setDisplayName("§eFernzünder");
|
||||||
|
|
||||||
VersionedRunnable.call(new VersionedRunnable(() -> im.getPersistentDataContainer().set(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE, (byte) 1), 15));
|
VersionedRunnable.call(
|
||||||
|
new VersionedRunnable(() -> {
|
||||||
|
im.getPersistentDataContainer().set(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE, (byte) 1);
|
||||||
|
im.getPersistentDataContainer().set(new NamespacedKey(BauSystem.getPlugin(), "deto-locs"), PersistentDataType.INTEGER, 0);
|
||||||
|
}, 15));
|
||||||
|
|
||||||
List<String> lorelist = Arrays.asList("§eLinks Klick §8- §7Setzte einen Punkt zum Aktivieren",
|
List<String> lorelist = Arrays.asList("§eLinks Klick §8- §7Setzte einen Punkt zum Aktivieren",
|
||||||
"§eLinks Klick + Shift §8- §7Füge einen Punkt hinzu", "§eRechts Klick §8- §7Löse alle Punkte aus");
|
"§eLinks Klick + Shift §8- §7Füge einen Punkt hinzu", "§eRechts Klick §8- §7Löse alle Punkte aus");
|
||||||
@ -66,7 +70,7 @@ public class Detonator implements Listener {
|
|||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
List<int[]> locs = new ArrayList<>();
|
List<int[]> locs = new ArrayList<>();
|
||||||
for (int i = 0; i < 128; i++) {
|
for (int i = 0; i < getDetoLocs(container); i++) {
|
||||||
NamespacedKey key = new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + i);
|
NamespacedKey key = new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + i);
|
||||||
if (container.has(key, PersistentDataType.INTEGER_ARRAY))
|
if (container.has(key, PersistentDataType.INTEGER_ARRAY))
|
||||||
locs.add(container.get(key, PersistentDataType.INTEGER_ARRAY));
|
locs.add(container.get(key, PersistentDataType.INTEGER_ARRAY));
|
||||||
@ -94,7 +98,7 @@ public class Detonator implements Listener {
|
|||||||
}, 12), new VersionedCallable<>(() -> removeLocation(item, location), 15));
|
}, 12), new VersionedCallable<>(() -> removeLocation(item, location), 15));
|
||||||
} else {
|
} else {
|
||||||
DetonatorListener.print(player, detoloader.addBack ? "§e" + detoloader.getBlock() + " hinzugefügt" :
|
DetonatorListener.print(player, detoloader.addBack ? "§e" + detoloader.getBlock() + " hinzugefügt" :
|
||||||
detoloader.getBlock(), Math.min(Detonator.getDetonator(player, player.getInventory().getItemInMainHand()).getLocs().size() + 1, 128));
|
detoloader.getBlock(), Detonator.getDetonator(player, player.getInventory().getItemInMainHand()).getLocs().size() + 1);
|
||||||
if (detoloader.getActivation() == 0)
|
if (detoloader.getActivation() == 0)
|
||||||
return VersionedCallable.call(new VersionedCallable<>(() -> {
|
return VersionedCallable.call(new VersionedCallable<>(() -> {
|
||||||
PLAYER_LOCS.computeIfAbsent(player, player1 -> new HashSet<>()).add(new Detoloader.DetonatorActivation(location));
|
PLAYER_LOCS.computeIfAbsent(player, player1 -> new HashSet<>()).add(new Detoloader.DetonatorActivation(location));
|
||||||
@ -110,11 +114,40 @@ public class Detonator implements Listener {
|
|||||||
|
|
||||||
public static void execute(Player player) {
|
public static void execute(Player player) {
|
||||||
VersionedRunnable.call(new VersionedRunnable(() -> execute(player, PLAYER_LOCS.get(player)), 12), new VersionedRunnable(() -> {
|
VersionedRunnable.call(new VersionedRunnable(() -> execute(player, PLAYER_LOCS.get(player)), 12), new VersionedRunnable(() -> {
|
||||||
Detonator detonator = getDetonator(player, player.getInventory().getItemInMainHand());
|
try {
|
||||||
|
ItemStack item = getNextBestDetonator(player);
|
||||||
|
if (item == null)
|
||||||
|
return;
|
||||||
|
Detonator detonator = getDetonator(player, item);
|
||||||
execute(player, detonator.getLocs());
|
execute(player, detonator.getLocs());
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§c" + e.getMessage());
|
||||||
|
}
|
||||||
}, 15));
|
}, 15));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ItemStack getNextBestDetonator(Player player) {
|
||||||
|
if (player.getInventory().getItemInMainHand().getItemMeta() != null && player.getInventory().getItemInMainHand().getItemMeta().getPersistentDataContainer().has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) {
|
||||||
|
return player.getInventory().getItemInMainHand();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(player.getInventory().getItemInOffHand().getItemMeta() != null && player.getInventory().getItemInOffHand().getItemMeta().getPersistentDataContainer().has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) {
|
||||||
|
return player.getInventory().getItemInOffHand();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ItemStack item : player.getInventory().getContents()) {
|
||||||
|
if (item == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (item.getItemMeta() != null &&
|
||||||
|
item.getItemMeta().getPersistentDataContainer().has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§cDu hast keinen Detonator im Inventar");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static void execute(Player player, Set<Detoloader.DetonatorActivation> locs) {
|
private static void execute(Player player, Set<Detoloader.DetonatorActivation> locs) {
|
||||||
for (Detoloader.DetonatorActivation activation : locs) {
|
for (Detoloader.DetonatorActivation activation : locs) {
|
||||||
|
|
||||||
@ -141,22 +174,46 @@ public class Detonator implements Listener {
|
|||||||
|
|
||||||
private static int getFreeSlot(ItemStack item) {
|
private static int getFreeSlot(ItemStack item) {
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta == null) {
|
||||||
|
throw new SecurityException("Das Item ist kein Detonator");
|
||||||
|
}
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
for (int i = 0; i < 128; i++) {
|
if (!container.has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) {
|
||||||
if (!container.has(new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + i), PersistentDataType.INTEGER_ARRAY))
|
throw new SecurityException("Das Item ist kein Detonator");
|
||||||
|
}
|
||||||
|
for (int i = 0; i < getDetoLocs(container) + 1; i++) {
|
||||||
|
if (!container.has(new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + i), PersistentDataType.INTEGER_ARRAY)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int getDetoLocs(PersistentDataContainer container) {
|
||||||
|
if (!container.has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) {
|
||||||
|
throw new SecurityException("Das Item ist kein Detonator");
|
||||||
|
}
|
||||||
|
return container.get(new NamespacedKey(BauSystem.getPlugin(), "deto-locs"), PersistentDataType.INTEGER);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void increaseLocsSize(PersistentDataContainer container, int to) {
|
||||||
|
if (!container.has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) {
|
||||||
|
throw new SecurityException("Das Item ist kein Detonator");
|
||||||
|
}
|
||||||
|
if (container.get(new NamespacedKey(BauSystem.getPlugin(), "deto-locs"), PersistentDataType.INTEGER) < to) {
|
||||||
|
container.set(new NamespacedKey(BauSystem.getPlugin(), "deto-locs"), PersistentDataType.INTEGER, to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static ItemStack pushLocToDetonator(ItemStack item, Detoloader.DetonatorActivation detoloader) {
|
public static ItemStack pushLocToDetonator(ItemStack item, Detoloader.DetonatorActivation detoloader) {
|
||||||
int slot = getFreeSlot(item);
|
int slot = getFreeSlot(item);
|
||||||
if (slot == -1)
|
if (slot == -1)
|
||||||
throw new SecurityException("Der Detonator ist auf 128 Positionen Limitiert");
|
throw new SecurityException("Ein Fehler ist aufgetreten");
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
Location block = detoloader.location;
|
Location block = detoloader.location;
|
||||||
meta.getPersistentDataContainer().set(new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + slot), PersistentDataType.INTEGER_ARRAY, new int[]
|
meta.getPersistentDataContainer().set(new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + slot), PersistentDataType.INTEGER_ARRAY, new int[]
|
||||||
{block.getBlockX(), block.getBlockY(), block.getBlockZ(), detoloader.activation});
|
{block.getBlockX(), block.getBlockY(), block.getBlockZ(), detoloader.activation});
|
||||||
|
increaseLocsSize(meta.getPersistentDataContainer(), slot + 1);
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@ -164,7 +221,8 @@ public class Detonator implements Listener {
|
|||||||
public static ItemStack clearDetonator(ItemStack item) {
|
public static ItemStack clearDetonator(ItemStack item) {
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
for (int i = 0; i < 128; i++) {
|
container.set(new NamespacedKey(BauSystem.getPlugin(), "deto-locs"), PersistentDataType.INTEGER, 0);
|
||||||
|
for (int i = 0; i < getDetoLocs(container); i++) {
|
||||||
NamespacedKey key = new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + i);
|
NamespacedKey key = new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + i);
|
||||||
container.remove(key);
|
container.remove(key);
|
||||||
}
|
}
|
||||||
@ -179,7 +237,7 @@ public class Detonator implements Listener {
|
|||||||
private static int getSlotOfLocation(ItemStack item, Location location) {
|
private static int getSlotOfLocation(ItemStack item, Location location) {
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
for (int i = 0; i < 128; i++) {
|
for (int i = 0; i < getDetoLocs(container); i++) {
|
||||||
NamespacedKey key = new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + i);
|
NamespacedKey key = new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + i);
|
||||||
if (container.has(key, PersistentDataType.INTEGER_ARRAY)) {
|
if (container.has(key, PersistentDataType.INTEGER_ARRAY)) {
|
||||||
int[] locs = container.get(key, PersistentDataType.INTEGER_ARRAY);
|
int[] locs = container.get(key, PersistentDataType.INTEGER_ARRAY);
|
||||||
|
@ -27,7 +27,6 @@ public class DetonatorListener implements Listener {
|
|||||||
}
|
}
|
||||||
ItemStack item = event.getItem();
|
ItemStack item = event.getItem();
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
try {
|
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case LEFT_CLICK_BLOCK:
|
case LEFT_CLICK_BLOCK:
|
||||||
Detoloader detoloader = VersionedCallable.call(
|
Detoloader detoloader = VersionedCallable.call(
|
||||||
@ -58,10 +57,6 @@ public class DetonatorListener implements Listener {
|
|||||||
Detonator.execute(player);
|
Detonator.execute(player);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
|
||||||
player.sendMessage(BauSystem.PREFIX + "§c" + e.getMessage());
|
|
||||||
player.getInventory().setItemInMainHand(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren