Delete FAWEBridge

This commit is contained in:
Telesphoreo 2020-11-08 20:09:49 -06:00
parent 9a7cc52e03
commit 08bfd73eec
3 changed files with 0 additions and 180 deletions

View File

@ -17,7 +17,6 @@ import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker;
import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge;
import me.totalfreedom.totalfreedommod.bridge.CoreProtectBridge;
import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge;
import me.totalfreedom.totalfreedommod.bridge.FAWEBridge;
import me.totalfreedom.totalfreedommod.bridge.LibsDisguisesBridge;
import me.totalfreedom.totalfreedommod.bridge.TFGuildsBridge;
import me.totalfreedom.totalfreedommod.bridge.WorldEditBridge;
@ -146,7 +145,6 @@ public class TotalFreedomMod extends JavaPlugin
public CoreProtectBridge cpb;
public TFGuildsBridge tfg;
public WorldEditBridge web;
public FAWEBridge fab;
public WorldGuardBridge wgb;
@Override
@ -268,7 +266,6 @@ public class TotalFreedomMod extends JavaPlugin
ldb = new LibsDisguisesBridge();
tfg = new TFGuildsBridge();
web = new WorldEditBridge();
fab = new FAWEBridge();
wgb = new WorldGuardBridge();
fsh.startServices();

View File

