diff --git a/pom.xml b/pom.xml index 7e3cebad..275f24ec 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ me.totalfreedom TotalFreedomMod - 2020.10 + 2020.11 jar diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java index 1665f317..47f1a83c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java @@ -7,6 +7,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Arrays; +import java.util.Collections; import java.util.List; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.config.ConfigEntry; @@ -103,7 +104,7 @@ public class CoreProtectBridge extends FreedomService @Override public void run() { - coreProtect.performRollback(86400, Arrays.asList(name), null, null, null, null, 0, null); + coreProtect.performRollback(86400, Collections.singletonList(name), null, null, null, null, 0, null); } }.runTaskAsynchronously(plugin); } @@ -123,7 +124,7 @@ public class CoreProtectBridge extends FreedomService @Override public void run() { - coreProtect.performRestore(86400, Arrays.asList(name), null, null, null, null, 0, null); + coreProtect.performRestore(86400, Collections.singletonList(name), null, null, null, null, 0, null); } }.runTaskAsynchronously(plugin); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/FAWEBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/FAWEBridge.java index 4f6adbb3..789f7f28 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/FAWEBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/FAWEBridge.java @@ -12,6 +12,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.util.FLog; import net.coreprotect.CoreProtect; import net.coreprotect.CoreProtectAPI; import org.bukkit.Bukkit; @@ -24,7 +25,7 @@ import org.bukkit.block.data.BlockData; public class FAWEBridge extends FreedomService { - private CoreProtectAPI api; + private final CoreProtectAPI api = plugin.cpb.getCoreProtectAPI();; private World world = null; private final Map, Map> blocksBroken = new HashMap<>(); private final Map, Map.Entry>> blocksPlaced = new HashMap<>(); @@ -32,68 +33,62 @@ public class FAWEBridge extends FreedomService @Override public void onStart() { - api = ((CoreProtect)Bukkit.getPluginManager().getPlugin("CoreProtect")).getAPI(); - /* * Iterates over blocks placed by GenerationCommands (in the EditSession) and adds them to the CoreProtect logs. */ - server.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() + server.getScheduler().scheduleSyncRepeatingTask(plugin, () -> { - @Override - public void run() + if (!(blocksBroken.isEmpty() && blocksPlaced.isEmpty())) { - if (!(blocksBroken.isEmpty() && blocksPlaced.isEmpty())) + // Send all broken blocks from the last ticks to the CoreProtect API. + Map.Entry playerAndSessionEntry = null; + for (Map.Entry, Map> entry : blocksBroken.entrySet()) { - // Send all broken blocks from the last ticks to the CoreProtect API. - Map.Entry playerAndSessionEntry = null; - for (Map.Entry, Map> entry : blocksBroken.entrySet()) - { - playerAndSessionEntry = entry.getKey(); - Map dataAndVectorEntry = entry.getValue(); - List blockVector3List = new ArrayList<>(); - blockVector3List.addAll(dataAndVectorEntry.keySet()); // Deep clone the block vector to avoid a change later in the code. + playerAndSessionEntry = entry.getKey(); + Map dataAndVectorEntry = entry.getValue(); + List blockVector3List = new ArrayList<>(); + blockVector3List.addAll(dataAndVectorEntry.keySet()); // Deep clone the block vector to avoid a change later in the code. - for (BlockVector3 blockVector3 : blockVector3List) + for (BlockVector3 blockVector3 : blockVector3List) + { + if (blockVector3 != null) { - 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); - } + 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>> entry : blocksPlaced.entrySet()) - { - playerAndSessionEntry = entry.getKey(); - Map.Entry> patternAndListEntry = entry.getValue(); - Pattern pattern = patternAndListEntry.getKey(); - List 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()); } + + // 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>> entry : blocksPlaced.entrySet()) + { + playerAndSessionEntry = entry.getKey(); + Map.Entry> patternAndListEntry = entry.getValue(); + Pattern pattern = patternAndListEntry.getKey(); + List 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); } @@ -101,10 +96,8 @@ public class FAWEBridge extends FreedomService @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. diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java index b254c1b4..90e02e66 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java @@ -60,7 +60,7 @@ public class WorldEditBridge extends FreedomService { for (int i = 0; i < count; i++) { - com.sk89q.worldedit.entity.Player fuckyou = (com.sk89q.worldedit.entity.Player)bukkitPlayer; + com.sk89q.worldedit.entity.Player fuckyou = bukkitPlayer; session.undo(session.getBlockBag(fuckyou), fuckyou); } }