[Maven] FAWE

This commit is contained in:
Telesphoreo 2020-10-16 22:33:33 -05:00
parent d4d1000c16
commit bb33778fc9
4 changed files with 52 additions and 58 deletions

View file

@ -5,7 +5,7 @@
<groupId>me.totalfreedom</groupId>
<artifactId>TotalFreedomMod</artifactId>
<version>2020.10</version>
<version>2020.11</version>
<packaging>jar</packaging>
<properties>

View file

@ -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);
}

View file

@ -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.Entry<String, EditSession>, Map<BlockVector3, String>> blocksBroken = new HashMap<>();
private final Map<Map.Entry<String, EditSession>, Map.Entry<Pattern, List<BlockVector3>>> 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<String, EditSession> playerAndSessionEntry = null;
for (Map.Entry<Map.Entry<String, EditSession>, Map<BlockVector3, String>> entry : blocksBroken.entrySet())
{
// 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.
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)
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<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());
}
// 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);
}
@ -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.

View file

@ -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);
}
}