forked from SteamWar/SteamWar
@@ -393,6 +393,9 @@ INVENTORY_FILL_DISABLE=§cInventoryFiller deactivated
|
||||
INVENTORY_FILL_GUI_NAME=Inventory Filler
|
||||
INVENTORY_FILL_GUI_POWER=§ePower§8:§7 {0}
|
||||
INVENTORY_FILL_GUI_TNT=§eTNT
|
||||
# Ray Visualizer
|
||||
RAY_VISUALIZER_ENABLE=§aRayVisualizer activated
|
||||
RAY_VISUALIZER_DISABLE=§aRayVisualizer deactivated
|
||||
# Killchecker
|
||||
KILLCHECKER_HELP_ENABLE=§8/§ekillchecker enable §8- §7Enables Killchecker / Recalculates kills
|
||||
KILLCHECKER_HELP_DISABLE=§8/§ekillchecker disable §8- §7Disables Killchecker
|
||||
|
||||
@@ -350,8 +350,11 @@ SMART_PLACE_DISABLE=§cSmartPlace deaktiviert
|
||||
# InventoryFiller
|
||||
INVENTORY_FILL_HELP=§8/§einventoryfill §8- §7Toggled InventoryFill
|
||||
INVENTORY_FILL_INFO=§7Hilft dir, Behälter zu füllen, indem du sie beim sneaken ansiehst und den Gegenstand fallen lässt. Oder scrolle einfach auf einen Behälter, um die Menge des gehaltenen Gegenstandes darin zu ändern.
|
||||
INVENTORY_FILL_ENABLE=§aInventoryFiller activated
|
||||
INVENTORY_FILL_DISABLE=§cInventoryFiller deactivated
|
||||
INVENTORY_FILL_ENABLE=§aInventoryFiller aktiviert
|
||||
INVENTORY_FILL_DISABLE=§cInventoryFiller deaktiviert
|
||||
# Ray Visualizer
|
||||
RAY_VISUALIZER_ENABLE=§aRayVisualizer aktiviert
|
||||
RAY_VISUALIZER_DISABLE=§aRayVisualizer deaktiviert
|
||||
# Killchecker
|
||||
KILLCHECKER_HELP_ENABLE=§8/§ekillchecker enable §8- §7Aktiviert Killchecker / Berechnet kills neu
|
||||
KILLCHECKER_HELP_DISABLE=§8/§ekillchecker disable §8- §7Deaktiviert Killchecker
|
||||
|
||||
+201
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* 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.features.rayvisualizer;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
import de.steamwar.bausystem.configplayer.Config;
|
||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.entity.CRay;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.MinVersion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.util.RayTraceResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Linked
|
||||
@MinVersion(20)
|
||||
public class RayVisualizerCommand extends SWCommand implements Listener {
|
||||
|
||||
private class CRayData {
|
||||
private CRay[] rays = new CRay[27 * 400];
|
||||
private boolean[] used = new boolean[27 * 400];
|
||||
|
||||
public void reset() {
|
||||
for (int i = 0; i < 27 * 400; i++) {
|
||||
if (!used[i] && rays[i] != null) {
|
||||
rays[i].die();
|
||||
rays[i] = null;
|
||||
}
|
||||
used[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean locEquals(Location loc1, Location loc2) {
|
||||
if ((long)(loc1.getX() * 1000) != (long)(loc2.getX() * 1000)) return false;
|
||||
if ((long)(loc1.getY() * 1000) != (long)(loc2.getY() * 1000)) return false;
|
||||
if ((long)(loc1.getZ() * 1000) != (long)(loc2.getZ() * 1000)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public CRay get(Location from, Location to) {
|
||||
for (int i = 0; i < rays.length; i++) {
|
||||
if (rays[i] != null && locEquals(from, rays[i].getFrom()) && locEquals(to, rays[i].getTo())) {
|
||||
used[i] = true;
|
||||
return rays[i];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < rays.length; i++) {
|
||||
if (rays[i] != null && locEquals(from, rays[i].getFrom()) && !used[i]) {
|
||||
used[i] = true;
|
||||
return rays[i];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < rays.length; i++) {
|
||||
if (used[i]) continue;
|
||||
CRay ray = rays[i];
|
||||
if (ray != null) {
|
||||
return ray;
|
||||
}
|
||||
ray = new CRay(server);
|
||||
ray.setBlock(Material.LIME_CONCRETE.createBlockData());
|
||||
ray.setWidth(1 / 32f);
|
||||
rays[i] = ray;
|
||||
used[i] = true;
|
||||
return ray;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private CRayData rayData = new CRayData();
|
||||
|
||||
private final REntityServer server = new REntityServer();
|
||||
private final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
||||
public RayVisualizerCommand() {
|
||||
super("rayvisualizer");
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
||||
if (server.getPlayers().isEmpty()) return;
|
||||
Map<Integer, List<TNTPrimed>> primedList = WORLD.getEntitiesByClass(TNTPrimed.class)
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(TNTPrimed::getFuseTicks));
|
||||
rayData.reset();
|
||||
if (primedList.isEmpty()) return;
|
||||
|
||||
List<Integer> fuseTicks = primedList.keySet().stream().sorted().collect(Collectors.toList());
|
||||
List<TNTPrimed> current = new ArrayList<>();
|
||||
for (int i = 0; i < fuseTicks.size(); i++) {
|
||||
List<TNTPrimed> tnts = primedList.get(fuseTicks.get(i));
|
||||
calculateRays(current, tnts);
|
||||
current.addAll(tnts);
|
||||
}
|
||||
}, 1, 1);
|
||||
}
|
||||
|
||||
private void calculateRays(List<TNTPrimed> fromTNTs, List<TNTPrimed> toTNTs) {
|
||||
for (TNTPrimed from : fromTNTs) {
|
||||
if (!from.isInWater()) continue;
|
||||
for (TNTPrimed to : toTNTs) {
|
||||
if (from == to) continue;
|
||||
if (to.getLocation().distanceSquared(from.getLocation()) > 25) continue;
|
||||
|
||||
Location fromLoc = from.getLocation();
|
||||
Location toLoc = to.getLocation().clone().add(-0.49, 0, -0.49);
|
||||
|
||||
final double minX = 0.5 * (1 - Math.floor(2 * 0.98 + 1) / (2 * 0.98 + 1));
|
||||
final double minZ = 0.5 * (1 - Math.floor(2 * 0.98 + 1) / (2 * 0.98 + 1));
|
||||
final double spacing = 0.98 / (2 * 0.98 + 1);
|
||||
|
||||
for (int dx = 0; dx < 3; dx++) {
|
||||
for (int dy = 0; dy < 3; dy++) {
|
||||
for (int dz = 0; dz < 3; dz++) {
|
||||
Location end = toLoc.clone().add(minX + dx * spacing, 0 + dy * spacing, minZ + dz * spacing);
|
||||
RayTraceResult result = fromLoc.getWorld().rayTraceBlocks(fromLoc, end.clone().subtract(fromLoc).toVector(), end.distance(fromLoc));
|
||||
if (result != null && result.getHitBlock() != null) {
|
||||
continue;
|
||||
}
|
||||
CRay cRay = rayData.get(fromLoc, end);
|
||||
if (cRay == null) continue;
|
||||
cRay.setFrom(fromLoc);
|
||||
cRay.setTo(end);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
boolean rayvisualizer = Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("rayvisualizer", false);
|
||||
if (rayvisualizer) server.addPlayer(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
server.removePlayer(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (Permission.BUILD.hasPermission(player)) {
|
||||
boolean rayvisualizer = Config.getInstance().get(player).getPlainValueOrDefault("rayvisualizer", false);
|
||||
if (rayvisualizer) server.addPlayer(player);
|
||||
} else {
|
||||
server.removePlayer(player);
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@Register
|
||||
public void toggle(@Validator Player player) {
|
||||
boolean rayvisualizer = Config.getInstance().get(player).getPlainValueOrDefault("rayvisualizer", false);
|
||||
Config.getInstance().get(player).put("rayvisualizer", !rayvisualizer);
|
||||
if (!rayvisualizer) {
|
||||
SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("RAY_VISUALIZER_ENABLE", player));
|
||||
server.addPlayer(player);
|
||||
} else {
|
||||
SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("RAY_VISUALIZER_DISABLE", player));
|
||||
server.removePlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user