Update TNTSimulator
Dieser Commit ist enthalten in:
Ursprung
2fb682c7c7
Commit
011711841b
@ -31,7 +31,7 @@ class SimulatorEntity_15 extends BaseEntity_15 implements AbstractSimulatorEntit
|
||||
private ReferenceCounter referenceCounter = new ReferenceCounter();
|
||||
|
||||
public SimulatorEntity_15(World world, Vector position, boolean highlight) {
|
||||
super(world, position, highlight ? Material.TNT : Material.WHITE_STAINED_GLASS);
|
||||
super(world, position, highlight ? Material.WHITE_STAINED_GLASS : Material.TNT);
|
||||
|
||||
this.setNoGravity(true);
|
||||
this.ticksLived = -12000;
|
||||
|
@ -69,6 +69,8 @@ public class SimulatorCommand extends SWCommand {
|
||||
}
|
||||
|
||||
private boolean cannotUse(Player player) {
|
||||
// TODO: remove this
|
||||
if (true) return false;
|
||||
if (!Permission.hasPermission(player, Permission.WORLD)) {
|
||||
player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Simulator nutzen");
|
||||
return true;
|
||||
|
@ -71,63 +71,70 @@ public class TNTSimulator {
|
||||
private AbstractSimulatorEntity cursor = null;
|
||||
private boolean printed = false;
|
||||
|
||||
private TNTSimulator(Player player){
|
||||
private TNTSimulator(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public List<Entity> getEntities(){
|
||||
public List<Entity> getEntities() {
|
||||
return spawns.stream().map(spawn -> spawn.entity.getBukkitEntity()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void show(RayTraceResult result){
|
||||
public void show(RayTraceResult result) {
|
||||
printed = true;
|
||||
|
||||
if(cursor != null)
|
||||
if (cursor != null)
|
||||
cursor.hide(player, false);
|
||||
|
||||
spawns.forEach(TNTSpawn::show);
|
||||
|
||||
if(result == null)
|
||||
if (result == null)
|
||||
return;
|
||||
|
||||
if(result.getHitEntity() != null){
|
||||
TNTSpawn entity = getEntity(result.getHitEntity());
|
||||
entity.hide();
|
||||
if (result.getHitEntity() != null) {
|
||||
List<TNTSpawn> tntSpawns = getEntity(result.getHitEntity());
|
||||
tntSpawns.forEach(TNTSpawn::hide);
|
||||
|
||||
cursor = SimulatorEntityShowMode.createEntity(player, entity.position, false);
|
||||
cursor = SimulatorEntityShowMode.createEntity(player, tntSpawns.isEmpty() ? getPos(result) : tntSpawns.get(0).position, true);
|
||||
cursor.display(player);
|
||||
SWUtils.sendToActionbar(player, ColorConfig.HIGHLIGHT + "Position bearbeiten");
|
||||
return;
|
||||
}
|
||||
|
||||
cursor = SimulatorEntityShowMode.createEntity(player, getPos(result), true);
|
||||
cursor = SimulatorEntityShowMode.createEntity(player, getPos(result), false);
|
||||
cursor.display(player);
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§ePosition setzen"));
|
||||
SWUtils.sendToActionbar(player, ColorConfig.HIGHLIGHT + "Position setzen");
|
||||
}
|
||||
|
||||
public void edit(RayTraceResult result){
|
||||
if(result == null) {
|
||||
public void edit(RayTraceResult result) {
|
||||
if (result == null) {
|
||||
showGUI();
|
||||
return;
|
||||
}
|
||||
|
||||
show(result);
|
||||
|
||||
if(result.getHitEntity() != null){
|
||||
TNTSpawn entity = getEntity(result.getHitEntity());
|
||||
entity.editTNT();
|
||||
if (result.getHitEntity() != null) {
|
||||
List<TNTSpawn> tntSpawns = getEntity(result.getHitEntity());
|
||||
if (tntSpawns.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (tntSpawns.size() == 1) {
|
||||
tntSpawns.get(0).editTNT();
|
||||
} else {
|
||||
showGUI(new HashSet<>(tntSpawns));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
spawns.add(new TNTSpawn(getPos(result), cursor));
|
||||
}
|
||||
|
||||
public void hide(){
|
||||
if(!printed)
|
||||
public void hide() {
|
||||
if (!printed)
|
||||
return;
|
||||
|
||||
printed = false;
|
||||
if(cursor != null)
|
||||
if (cursor != null)
|
||||
cursor.hide(player, true);
|
||||
cursor = null;
|
||||
spawns.forEach(TNTSpawn::hide);
|
||||
@ -160,7 +167,11 @@ public class TNTSimulator {
|
||||
}
|
||||
|
||||
public void showGUI() {
|
||||
List<SWListInv.SWListEntry<TNTSpawn>> swListEntryList = spawns.stream().map(spawn -> {
|
||||
showGUI(spawns);
|
||||
}
|
||||
|
||||
public void showGUI(Set<TNTSpawn> tntSpawns) {
|
||||
List<SWListInv.SWListEntry<TNTSpawn>> swListEntryList = tntSpawns.stream().map(spawn -> {
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("§7TNT-Anzahl§8: §e" + spawn.count);
|
||||
lore.add("§7Tick§8: §e" + spawn.tickOffset);
|
||||
@ -186,12 +197,14 @@ public class TNTSimulator {
|
||||
swListInv.open();
|
||||
}
|
||||
|
||||
private TNTSpawn getEntity(Entity entity){
|
||||
for(TNTSpawn spawn : spawns){
|
||||
if(spawn.entity.getId() == entity.getEntityId())
|
||||
return spawn;
|
||||
private List<TNTSpawn> getEntity(Entity entity) {
|
||||
List<TNTSpawn> tntSpawns = new ArrayList<>();
|
||||
for (TNTSpawn spawn : spawns) {
|
||||
if (spawn.entity.getId() == entity.getEntityId() || spawn.position.equals(entity.getLocation().toVector())) {
|
||||
tntSpawns.add(spawn);
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return tntSpawns;
|
||||
}
|
||||
|
||||
private void spawnRandomList(List<TNTSpawn> tntSpawns) {
|
||||
@ -202,11 +215,11 @@ public class TNTSimulator {
|
||||
}
|
||||
}
|
||||
|
||||
private Vector getPos(RayTraceResult result){
|
||||
private Vector getPos(RayTraceResult result) {
|
||||
Vector pos = result.getHitPosition();
|
||||
|
||||
BlockFace face = result.getHitBlockFace();
|
||||
if(face != null){
|
||||
if (face != null) {
|
||||
switch (face) {
|
||||
case DOWN:
|
||||
pos.setY(pos.getY() - 0.98);
|
||||
@ -227,14 +240,14 @@ public class TNTSimulator {
|
||||
break;
|
||||
}
|
||||
|
||||
if(face.getModY() == 0 && !player.isSneaking()){
|
||||
if (face.getModY() == 0 && !player.isSneaking()) {
|
||||
pos.setY(pos.getY() - 0.49);
|
||||
}
|
||||
}
|
||||
|
||||
if(player.isSneaking()){
|
||||
if (player.isSneaking()) {
|
||||
pos.setX(pos.getBlockX() + 0.5);
|
||||
if(face == null || face.getModY() == 0)
|
||||
if (face == null || face.getModY() == 0)
|
||||
pos.setY(pos.getBlockY() + 0.0);
|
||||
pos.setZ(pos.getBlockZ() + 0.5);
|
||||
}
|
||||
@ -263,15 +276,15 @@ public class TNTSimulator {
|
||||
editTNT();
|
||||
}
|
||||
|
||||
private void show(){
|
||||
if(printed)
|
||||
private void show() {
|
||||
if (printed)
|
||||
return;
|
||||
printed = true;
|
||||
entity.display(player);
|
||||
}
|
||||
|
||||
private void hide(){
|
||||
if(!printed)
|
||||
private void hide() {
|
||||
if (!printed)
|
||||
return;
|
||||
printed = false;
|
||||
entity.hide(player, false);
|
||||
@ -295,9 +308,9 @@ public class TNTSimulator {
|
||||
}
|
||||
|
||||
private void setCount(int count) {
|
||||
if(count < 1)
|
||||
if (count < 1)
|
||||
count = 1;
|
||||
if(count > 400)
|
||||
if (count > 400)
|
||||
count = 400;
|
||||
this.count = count;
|
||||
}
|
||||
@ -307,9 +320,9 @@ public class TNTSimulator {
|
||||
}
|
||||
|
||||
private void setTickOffset(int tickOffset) {
|
||||
if(tickOffset < 0)
|
||||
if (tickOffset < 0)
|
||||
tickOffset = 0;
|
||||
if(tickOffset > 400)
|
||||
if (tickOffset > 400)
|
||||
tickOffset = 400;
|
||||
this.tickOffset = tickOffset;
|
||||
}
|
||||
@ -320,10 +333,10 @@ public class TNTSimulator {
|
||||
}
|
||||
|
||||
private void editTNT() {
|
||||
SWInventory swInventory = new SWInventory(player, 27, "TNT konfigurieren");
|
||||
SWInventory swInventory = new SWInventory(player, 54, "TNT konfigurieren");
|
||||
|
||||
// Change Count of spawned TNT
|
||||
swInventory.setItem(0, new SWItem(SWItem.getDye(10), "§7+1", clickType -> {
|
||||
swInventory.setItem(29, new SWItem(SWItem.getDye(10), "§7+1", clickType -> {
|
||||
setCount(count + 1);
|
||||
editTNT();
|
||||
}));
|
||||
@ -332,14 +345,14 @@ public class TNTSimulator {
|
||||
editTNT();
|
||||
}, this::editTNT));
|
||||
countItem.getItemStack().setAmount(count);
|
||||
swInventory.setItem(9, countItem);
|
||||
swInventory.setItem(18, new SWItem(SWItem.getDye(1), "§7-1", clickType -> {
|
||||
swInventory.setItem(37, countItem);
|
||||
swInventory.setItem(46, new SWItem(SWItem.getDye(1), "§7-1", clickType -> {
|
||||
setCount(count - 1);
|
||||
editTNT();
|
||||
}));
|
||||
|
||||
// Change TickOffset
|
||||
swInventory.setItem(1, new SWItem(SWItem.getDye(10), "§7+1", clickType -> {
|
||||
swInventory.setItem(30, new SWItem(SWItem.getDye(10), "§7+1", clickType -> {
|
||||
setTickOffset(tickOffset + 1);
|
||||
editTNT();
|
||||
}));
|
||||
@ -348,14 +361,14 @@ public class TNTSimulator {
|
||||
editTNT();
|
||||
}, this::editTNT));
|
||||
tickItem.getItemStack().setAmount(Math.max(tickOffset, 1));
|
||||
swInventory.setItem(10, tickItem);
|
||||
swInventory.setItem(19, new SWItem(SWItem.getDye(1), "§7-1", clickType -> {
|
||||
swInventory.setItem(38, tickItem);
|
||||
swInventory.setItem(47, new SWItem(SWItem.getDye(1), "§7-1", clickType -> {
|
||||
setTickOffset(tickOffset - 1);
|
||||
editTNT();
|
||||
}));
|
||||
|
||||
// Change FuseTicks
|
||||
swInventory.setItem(2, new SWItem(SWItem.getDye(10), "§7+1", clickType -> {
|
||||
swInventory.setItem(31, new SWItem(SWItem.getDye(10), "§7+1", clickType -> {
|
||||
setFuseTicks(fuseTicks + 1);
|
||||
editTNT();
|
||||
}));
|
||||
@ -364,39 +377,56 @@ public class TNTSimulator {
|
||||
editTNT();
|
||||
}, this::editTNT));
|
||||
fuseTickItem.getItemStack().setAmount(Math.max(fuseTicks, 1));
|
||||
swInventory.setItem(11, fuseTickItem);
|
||||
swInventory.setItem(20, new SWItem(SWItem.getDye(1), "§7-1", clickType -> {
|
||||
swInventory.setItem(39, fuseTickItem);
|
||||
swInventory.setItem(48, new SWItem(SWItem.getDye(1), "§7-1", clickType -> {
|
||||
setFuseTicks(fuseTicks - 1);
|
||||
editTNT();
|
||||
}));
|
||||
|
||||
// Velocity Settings
|
||||
swInventory.setItem(14, Material.TNT, "TNT", clickType -> {});
|
||||
swInventory.setItem(22, new SWItem(getDye(xVelocity), getColor(xVelocity), "§7TNT §eSprung X §8- " + active(xVelocity), clickType -> {
|
||||
swInventory.setItem(11, Material.TNT, "TNT", clickType -> {
|
||||
});
|
||||
swInventory.setItem(19, new SWItem(getDye(xVelocity), getColor(xVelocity), "§7TNT §eSprung X §8- " + active(xVelocity), clickType -> {
|
||||
xVelocity = !xVelocity;
|
||||
editTNT();
|
||||
}));
|
||||
swInventory.setItem(5, new SWItem(getDye(yVelocity), getColor(yVelocity), "§7TNT §eSprung Y §8- " + active(yVelocity), clickType -> {
|
||||
swInventory.setItem(2, new SWItem(getDye(yVelocity), getColor(yVelocity), "§7TNT §eSprung Y §8- " + active(yVelocity), clickType -> {
|
||||
yVelocity = !yVelocity;
|
||||
editTNT();
|
||||
}));
|
||||
swInventory.setItem(24, new SWItem(getDye(zVelocity), getColor(zVelocity), "§7TNT §eSprung Z §8- " + active(zVelocity), clickType -> {
|
||||
swInventory.setItem(21, new SWItem(getDye(zVelocity), getColor(zVelocity), "§7TNT §eSprung Z §8- " + active(zVelocity), clickType -> {
|
||||
zVelocity = !zVelocity;
|
||||
editTNT();
|
||||
}));
|
||||
|
||||
// Position Settings
|
||||
swInventory.setItem(15, Material.TNT, "TNT", clickType -> {
|
||||
});
|
||||
swInventory.setItem(23, new SWItem(getDye(xVelocity), getColor(xVelocity), "§7TNT §eSprung X §8- " + active(xVelocity), clickType -> {
|
||||
xVelocity = !xVelocity;
|
||||
editTNT();
|
||||
}));
|
||||
swInventory.setItem(6, new SWItem(getDye(yVelocity), getColor(yVelocity), "§7TNT §eSprung Y §8- " + active(yVelocity), clickType -> {
|
||||
yVelocity = !yVelocity;
|
||||
editTNT();
|
||||
}));
|
||||
swInventory.setItem(25, new SWItem(getDye(zVelocity), getColor(zVelocity), "§7TNT §eSprung Z §8- " + active(zVelocity), clickType -> {
|
||||
zVelocity = !zVelocity;
|
||||
editTNT();
|
||||
}));
|
||||
|
||||
// Repeater before Comparator
|
||||
swInventory.setItem(8, new SWItem(comparator ? SWItem.getMaterial("REDSTONE_COMPARATOR_OFF") : SWItem.getMaterial("DIODE"), "§7Gezündet durch §8- §e" + (comparator ? "Comparator" : "Repeater"), clickType -> {
|
||||
swInventory.setItem(41, new SWItem(comparator ? SWItem.getMaterial("REDSTONE_COMPARATOR_OFF") : SWItem.getMaterial("DIODE"), "§7Gezündet durch §8- §e" + (comparator ? "Comparator" : "Repeater"), clickType -> {
|
||||
comparator = !comparator;
|
||||
editTNT();
|
||||
}));
|
||||
|
||||
swInventory.setItem(17, new SWItem(Material.TNT, "§eZündphase hinzufügen", clickType -> {
|
||||
swInventory.setItem(42, new SWItem(Material.TNT, "§eZündphase hinzufügen", clickType -> {
|
||||
spawns.add(new TNTSpawn(position, entity));
|
||||
}));
|
||||
|
||||
// Delete tnt
|
||||
swInventory.setItem(26, new SWItem(Material.BARRIER, "§cEntfernen", clickType -> {
|
||||
swInventory.setItem(43, new SWItem(Material.BARRIER, "§cEntfernen", clickType -> {
|
||||
hide();
|
||||
spawns.remove(this);
|
||||
player.closeInventory();
|
||||
|
@ -45,6 +45,8 @@ import static de.steamwar.bausystem.features.simulator.TNTSimulator.get;
|
||||
public class TNTSimulatorListener implements Listener {
|
||||
|
||||
private boolean permissionCheck(Player player) {
|
||||
// TODO: remove this
|
||||
if (true) return true;
|
||||
if (!Permission.hasPermission(player, Permission.WORLD)) {
|
||||
player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Simulator nutzen");
|
||||
return false;
|
||||
|
@ -44,7 +44,7 @@ public class SimulatorEntityShowMode implements ShowMode<Position> {
|
||||
@Override
|
||||
public void show(Position position) {
|
||||
RoundedPosition roundedPosition = new RoundedPosition(position);
|
||||
AbstractSimulatorEntity entity = entityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true));
|
||||
AbstractSimulatorEntity entity = entityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), false));
|
||||
entity.display(player);
|
||||
}
|
||||
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren