ScriptSystemImprovements #209
@ -24,7 +24,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.FallingBlock;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -36,7 +36,7 @@ class TPSLimit_12 {
|
|||||||
|
|
||||||
static void createTickCache(World world) {
|
static void createTickCache(World world) {
|
||||||
packets.clear();
|
packets.clear();
|
||||||
world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> {
|
world.getEntities().stream().filter(entity -> !(entity instanceof Player)).forEach(entity -> {
|
||||||
packets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), 0, 0, 0));
|
packets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), 0, 0, 0));
|
||||||
packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
|
packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity {
|
|||||||
} else if (references++ > 0)
|
} else if (references++ > 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0, 0);
|
PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 70, Block.getCombinedId(getBlock()));
|
||||||
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
playerConnection.sendPacket(packetPlayOutSpawnEntity);
|
playerConnection.sendPacket(packetPlayOutSpawnEntity);
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.FallingBlock;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -37,7 +37,7 @@ class TPSLimit_15 {
|
|||||||
|
|
||||||
static void createTickCache(World world) {
|
static void createTickCache(World world) {
|
||||||
packets.clear();
|
packets.clear();
|
||||||
world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> {
|
world.getEntities().stream().filter(entity -> !(entity instanceof Player)).forEach(entity -> {
|
||||||
packets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), noMotion));
|
packets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), noMotion));
|
||||||
packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
|
packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import de.steamwar.bausystem.commands.*;
|
|||||||
import de.steamwar.bausystem.world.*;
|
import de.steamwar.bausystem.world.*;
|
||||||
import de.steamwar.core.CommandRemover;
|
import de.steamwar.core.CommandRemover;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
|
import de.steamwar.core.VersionedRunnable;
|
||||||
import de.steamwar.scoreboard.SWScoreboard;
|
import de.steamwar.scoreboard.SWScoreboard;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -101,6 +102,7 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
getCommand("scriptvars").setTabCompleter(new CommandScriptVarsTabCompleter());
|
getCommand("scriptvars").setTabCompleter(new CommandScriptVarsTabCompleter());
|
||||||
getCommand("simulator").setExecutor(new CommandSimulator());
|
getCommand("simulator").setExecutor(new CommandSimulator());
|
||||||
getCommand("simulator").setTabCompleter(new CommandSimulatorTabCompleter());
|
getCommand("simulator").setTabCompleter(new CommandSimulatorTabCompleter());
|
||||||
|
getCommand("redstonetester").setExecutor(new CommandRedstoneTester());
|
||||||
getCommand("gui").setExecutor(new CommandGUI());
|
getCommand("gui").setExecutor(new CommandGUI());
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(this, this);
|
Bukkit.getPluginManager().registerEvents(this, this);
|
||||||
@ -111,6 +113,7 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
Bukkit.getPluginManager().registerEvents(new TNTSimulatorListener(), this);
|
Bukkit.getPluginManager().registerEvents(new TNTSimulatorListener(), this);
|
||||||
Bukkit.getPluginManager().registerEvents(new CommandGUI(), this);
|
Bukkit.getPluginManager().registerEvents(new CommandGUI(), this);
|
||||||
Bukkit.getPluginManager().registerEvents(new DetonatorListener(), this);
|
Bukkit.getPluginManager().registerEvents(new DetonatorListener(), this);
|
||||||
|
VersionedRunnable.call(new VersionedRunnable(() -> Bukkit.getPluginManager().registerEvents(new RedstoneListener(), this), 15));
|
||||||
new AFKStopper();
|
new AFKStopper();
|
||||||
|
|
||||||
autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200);
|
autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200);
|
||||||
|
@ -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");
|
||||||
}
|
}
|
||||||
|
@ -53,8 +53,6 @@ public class CommandGUI implements CommandExecutor, Listener {
|
|||||||
OPEN_INVS.remove(player);
|
OPEN_INVS.remove(player);
|
||||||
});
|
});
|
||||||
|
|
||||||
inv.setItem(37, getMaterial("GLASS_PANE", "THIN_GLASS"), "§7Platzhalter", clickType -> {
|
|
||||||
});
|
|
||||||
inv.setItem(43, getMaterial("GLASS_PANE", "THIN_GLASS"), "§7Platzhalter", clickType -> {
|
inv.setItem(43, getMaterial("GLASS_PANE", "THIN_GLASS"), "§7Platzhalter", clickType -> {
|
||||||
});
|
});
|
||||||
inv.setItem(42, Material.NETHER_STAR, "§7Bau GUI Item", Arrays.asList("§7Du kannst dieses Item zum Öffnen der BauGUI nutzen", "§7oder Doppel F (Swap hands) drücken."), false, clickType -> {
|
inv.setItem(42, Material.NETHER_STAR, "§7Bau GUI Item", Arrays.asList("§7Du kannst dieses Item zum Öffnen der BauGUI nutzen", "§7oder Doppel F (Swap hands) drücken."), false, clickType -> {
|
||||||
@ -78,6 +76,14 @@ public class CommandGUI implements CommandExecutor, Listener {
|
|||||||
player.performCommand("sim wand");
|
player.performCommand("sim wand");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ItemStack redstoneWand = wand(player, RedstoneListener.WAND, "§8/§7redstonetester", Permission.build, "Du hast keine Buildrechte");
|
||||||
|
inv.setItem(37, redstoneWand, clickType -> {
|
||||||
|
if (Welt.noPermission(player, Permission.build))
|
||||||
|
return;
|
||||||
|
player.closeInventory();
|
||||||
|
player.performCommand("redstonetester");
|
||||||
|
});
|
||||||
|
|
||||||
inv.setItem(40, getMaterial("WOODEN_AXE", "WOOD_AXE"), "§eWorldedit Axt", getNoPermsLore(Arrays.asList("§8//§7wand"), player, "§cDu hast keine Worldeditrechte", Permission.worldedit), false, clickType -> {
|
inv.setItem(40, getMaterial("WOODEN_AXE", "WOOD_AXE"), "§eWorldedit Axt", getNoPermsLore(Arrays.asList("§8//§7wand"), player, "§cDu hast keine Worldeditrechte", Permission.worldedit), false, clickType -> {
|
||||||
if (Welt.noPermission(player, Permission.world))
|
if (Welt.noPermission(player, Permission.world))
|
||||||
return;
|
return;
|
||||||
@ -571,7 +577,7 @@ public class CommandGUI implements CommandExecutor, Listener {
|
|||||||
ItemMeta meta = base.getItemMeta();
|
ItemMeta meta = base.getItemMeta();
|
||||||
List<String> lore = meta.getLore();
|
List<String> lore = meta.getLore();
|
||||||
lore.add(command);
|
lore.add(command);
|
||||||
if (Welt.noPermission(player, permission))
|
if (permission != null && Welt.noPermission(player, permission))
|
||||||
lore.add(noPermissionMessage);
|
lore.add(noPermissionMessage);
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
base.setItemMeta(meta);
|
base.setItemMeta(meta);
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.commands;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.Permission;
|
||||||
|
import de.steamwar.bausystem.SWUtils;
|
||||||
|
import de.steamwar.bausystem.world.RedstoneListener;
|
||||||
|
import de.steamwar.bausystem.world.Welt;
|
||||||
|
import de.steamwar.core.VersionedRunnable;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class CommandRedstoneTester implements CommandExecutor {
|
||||||
|
|
||||||
|
private boolean permissionCheck(Player player) {
|
||||||
|
if (Welt.noPermission(player, Permission.build)) {
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Redstonetester nutzen");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
|
||||||
|
if (!(commandSender instanceof Player))
|
||||||
|
return false;
|
||||||
|
Player player = (Player) commandSender;
|
||||||
|
VersionedRunnable.call(new VersionedRunnable(() -> {
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "Der RedstoneTester ist nicht in der 1.12 verfügbar");
|
||||||
|
}, 8), new VersionedRunnable(() -> {
|
||||||
|
if (!permissionCheck(player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten");
|
||||||
|
SWUtils.giveItemToPlayer(player, RedstoneListener.WAND);
|
||||||
|
}, 15));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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 {
|
||||||
execute(player, detonator.getLocs());
|
ItemStack item = getNextBestDetonator(player);
|
||||||
|
if (item == null)
|
||||||
|
return;
|
||||||
|
Detonator detonator = getDetonator(player, item);
|
||||||
|
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,40 +27,35 @@ 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(
|
new VersionedCallable<>(() -> AutoLoader_12.onPlayerInteractLoader(event), 12),
|
||||||
new VersionedCallable<>(() -> AutoLoader_12.onPlayerInteractLoader(event), 12),
|
new VersionedCallable<>(() -> AutoLoader_15.onPlayerInteractLoader(event), 15));
|
||||||
new VersionedCallable<>(() -> AutoLoader_15.onPlayerInteractLoader(event), 15));
|
|
||||||
|
|
||||||
if (detoloader == null) {
|
if (detoloader == null) {
|
||||||
return;
|
return;
|
||||||
} else if (detoloader.activation == -1) {
|
} else if (detoloader.activation == -1) {
|
||||||
print(player, detoloader.getBlock(), detoloader.addBack ? Detonator.getDetonator(player, player.getInventory().getItemInMainHand()).getLocs().size() : 0);
|
print(player, detoloader.getBlock(), detoloader.addBack ? Detonator.getDetonator(player, player.getInventory().getItemInMainHand()).getLocs().size() : 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getPlayer().isSneaking()) {
|
if (event.getPlayer().isSneaking()) {
|
||||||
player.getInventory().setItemInMainHand(Detonator.toggleLocation(item, player, detoloader, event.getClickedBlock().getLocation()));
|
player.getInventory().setItemInMainHand(Detonator.toggleLocation(item, player, detoloader, event.getClickedBlock().getLocation()));
|
||||||
|
} else {
|
||||||
|
if (detoloader.getActivation() == 0) {
|
||||||
|
player.getInventory().setItemInMainHand(Detonator.setLocation(player, item, new Detoloader.DetonatorActivation(event.getClickedBlock().getLocation())));
|
||||||
} else {
|
} else {
|
||||||
if (detoloader.getActivation() == 0) {
|
player.getInventory().setItemInMainHand(Detonator.setLocation(player, item, new Detoloader.DetonatorActivation(detoloader.activation, event.getClickedBlock().getLocation())));
|
||||||
player.getInventory().setItemInMainHand(Detonator.setLocation(player, item, new Detoloader.DetonatorActivation(event.getClickedBlock().getLocation())));
|
|
||||||
} else {
|
|
||||||
player.getInventory().setItemInMainHand(Detonator.setLocation(player, item, new Detoloader.DetonatorActivation(detoloader.activation, event.getClickedBlock().getLocation())));
|
|
||||||
}
|
|
||||||
print(player, detoloader.addBack ? "§e" + detoloader.getBlock() + " gesetzt" :
|
|
||||||
detoloader.getBlock(), detoloader.addBack ? Detonator.getDetonator(player, player.getInventory().getItemInMainHand()).getLocs().size() : 0);
|
|
||||||
}
|
}
|
||||||
break;
|
print(player, detoloader.addBack ? "§e" + detoloader.getBlock() + " gesetzt" :
|
||||||
case RIGHT_CLICK_AIR:
|
detoloader.getBlock(), detoloader.addBack ? Detonator.getDetonator(player, player.getInventory().getItemInMainHand()).getLocs().size() : 0);
|
||||||
case RIGHT_CLICK_BLOCK:
|
}
|
||||||
Detonator.execute(player);
|
break;
|
||||||
break;
|
case RIGHT_CLICK_AIR:
|
||||||
}
|
case RIGHT_CLICK_BLOCK:
|
||||||
} catch (RuntimeException e) {
|
Detonator.execute(player);
|
||||||
player.sendMessage(BauSystem.PREFIX + "§c" + e.getMessage());
|
break;
|
||||||
player.getInventory().setItemInMainHand(item);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
175
BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java
Normale Datei
175
BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java
Normale Datei
@ -0,0 +1,175 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.world;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.Permission;
|
||||||
|
import de.steamwar.inventory.SWItem;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.block.data.Powerable;
|
||||||
|
import org.bukkit.block.data.type.Piston;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockDispenseEvent;
|
||||||
|
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||||
|
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||||
|
import org.bukkit.event.block.BlockRedstoneEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class RedstoneListener implements Listener {
|
||||||
|
|
||||||
|
public static final ItemStack WAND = new SWItem(Material.BLAZE_ROD, "§eRedstonetester", Arrays.asList("§eLinksklick Block §8- §7Setzt die 1. Position", "§eRechtsklick Block §8- §7Setzt die 2. Position", "§eShift-Rechtsklick Luft §8- §7Zurücksetzten"), false, null).getItemStack();
|
||||||
|
private static Map<Player, RedstoneTester> playerMap = new HashMap<>();
|
||||||
|
|
||||||
|
private boolean permissionCheck(Player player) {
|
||||||
|
if (Welt.noPermission(player, Permission.build)) {
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Redstonetester nutzen");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
|
if (!WAND.isSimilar(event.getItem())) return;
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
Block block = event.getClickedBlock();
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
if (!permissionCheck(event.getPlayer())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (event.getAction()) {
|
||||||
|
case RIGHT_CLICK_AIR:
|
||||||
|
if (player.isSneaking()) {
|
||||||
|
playerMap.remove(event.getPlayer());
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "Positionen gelöscht§8.");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LEFT_CLICK_BLOCK:
|
||||||
|
if (!validBlock(event.getPlayer(), block.getBlockData())) return;
|
||||||
|
playerMap.computeIfAbsent(event.getPlayer(), RedstoneTester::new).loc1 = block.getLocation();
|
||||||
|
sendLocation(event.getPlayer(), "POS1", block.getLocation());
|
||||||
|
break;
|
||||||
|
case RIGHT_CLICK_BLOCK:
|
||||||
|
if (!validBlock(event.getPlayer(), block.getBlockData())) return;
|
||||||
|
playerMap.computeIfAbsent(event.getPlayer(), RedstoneTester::new).loc2 = block.getLocation();
|
||||||
|
sendLocation(event.getPlayer(), "POS2", block.getLocation());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendLocation(Player player, String prefix, Location location) {
|
||||||
|
player.sendMessage(BauSystem.PREFIX + prefix + "§8: §e" + locationToString(location));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String locationToString(Location location) {
|
||||||
|
return location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean validBlock(Player player, BlockData block) {
|
||||||
|
if (block instanceof Powerable) return true;
|
||||||
|
if (block instanceof Piston) return true;
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§cUnbekannte Position");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
playerMap.remove(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPistonExtend(BlockPistonExtendEvent e) {
|
||||||
|
playerMap.forEach((player, redstoneTester) -> {
|
||||||
|
redstoneTester.activate(e.getBlock().getLocation());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPistonRetract(BlockPistonRetractEvent e) {
|
||||||
|
playerMap.forEach((player, redstoneTester) -> {
|
||||||
|
redstoneTester.activate(e.getBlock().getLocation());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onRedstoneEvent(BlockRedstoneEvent e) {
|
||||||
|
playerMap.forEach((player, redstoneTester) -> {
|
||||||
|
redstoneTester.activate(e.getBlock().getLocation());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockDispense(BlockDispenseEvent e) {
|
||||||
|
playerMap.forEach((player, redstoneTester) -> {
|
||||||
|
redstoneTester.activate(e.getBlock().getLocation());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class RedstoneTester {
|
||||||
|
|
||||||
|
private final Player player;
|
||||||
|
private Location loc1 = null;
|
||||||
|
private Location loc2 = null;
|
||||||
|
|
||||||
|
private long lastTick = 0;
|
||||||
|
private Long tick = null;
|
||||||
|
|
||||||
|
public RedstoneTester(Player player) {
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void activate(Location location) {
|
||||||
|
if (loc1 == null || loc2 == null) {
|
||||||
|
tick = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (loc1.equals(location)) {
|
||||||
|
if (TPSUtils.currentTick.get() - lastTick > 100) {
|
||||||
|
tick = null;
|
||||||
|
}
|
||||||
|
lastTick = TPSUtils.currentTick.get();
|
||||||
|
if (tick == null) {
|
||||||
|
tick = TPSUtils.currentTick.get();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (tick != null && loc2.equals(location)) {
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "Differenz§8: §e" + (TPSUtils.currentTick.get() - tick) + "§8 - §7in Ticks §8(§7Ticks/2 -> Redstoneticks§8)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -26,6 +26,8 @@ import de.steamwar.core.TPSWatcher;
|
|||||||
import de.steamwar.core.VersionedRunnable;
|
import de.steamwar.core.VersionedRunnable;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class TPSUtils {
|
public class TPSUtils {
|
||||||
|
|
||||||
private TPSUtils() {
|
private TPSUtils() {
|
||||||
@ -36,12 +38,19 @@ public class TPSUtils {
|
|||||||
private static long nanoOffset = 0;
|
private static long nanoOffset = 0;
|
||||||
private static long nanoDOffset = 0;
|
private static long nanoDOffset = 0;
|
||||||
|
|
||||||
|
private static long ticksSinceServerStart = 0;
|
||||||
|
public static final Supplier<Long> currentTick = () -> ticksSinceServerStart;
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8),
|
VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8),
|
||||||
new VersionedRunnable(() -> {
|
new VersionedRunnable(() -> {
|
||||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> nanoOffset += nanoDOffset, 1, 1);
|
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> nanoOffset += nanoDOffset, 1, 1);
|
||||||
TPSUtils_15.init(() -> nanoOffset);
|
TPSUtils_15.init(() -> nanoOffset);
|
||||||
}, 15));
|
}, 15));
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
|
||||||
|
ticksSinceServerStart++;
|
||||||
|
}, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setTPS(double tps) {
|
public static void setTPS(double tps) {
|
||||||
|
@ -40,3 +40,5 @@ commands:
|
|||||||
simulator:
|
simulator:
|
||||||
aliases: sim
|
aliases: sim
|
||||||
gui:
|
gui:
|
||||||
|
redstonetester:
|
||||||
|
aliases: rt
|
In neuem Issue referenzieren
Einen Benutzer sperren