SteamWar/BauSystem
Archiviert
13
0

Merge remote-tracking branch 'origin/master'

Dieser Commit ist enthalten in:
jojo 2021-01-11 17:17:46 +01:00
Commit dfaa04d0c4
6 geänderte Dateien mit 89 neuen und 73 gelöschten Zeilen

Datei anzeigen

@ -24,6 +24,7 @@ import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Openable;
import org.bukkit.block.data.Powerable;
import org.bukkit.block.data.type.Switch;
import org.bukkit.event.player.PlayerInteractEvent;
@ -48,10 +49,17 @@ class AutoLoader_15 {
if (!(data instanceof Powerable))
return false;
Powerable powerable = (Powerable) data;
powerable.setPowered(active);
block.setBlockData(powerable);
if(data instanceof Openable) {
Openable openable = (Openable) data;
openable.setOpen(active);
block.setBlockData(openable);
}
if (data instanceof Switch) {
Switch swtch = (Switch) data;
Block relative;
@ -90,11 +98,7 @@ class AutoLoader_15 {
Material material = block.getType();
if (material == Material.LEVER) {
if (powerable.isPowered()) {
return new Detoloader("Hebel", 0).setActive(false);
} else {
return new Detoloader("Hebel", 0).setActive(true);
}
return new Detoloader("Hebel", 0).setActive(!powerable.isPowered());
} else if (material == Material.STONE_BUTTON) {
return new Detoloader("Knopf", Detoloader.STONE_BUTTON);
} else if (material.name().contains("PRESSURE_PLATE")){
@ -111,6 +115,8 @@ class AutoLoader_15 {
}
static boolean getLever(Block block) {
if(!(block.getBlockData() instanceof Powerable))
return false;
return ((Powerable) block.getBlockData()).isPowered();
}
}

Datei anzeigen

@ -83,5 +83,5 @@ public class Detoloader {
public static final int WOODEN_BUTTON = 30;
public static final int PRESSURE_PLATE = 20;
public static final int NOTE_BLOCK = 1;
public static final int TRIPWIRE = 10;
public static final int TRIPWIRE = 20;
}

Datei anzeigen

@ -34,6 +34,7 @@ public class CommandDetonator implements CommandExecutor {
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 reset §8- §7Löscht alle markierten Positionen");
player.sendMessage("§8/§edetonator remove §8- §7Entfernt den Fernzünder");
}
private boolean permissionCheck(Player player) {
@ -65,16 +66,20 @@ public class CommandDetonator implements CommandExecutor {
player.updateInventory();
Detonator.getDetonator(player);
break;
case "delete":
case "reset":
case "remove":
Detonator.deleteDetonator(player);
player.getInventory().removeItem(Detonator.WAND);
break;
case "detonate":
case "click":
case "use":
Detonator.getDetonator(player).execute();
break;
case "clear":
case "delete":
case "reset":
Detonator.getDetonator(player).clearLocs();
break;
default:
help(player);
}

Datei anzeigen

@ -40,6 +40,7 @@ public class CommandDetonatorTabCompleter implements TabCompleter {
tabComplete.add("wand");
tabComplete.add("reset");
tabComplete.add("detonate");
tabComplete.add("remove");
if (args.length >= 2) {
return new ArrayList<>();

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.bausystem.world;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.core.Core;
import de.steamwar.core.VersionedCallable;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -64,6 +65,7 @@ public class AutoLoader extends IAutoLoader implements Listener {
private int waitTicks;
private ListIterator<LoaderAction> lastAction;
private boolean setup;
private Location lastLocation;
private AutoLoader(Player player){
this.player = player;
@ -166,25 +168,25 @@ public class AutoLoader extends IAutoLoader implements Listener {
if (!setup || !event.getPlayer().equals(player))
return;
Detoloader detoloader = null;
switch(Core.getVersion()){
case 15:
detoloader = AutoLoader_15.onPlayerInteractLoader(event);
break;
default:
detoloader = AutoLoader_12.onPlayerInteractLoader(event);
Detoloader detoloader = VersionedCallable.call(
new VersionedCallable<>(() -> AutoLoader_12.onPlayerInteractLoader(event), 12),
new VersionedCallable<>(() -> AutoLoader_15.onPlayerInteractLoader(event), 15));
}
if (detoloader == null || detoloader.getActivation() < 0) return;
if(detoloader.useActive)
if (lastLocation != null && lastLocation.distance(event.getClickedBlock().getLocation()) <= 1) return;
if (detoloader.useActive) {
new IAutoLoader.RedstoneActivation(this, event.getClickedBlock().getLocation()
, detoloader.getActivation() == 0 ? getLastActivation() : detoloader.getActivation()
, detoloader.isActive());
else
} else {
new IAutoLoader.TemporaryActivation(this, event.getClickedBlock().getLocation()
, detoloader.getActivation());
}
print(detoloader.addBack ? "§e" + detoloader.getBlock() + " betätigt" :
detoloader.getBlock(), detoloader.addBack);
lastLocation = event.getClickedBlock().getLocation();
}
@EventHandler

Datei anzeigen

@ -20,13 +20,15 @@
package de.steamwar.bausystem.world;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.core.Core;
import de.steamwar.core.VersionedCallable;
import de.steamwar.core.VersionedRunnable;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@ -72,36 +74,28 @@ public class Detonator implements Listener {
public static void deleteDetonator(Player player) {
if (players.containsKey(player))
players.remove(player);
HandlerList.unregisterAll(players.remove(player));
}
public void execute() {
for (Detoloader.DetonatorActivation activation : getLocations()) {
Boolean powered;
if(activation.activation == -1) switch (Core.getVersion()) {
case 15:
try {
powered = AutoLoader_15.getLever(activation.location.getBlock());
}catch (ClassCastException e) {
locs.remove(activation);
return;
}
AutoLoader_15.setRedstone(activation.location, !powered);
break;
default:
powered = AutoLoader_12.getLever(activation.location.getBlock());
if (activation.activation == -1) {
VersionedRunnable.call(new VersionedRunnable(() -> {
boolean powered = AutoLoader_12.getLever(activation.location.getBlock());
AutoLoader_12.setRedstone(activation.location, !powered);
}else switch (Core.getVersion()) {
case 15:
AutoLoader_15.setRedstone(activation.location, true);
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () ->
AutoLoader_15.setRedstone(activation.location, false), activation.activation);
break;
default:
}, 12), new VersionedRunnable(() -> {
boolean powered = AutoLoader_15.getLever(activation.location.getBlock());
AutoLoader_15.setRedstone(activation.location, !powered);
}, 15));
} else {
VersionedRunnable.call(new VersionedRunnable(() -> {
AutoLoader_12.setRedstone(activation.location, true);
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () ->
AutoLoader_12.setRedstone(activation.location, false), activation.activation);
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> AutoLoader_12.setRedstone(activation.location, false), activation.activation);
}, 12), new VersionedRunnable(() -> {
AutoLoader_15.setRedstone(activation.location, true);
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> AutoLoader_15.setRedstone(activation.location, false), activation.activation);
}, 15));
}
}
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§a" + locs.size() + " Punkt" + (locs.size() > 1 ? "e" : "") + " ausgelöst!"));
@ -111,21 +105,23 @@ public class Detonator implements Listener {
public void onPlayerInteract(PlayerInteractEvent event) {
if (!event.getPlayer().equals(player))
return;
if (event.getItem() == null) return;
if (event.getItem().isSimilar(WAND)) {
event.setCancelled(true);
switch (event.getAction()) {
case LEFT_CLICK_BLOCK:
Detoloader detoloader;
switch(Core.getVersion()){
case 15:
detoloader = AutoLoader_15.onPlayerInteractLoader(event);
break;
default:
detoloader = AutoLoader_12.onPlayerInteractLoader(event);
Detoloader detoloader = VersionedCallable.call(
new VersionedCallable<>(() -> AutoLoader_12.onPlayerInteractLoader(event), 12),
new VersionedCallable<>(() -> AutoLoader_15.onPlayerInteractLoader(event), 15));
if (detoloader == null) {
return;
} else if (detoloader.activation == -1) {
print(detoloader.getBlock(), detoloader.addBack);
return;
}
if(detoloader == null || detoloader.activation == -1) return;
if (event.getPlayer().isSneaking()) {
if (locs.stream().filter(detonatorActivation -> detonatorActivation.location.equals(event.getClickedBlock().getLocation())).collect(Collectors.toList()).size() == 1) {
@ -162,7 +158,8 @@ public class Detonator implements Listener {
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
deleteDetonator(event.getPlayer());
if (event.getPlayer().equals(player))
deleteDetonator(player);
}
Set<Detoloader.DetonatorActivation> getLocations() {
@ -173,10 +170,15 @@ public class Detonator implements Listener {
return player;
}
public void clearLocs() {
locs.clear();
}
void print(String message, boolean withSize) {
if(withSize)
if (withSize) {
getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message + " §8" + getLocations().size()));
else
}else {
getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
}
}
}