@ -1,176 +0,0 @@
package me.totalfreedom.totalfreedommod.bridge;
import com.google.gson.Gson;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BaseBlock;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import me.totalfreedom.totalfreedommod.FreedomService;
import net.coreprotect.CoreProtect;
import net.coreprotect.CoreProtectAPI;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
public class FAWEBridge extends FreedomService
{
private final CoreProtectAPI api = plugin.cpb.getCoreProtectAPI();;
private World world = null;
private final Map<Map.Entry<String, EditSession>, Map<BlockVector3, String>> blocksBroken = new HashMap<>();
private final Map<Map.Entry<String, EditSession>, Map.Entry<Pattern, List<BlockVector3>>> blocksPlaced = new HashMap<>();
@Override
public void onStart()
{
/*
* Iterates over blocks placed by GenerationCommands (in the EditSession) and adds them to the CoreProtect logs.
*/
server.getScheduler().scheduleSyncRepeatingTask(plugin, () ->
{
if (!(blocksBroken.isEmpty() && blocksPlaced.isEmpty()))
{
// Send all broken blocks from the last ticks to the CoreProtect API.
Map.Entry<String, EditSession> playerAndSessionEntry = null;
for (Map.Entry<Map.Entry<String, EditSession>, Map<BlockVector3, String>> entry : blocksBroken.entrySet())
{
playerAndSessionEntry = entry.getKey();
Map<BlockVector3, String> dataAndVectorEntry = entry.getValue();
List<BlockVector3> blockVector3List = new ArrayList<>();
blockVector3List.addAll(dataAndVectorEntry.keySet()); // Deep clone the block vector to avoid a change later in the code.
for (BlockVector3 blockVector3 : blockVector3List)
{
if (blockVector3 != null)
{
EditSession editSession = playerAndSessionEntry.getValue();
World world = server.getWorld(editSession.getWorld().getName());
Location location = new Location(world, blockVector3.getX(), blockVector3.getY(), blockVector3.getZ());
BlockData blockData = server.createBlockData(dataAndVectorEntry.get(blockVector3));
api.logRemoval(playerAndSessionEntry.getKey(), location, blockData.getMaterial(), blockData);
}
}
}
// Clear after broken blocks have been updated.
blocksBroken.values().clear();
blocksBroken.putIfAbsent(playerAndSessionEntry, new HashMap<>());
// Send all blocks placed to the CoreProtect API (except from the air as it's only a broken block).
for (Map.Entry<Map.Entry<String, EditSession>, Map.Entry<Pattern, List<BlockVector3>>> entry : blocksPlaced.entrySet())
{
playerAndSessionEntry = entry.getKey();
Map.Entry<Pattern, List<BlockVector3>> patternAndListEntry = entry.getValue();
Pattern pattern = patternAndListEntry.getKey();
List<BlockVector3> blockVector3List = new ArrayList<>();
blockVector3List.addAll(patternAndListEntry.getValue()); // Deep clone the block vector to avoid a change later in the code.
for (BlockVector3 blockVector3 : blockVector3List)
{
if (blockVector3 != null && !pattern.apply(blockVector3).getBlockType().getMaterial().isAir())
{
World world = server.getWorld(playerAndSessionEntry.getValue().getWorld().getName());
Location location = new Location(world, blockVector3.getX(), blockVector3.getY(), blockVector3.getZ());
BaseBlock block = pattern.apply(blockVector3);
Material material = Material.getMaterial(block.getBlockType().getId().replaceFirst("minecraft:", "").toUpperCase());
api.logPlacement(playerAndSessionEntry.getKey(), location, material, material.createBlockData());
}
}
}
blocksPlaced.values().forEach(collection -> collection.getValue().clear());
}
}, 0L, 40L);
}
@Override
public void onStop()
{
}
public void logBlockEdit(String playerName, EditSession editSession, Pattern pattern, BlockVector3 blockVector3)
{
// Cache the world used for the next iterations to come.
if (world == null || !world.getName().equals(editSession.getWorld().getName()))
{
world = server.getWorld(editSession.getWorld().getName());
}
Map.Entry<String, EditSession> playerAndSessionEntry = new AbstractMap.SimpleEntry(playerName, editSession);
Block block = world.getBlockAt(blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ());
// Add the broken block to CoreProtect if it's not air.
if (!block.getType().isAir())
{
String blockData = block.getBlockData().getAsString();
blockData = new Gson().fromJson(new Gson().toJson(blockData), blockData.getClass()); // Overwrite original with deep clones.
blockVector3 = new Gson().fromJson(new Gson().toJson(blockVector3), blockVector3.getClass()); // Overwrite original with deep clones.
blocksBroken.putIfAbsent(playerAndSessionEntry, new HashMap<>());
blocksBroken.get(playerAndSessionEntry).put(blockVector3, blockData);
}
// Add the placed block to CoreProtect if it's not air.
if (!pattern.apply(blockVector3).getBlockType().getMaterial().isAir())
{
blocksPlaced.putIfAbsent(playerAndSessionEntry, new AbstractMap.SimpleEntry<>(pattern, new ArrayList<>()));
BlockVector3 vectorClone = new Gson().fromJson(new Gson().toJson(blockVector3), blockVector3.getClass());
if (!blocksPlaced.get(playerAndSessionEntry).getValue().contains(vectorClone))
{
blocksPlaced.get(playerAndSessionEntry).getValue().add(vectorClone);
}
}
}
public void logBlockEdits(String playerName, EditSession editSession, Region region, Pattern pattern)
{
// Add the broken blocks to CoreProtect.
if (world == null || !world.getName().equals(editSession.getWorld().getName()))
{
world = server.getWorld(editSession.getWorld().getName());
}
List<BlockState> blocks = new ArrayList<>();
for (BlockVector3 blockVector3 : region)
{
blocks.add(world.getBlockAt(blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ()).getState());
}
logBlockEdit(playerName, editSession, pattern, blocks);
}
public void logBlockEdit(String playerName, EditSession editSession, Pattern pattern, List<BlockState> blocks)
{
Map.Entry<String, EditSession> playerAndSessionEntry = new AbstractMap.SimpleEntry(playerName, editSession);
server.getScheduler().scheduleAsyncDelayedTask(plugin, () ->
{
for (BlockState block : blocks)
{
BlockVector3 blockVector3 = BlockVector3.at(block.getX(), block.getY(), block.getZ());
// Add the broken block to CoreProtect if it's not air.
if (!block.getType().isAir())
{
api.logRemoval(playerAndSessionEntry.getKey(), block.getLocation(), block.getType(), block.getBlockData());
}
// Add the placed block to CoreProtect if it's not air.
BaseBlock baseBlock = pattern.apply(blockVector3);
if (!baseBlock.getBlockType().getMaterial().isAir())
{
Material material = Material.getMaterial(baseBlock.getBlockType().getId().replaceFirst("minecraft:", "").toUpperCase());
api.logPlacement(playerAndSessionEntry.getKey(), block.getLocation(), material, material.createBlockData());
}
}
}, 0L);
}
}

View File

@ -8,7 +8,6 @@ import org.bukkit.plugin.Plugin;
public class TFGuildsBridge extends FreedomService
{
public boolean enabled = false;
@Override