Dieser Commit ist enthalten in:
Ursprung
16a5de7a84
Commit
0ca3ede280
@ -52,7 +52,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class WorldEditWrapper14 implements WorldEditWrapper.IWorldEditWrapper {
|
||||
public class WorldEditWrapper14 implements WorldEditWrapper {
|
||||
|
||||
private static final ClipboardFormat SCHEMATIC = ClipboardFormats.findByAlias("schematic");
|
||||
private static final ClipboardFormat SCHEM = ClipboardFormats.findByAlias("schem");
|
||||
@ -131,6 +131,21 @@ public class WorldEditWrapper14 implements WorldEditWrapper.IWorldEditWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.util.Vector getOrigin(Clipboard clipboard) {
|
||||
return new org.bukkit.util.Vector(clipboard.getOrigin().getX(), clipboard.getOrigin().getY(), clipboard.getOrigin().getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.util.Vector getMinimum(Region region) {
|
||||
return new org.bukkit.util.Vector(region.getMinimumPoint().getX(), region.getMinimumPoint().getY(), region.getMinimumPoint().getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.util.Vector getMaximum(Region region) {
|
||||
return new org.bukkit.util.Vector(region.getMaximumPoint().getX(), region.getMaximumPoint().getY(), region.getMaximumPoint().getZ());
|
||||
}
|
||||
|
||||
private static class MCEditSchematicReader extends NBTSchematicReader {
|
||||
|
||||
private final NBTInputStream inputStream;
|
||||
|
@ -23,7 +23,6 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.sk89q.jnbt.*;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
@ -34,17 +33,24 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.SchematicReader;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.world.registry.WorldData;
|
||||
import de.steamwar.sql.NoClipboardException;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class WorldEditWrapper8 implements WorldEditWrapper.IWorldEditWrapper {
|
||||
public class WorldEditWrapper8 implements WorldEditWrapper {
|
||||
|
||||
@Override
|
||||
public InputStream getPlayerClipboard(Player player, boolean schemFormat) {
|
||||
@ -105,6 +111,21 @@ public class WorldEditWrapper8 implements WorldEditWrapper.IWorldEditWrapper {
|
||||
return new SchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.util.Vector getOrigin(Clipboard clipboard) {
|
||||
return new org.bukkit.util.Vector(clipboard.getOrigin().getX(), clipboard.getOrigin().getY(), clipboard.getOrigin().getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.util.Vector getMinimum(Region region) {
|
||||
return new org.bukkit.util.Vector(region.getMinimumPoint().getX(), region.getMinimumPoint().getY(), region.getMinimumPoint().getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.util.Vector getMaximum(Region region) {
|
||||
return new org.bukkit.util.Vector(region.getMaximumPoint().getX(), region.getMaximumPoint().getY(), region.getMaximumPoint().getZ());
|
||||
}
|
||||
|
||||
private static class SpongeSchematicReader implements ClipboardReader {
|
||||
|
||||
private final NBTInputStream inputStream;
|
||||
|
@ -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);
|
||||
|
116
SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java
Normale Datei
116
SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java
Normale Datei
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
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 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() != Material.WOODEN_AXE)
|
||||
continue;
|
||||
|
||||
LocalSession session = we.getSession(player);
|
||||
try {
|
||||
Clipboard clipboard = session.getClipboard().getClipboard();
|
||||
Region region = clipboard.getRegion();
|
||||
Vector offset = player.getLocation().toVector().subtract(WorldEditWrapper.impl.getOrigin(clipboard));
|
||||
drawCuboid(
|
||||
WorldEditWrapper.impl.getMinimum(region).add(offset),
|
||||
WorldEditWrapper.impl.getMaximum(region).add(offset),
|
||||
Particle.VILLAGER_HAPPY, player
|
||||
);
|
||||
} catch (EmptyClipboardException e) {
|
||||
//ignore
|
||||
}
|
||||
|
||||
RegionSelector regionSelector = session.getRegionSelector(session.getSelectionWorld());
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -21,24 +21,26 @@ package de.steamwar.core;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
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);
|
||||
|
||||
public static WorldEditPlugin getWorldEditPlugin() {
|
||||
static WorldEditPlugin getWorldEditPlugin() {
|
||||
return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren