Merge branch 'main' into 1.21.3

# Conflicts:
#	SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditWrapper.java
This commit is contained in:
2024-11-30 21:37:45 +01:00
18 changed files with 247 additions and 51 deletions
@@ -106,6 +106,9 @@ public class Core extends JavaPlugin{
if(Core.getVersion() >= 19)
new ServerDataHandler();
if(Core.getVersion() > 8 && Bukkit.getPluginManager().getPlugin("WorldEdit") != null)
new WorldEditRenderer();
Bukkit.getScheduler().runTaskTimer(this, TabCompletionCache::invalidateOldEntries, 20, 20);
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), SteamwarUser::clear, 72000, 72000);
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), SchematicNode::clear, 20L * 30, 20L * 30);
@@ -0,0 +1,126 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.core;
import com.sk89q.worldedit.EmptyClipboardException;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.world.World;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
public class WorldEditRenderer {
private static final int VIEW_DISTANCE = 64;
private static final int SQ_VIEW_DISTANCE = VIEW_DISTANCE * VIEW_DISTANCE;
private static final double STEP_SIZE = 0.5;
private static final Vector ONES = new Vector(1, 1, 1);
private static final Material WAND = FlatteningWrapper.impl.getMaterial("WOOD_AXE");
private final WorldEditPlugin we;
public WorldEditRenderer() {
we = WorldEditWrapper.getWorldEditPlugin();
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), this::render, 20, 20);
}
private void render() {
for(Player player : Bukkit.getOnlinePlayers()) {
//noinspection deprecation
if(player.getItemInHand().getType() != WAND)
continue;
LocalSession session = we.getSession(player);
try {
Clipboard clipboard = session.getClipboard().getClipboard();
Vector pos = player.getLocation().toVector();
Region region = clipboard.getRegion();
Transform transform = session.getClipboard().getTransform();
Vector a = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMinimum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos);
Vector b = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMaximum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos);
drawCuboid(Vector.getMinimum(a, b), Vector.getMaximum(a, b), Particle.VILLAGER_HAPPY, player);
} catch (EmptyClipboardException e) {
//ignore
}
World world = session.getSelectionWorld();
if(world != null) {
RegionSelector regionSelector = session.getRegionSelector(world);
try {
Region region = regionSelector.getRegion();
drawCuboid(WorldEditWrapper.impl.getMinimum(region), WorldEditWrapper.impl.getMaximum(region), Particle.DRAGON_BREATH, player);
} catch (IncompleteRegionException e) {
//ignore
}
}
}
}
private void drawCuboid(Vector min, Vector max, Particle particle, Player owner) {
max.add(ONES);
for(double x = min.getBlockX(); x <= max.getBlockX(); x += STEP_SIZE) {
draw(x, min.getBlockY(), min.getBlockZ(), particle, owner);
draw(x, min.getBlockY(), max.getBlockZ(), particle, owner);
draw(x, max.getBlockY(), min.getBlockZ(), particle, owner);
draw(x, max.getBlockY(), max.getBlockZ(), particle, owner);
}
for(double y = min.getBlockY() + STEP_SIZE; y <= max.getBlockY() - STEP_SIZE; y += STEP_SIZE) {
draw(min.getBlockX(), y, min.getBlockZ(), particle, owner);
draw(min.getBlockX(), y, max.getBlockZ(), particle, owner);
draw(max.getBlockX(), y, min.getBlockZ(), particle, owner);
draw(max.getBlockX(), y, max.getBlockZ(), particle, owner);
}
for(double z = min.getBlockZ() + STEP_SIZE; z <= max.getBlockZ() - STEP_SIZE; z += STEP_SIZE) {
draw(min.getBlockX(), min.getBlockY(), z, particle, owner);
draw(min.getBlockX(), max.getBlockY(), z, particle, owner);
draw(max.getBlockX(), min.getBlockY(), z, particle, owner);
draw(max.getBlockX(), max.getBlockY(), z, particle, owner);
}
}
private void draw(double x, double y, double z, Particle particle, Player owner) {
for(Player player : Bukkit.getOnlinePlayers()) {
Location location = player.getLocation();
double dx = x - location.getX();
double dy = y - location.getY();
double dz = z - location.getZ();
if(dx*dx + dy*dy + dz*dz > SQ_VIEW_DISTANCE)
continue;
player.spawnParticle(player == owner ? particle : Particle.TOWN_AURA, x, y, z, 1, 0.0, 0.0, 0.0, 0.0);
}
}
}
@@ -26,24 +26,28 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.session.ClipboardHolder;
import de.steamwar.sql.NoClipboardException;
import org.apache.logging.log4j.util.TriConsumer;
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.regions.Region;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.io.*;
import java.util.logging.Level;
public class WorldEditWrapper {
private WorldEditWrapper() {}
public interface WorldEditWrapper {
WorldEditWrapper impl = VersionDependent.getVersionImpl(Core.getInstance());
public static final IWorldEditWrapper impl = VersionDependent.getVersionImpl(Core.getInstance());
InputStream getPlayerClipboard(Player player, boolean schemFormat);
void setPlayerClipboard(Player player, InputStream is, boolean schemFormat);
Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException;
public interface IWorldEditWrapper {
InputStream getPlayerClipboard(Player player, boolean schemFormat);
void setPlayerClipboard(Player player, InputStream is, boolean schemFormat);
Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException;
}
Vector getOrigin(Clipboard clipboard);
Vector getMinimum(Region region);
Vector getMaximum(Region region);
Vector applyTransform(Vector vector, Transform transform);
public static WorldEditPlugin getWorldEditPlugin() {
static WorldEditPlugin getWorldEditPlugin() {
return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
}