SteamWar/BauSystem
Archiviert
13
0

Add TNTSpawn naming

Dieser Commit ist enthalten in:
jojo 2021-01-20 20:28:45 +01:00
Ursprung 870fc285e7
Commit bbdf02594b
5 geänderte Dateien mit 36 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -22,6 +22,7 @@
package de.steamwar.bausystem.cannonsimulator; package de.steamwar.bausystem.cannonsimulator;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv; import de.steamwar.inventory.SWListInv;
@ -102,7 +103,7 @@ public class TNTSimulator {
static void editTNT(Player player, TNTSpawn tntSpawn) { static void editTNT(Player player, TNTSpawn tntSpawn) {
TNTSimulator tntSimulator = get(player); TNTSimulator tntSimulator = get(player);
SWInventory swInventory = new SWInventory(player, 54, "TNT"); SWInventory swInventory = new SWInventory(player, 54, "TNT" + (tntSpawn.getName().isEmpty() ? "§8- §e" + tntSpawn.getName() : ""));
swInventory.setItem(49, new SWItem(Material.REDSTONE_BLOCK, "§cZurück", clickType -> { swInventory.setItem(49, new SWItem(Material.REDSTONE_BLOCK, "§cZurück", clickType -> {
openSimulator(player); openSimulator(player);
})); }));
@ -113,6 +114,16 @@ public class TNTSimulator {
openSimulator(player); openSimulator(player);
})); }));
// tnt Name
swInventory.setItem(45, new SWItem(Material.NAME_TAG, "§eName", clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Name");
swAnvilInv.setCallback(s -> {
tntSpawn.setName(s);
editTNT(player, tntSpawn);
});
swAnvilInv.open();
}));
// Change Count of spawned TNT // Change Count of spawned TNT
swInventory.setItem(10, new SWItem(SWItem.getDye(10), "§a+1", clickType -> { swInventory.setItem(10, new SWItem(SWItem.getDye(10), "§a+1", clickType -> {
tntSpawn.setCount(tntSpawn.getCount() + 1); tntSpawn.setCount(tntSpawn.getCount() + 1);
@ -293,7 +304,7 @@ public class TNTSimulator {
} }
private static double clamp(double d) { private static double clamp(double d) {
return (int)(d * 100) * 0.01; return (int)(d * 10000) * 0.0001;
} }
private Set<TNTSpawn> tntSpawns = new HashSet<>(); private Set<TNTSpawn> tntSpawns = new HashSet<>();

Datei anzeigen

@ -49,7 +49,7 @@ public class TNTSimulatorListener implements Listener {
if (event.getItem() == null) return; if (event.getItem() == null) return;
if (!event.getItem().isSimilar(TNTSimulator.WAND)) return; if (!event.getItem().isSimilar(TNTSimulator.WAND)) return;
event.setCancelled(true); event.setCancelled(true);
if (permissionCheck(event.getPlayer())) { if (!permissionCheck(event.getPlayer())) {
return; return;
} }

Datei anzeigen

@ -30,6 +30,7 @@ public class TNTSpawn implements Comparable<TNTSpawn> {
private static final World WORLD = Bukkit.getWorlds().get(0); private static final World WORLD = Bukkit.getWorlds().get(0);
private String name = "";
private Vector position; private Vector position;
private int fuseTicks = 80; private int fuseTicks = 80;
private int count = 1; private int count = 1;
@ -53,6 +54,14 @@ public class TNTSpawn implements Comparable<TNTSpawn> {
} }
} }
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Vector getPosition() { public Vector getPosition() {
return position; return position;
} }

Datei anzeigen

@ -25,6 +25,7 @@ import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.cannonsimulator.TNTSimulator; import de.steamwar.bausystem.cannonsimulator.TNTSimulator;
import de.steamwar.bausystem.world.Welt; import de.steamwar.bausystem.world.Welt;
import org.bukkit.block.data.type.TNT;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -45,13 +46,20 @@ public class CommandSimulator implements CommandExecutor {
if (!(commandSender instanceof Player)) if (!(commandSender instanceof Player))
return false; return false;
Player player = (Player) commandSender; Player player = (Player) commandSender;
if (permissionCheck(player)) { if (!permissionCheck(player)) {
return false; return false;
} }
if (args.length == 1 && args[0].equalsIgnoreCase("wand")) { if (args.length == 1) {
player.getInventory().setItemInMainHand(TNTSimulator.WAND); switch (args[0].toLowerCase()) {
player.updateInventory(); case "wand":
player.getInventory().setItemInMainHand(TNTSimulator.WAND);
player.updateInventory();
break;
case "start":
TNTSimulator.get(player).start();
break;
}
return false; return false;
} }
TNTSimulator.openSimulator(player); TNTSimulator.openSimulator(player);

Datei anzeigen

@ -40,6 +40,7 @@ public class CommandSimulatorTabCompleter implements TabCompleter {
private List<String> detonaterTabComplete(Player player, String[] args) { private List<String> detonaterTabComplete(Player player, String[] args) {
List<String> tabComplete = new ArrayList<>(); List<String> tabComplete = new ArrayList<>();
tabComplete.add("wand"); tabComplete.add("wand");
tabComplete.add("start");
if (args.length >= 2) { if (args.length >= 2) {
return new ArrayList<>(); return new ArrayList<>();