SteamWar/BauSystem
Archiviert
13
0

Merge pull request 'RedstoneTester' (#202) from RedstoneTester into master

Reviewed-on: #202
Reviewed-by: Zeanon <thezeanon@gmail.com>
Dieser Commit ist enthalten in:
YoyoNow 2021-04-01 18:21:39 +02:00
Commit 1d865806e7
6 geänderte Dateien mit 259 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -23,6 +23,7 @@ import de.steamwar.bausystem.commands.*;
import de.steamwar.bausystem.world.*;
import de.steamwar.core.CommandRemover;
import de.steamwar.core.Core;
import de.steamwar.core.VersionedRunnable;
import de.steamwar.scoreboard.SWScoreboard;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
@ -99,6 +100,7 @@ public class BauSystem extends JavaPlugin implements Listener {
getCommand("script").setExecutor(new CommandScript());
getCommand("simulator").setExecutor(new CommandSimulator());
getCommand("simulator").setTabCompleter(new CommandSimulatorTabCompleter());
getCommand("redstonetester").setExecutor(new CommandRedstoneTester());
getCommand("gui").setExecutor(new CommandGUI());
Bukkit.getPluginManager().registerEvents(this, this);
@ -109,6 +111,7 @@ public class BauSystem extends JavaPlugin implements Listener {
Bukkit.getPluginManager().registerEvents(new TNTSimulatorListener(), this);
Bukkit.getPluginManager().registerEvents(new CommandGUI(), this);
Bukkit.getPluginManager().registerEvents(new DetonatorListener(), this);
VersionedRunnable.call(new VersionedRunnable(() -> Bukkit.getPluginManager().registerEvents(new RedstoneListener(), this), 15));
new AFKStopper();
autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200);

Datei anzeigen

@ -53,8 +53,6 @@ public class CommandGUI implements CommandExecutor, Listener {
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(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");
});
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 -> {
if (Welt.noPermission(player, Permission.world))
return;
@ -571,7 +577,7 @@ public class CommandGUI implements CommandExecutor, Listener {
ItemMeta meta = base.getItemMeta();
List<String> lore = meta.getLore();
lore.add(command);
if (Welt.noPermission(player, permission))
if (permission != null && Welt.noPermission(player, permission))
lore.add(noPermissionMessage);
meta.setLore(lore);
base.setItemMeta(meta);

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -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)");
}
}
}
}

Datei anzeigen

@ -26,6 +26,8 @@ import de.steamwar.core.TPSWatcher;
import de.steamwar.core.VersionedRunnable;
import org.bukkit.Bukkit;
import java.util.function.Supplier;
public class TPSUtils {
private TPSUtils() {
@ -36,12 +38,19 @@ public class TPSUtils {
private static long nanoOffset = 0;
private static long nanoDOffset = 0;
private static long ticksSinceServerStart = 0;
public static final Supplier<Long> currentTick = () -> ticksSinceServerStart;
public static void init() {
VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8),
new VersionedRunnable(() -> {
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> nanoOffset += nanoDOffset, 1, 1);
TPSUtils_15.init(() -> nanoOffset);
}, 15));
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
ticksSinceServerStart++;
}, 1, 1);
}
public static void setTPS(double tps) {

Datei anzeigen

@ -39,3 +39,5 @@ commands:
simulator:
aliases: sim
gui:
redstonetester:
aliases: rt