CannonSimulator #164
@ -22,7 +22,6 @@
|
||||
package de.steamwar.bausystem.cannonsimulator;
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.inventory.SWAnvilInv;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
@ -34,6 +33,7 @@ import org.bukkit.util.Consumer;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class TNTSimulator {
|
||||
|
||||
@ -197,6 +197,12 @@ public class TNTSimulator {
|
||||
editTNT(player, tntSpawn);
|
||||
}));
|
||||
|
||||
// Repeater before Comparator
|
||||
swInventory.setItem(4, new SWItem(tntSpawn.isComparator() ? Material.COMPARATOR : Material.REPEATER, "§7Gezündet durch §8- §e" + (tntSpawn.isComparator() ? "Comparator" : "Repeater"), clickType -> {
|
||||
tntSpawn.setComparator(!tntSpawn.isComparator());
|
||||
editTNT(player, tntSpawn);
|
||||
}));
|
||||
|
||||
// Velocity Settings
|
||||
swInventory.setItem(13, new SWItem(tntSpawn.isxVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7Start §eVelocity X §8- §7" + active(tntSpawn.isxVelocity()), clickType -> {
|
||||
tntSpawn.setxVelocity(!tntSpawn.isxVelocity());
|
||||
@ -310,10 +316,46 @@ public class TNTSimulator {
|
||||
|
||||
private Set<TNTSpawn> tntSpawns = new HashSet<>();
|
||||
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Chaoscaot
hat
Kann das nicht am anfang der Datei stehen? May be final Kann das nicht am anfang der Datei stehen? May be final
|
||||
private static class TNTSpawnPair {
|
||||
|
||||
private int countLeft;
|
||||
private TNTSpawn tntSpawn;
|
||||
|
||||
public TNTSpawnPair(int countLeft, TNTSpawn tntSpawn) {
|
||||
this.countLeft = countLeft;
|
||||
this.tntSpawn = tntSpawn;
|
||||
}
|
||||
|
||||
private void spawn() {
|
||||
tntSpawn.spawn();
|
||||
countLeft--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void start() {
|
||||
Map<Integer, List<TNTSpawnPair>[]> tntSpawnMap = new HashMap<>();
|
||||
tntSpawns.forEach(tntSpawn -> {
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), tntSpawn::spawn, tntSpawn.getTickOffset() + 1L);
|
||||
tntSpawnMap.computeIfAbsent(tntSpawn.getTickOffset(), integer -> new ArrayList[]{new ArrayList<>(), new ArrayList<>()})[tntSpawn.isComparator() ? 1 : 0].add(new TNTSpawnPair(tntSpawn.getCount(), tntSpawn));
|
||||
});
|
||||
tntSpawnMap.forEach((integer, tntSpawnPairs) -> {
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> {
|
||||
spawnRandomList(tntSpawnPairs[0]);
|
||||
spawnRandomList(tntSpawnPairs[1]);
|
||||
}, integer + 1L);
|
||||
});
|
||||
}
|
||||
|
||||
private void spawnRandomList(List<TNTSpawnPair> tntSpawnPairs) {
|
||||
AtomicInteger index = new AtomicInteger(tntSpawnPairs.size() - 1);
|
||||
while (!tntSpawnPairs.isEmpty()) {
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Chaoscaot
hat
Warum wird hierfür ein AtomicInteger benötigt? Warum wird hierfür ein AtomicInteger benötigt?
YoyoNow
hat
Weil effectively final und final variablen! Weil effectively final und final variablen!
YoyoNow
hat
Wobei im Moment vllt auch nicht mehr so wichtig. Wobei im Moment vllt auch nicht mehr so wichtig.
|
||||
TNTSpawnPair tntSpawnPair = tntSpawnPairs.get(index.get());
|
||||
tntSpawnPair.spawn();
|
||||
if (tntSpawnPair.countLeft <= 0) {
|
||||
tntSpawnPairs.remove(index.get());
|
||||
}
|
||||
if (index.decrementAndGet() < 0) index.set(tntSpawnPairs.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -38,20 +38,19 @@ public class TNTSpawn implements Comparable<TNTSpawn> {
|
||||
private boolean xVelocity = true;
|
||||
private boolean yVelocity = true;
|
||||
private boolean zVelocity = true;
|
||||
private boolean comparator = false;
|
||||
|
||||
public TNTSpawn(Vector position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public void spawn() {
|
||||
for (int i = 0; i < count; i++) {
|
||||
WORLD.spawn(position.toLocation(WORLD), TNTPrimed.class, tntPrimed -> {
|
||||
tntPrimed.setFuseTicks(fuseTicks);
|
||||
if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0));
|
||||
if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0));
|
||||
if (!zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0));
|
||||
});
|
||||
}
|
||||
WORLD.spawn(position.toLocation(WORLD), TNTPrimed.class, tntPrimed -> {
|
||||
tntPrimed.setFuseTicks(fuseTicks);
|
||||
if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0));
|
||||
if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0));
|
||||
if (!zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0));
|
||||
});
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -118,6 +117,14 @@ public class TNTSpawn implements Comparable<TNTSpawn> {
|
||||
this.zVelocity = zVelocity;
|
||||
}
|
||||
|
||||
public boolean isComparator() {
|
||||
return comparator;
|
||||
}
|
||||
|
||||
public void setComparator(boolean comparator) {
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(TNTSpawn tntSpawn) {
|
||||
return -Integer.compare(tickOffset, tntSpawn.tickOffset);
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Warum braucht das sein eigenes Package? Und kann nicht einfach in das
world
package rein?