mirror of
https://github.com/TheDeus-Group/TFM-4.3-Reloaded.git
synced 2024-12-22 22:14:57 +00:00
Merge vanish and coreprotect-switch into main
This commit is contained in:
parent
b1882a2a10
commit
522915a76a
7 changed files with 979 additions and 1409 deletions
|
@ -5,7 +5,6 @@ import me.StevenLawson.TotalFreedomMod.ban.BanManager;
|
|||
import me.StevenLawson.TotalFreedomMod.bridge.WorldEditBridge;
|
||||
import me.StevenLawson.TotalFreedomMod.manager.UUIDManager;
|
||||
import me.StevenLawson.TotalFreedomMod.util.Utilities;
|
||||
import me.StevenLawson.TotalFreedomMod.world.RollbackManager;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -48,7 +47,8 @@ public class Command_gtfo extends FreedomCommand {
|
|||
}
|
||||
|
||||
// rollback
|
||||
RollbackManager.rollback(player.getName());
|
||||
// RollbackManager.rollback(player.getName());
|
||||
// TODO: Use coreprotect API calls
|
||||
|
||||
// deop
|
||||
player.setOp(false);
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
package me.StevenLawson.TotalFreedomMod.commands;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.util.Utilities;
|
||||
import me.StevenLawson.TotalFreedomMod.world.RollbackManager;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, blockHostConsole = true)
|
||||
public class Command_rollback extends FreedomCommand {
|
||||
@Override
|
||||
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
|
||||
if (args.length == 0 || args.length > 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
if ("purgeall".equals(args[0])) {
|
||||
Utilities.adminAction(sender.getName(), "Purging all rollback history", false);
|
||||
playerMsg(sender, "Purged all rollback history for " + RollbackManager.purgeEntries() + " players.");
|
||||
}
|
||||
else
|
||||
{
|
||||
final String playerName = RollbackManager.findPlayer(args[0]);
|
||||
|
||||
if (playerName == null)
|
||||
{
|
||||
playerMsg(sender, "That player has no entries stored.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (RollbackManager.canUndoRollback(playerName))
|
||||
{
|
||||
playerMsg(sender, "That player has just been rolled back.");
|
||||
}
|
||||
|
||||
Utilities.adminAction(sender.getName(), "Rolling back player: " + playerName, false);
|
||||
playerMsg(sender, "Rolled back " + RollbackManager.rollback(playerName) + " edits for " + playerName + ".");
|
||||
playerMsg(sender, "If this rollback was a mistake, use /rollback undo " + playerName + " within 40 seconds to reverse the rollback.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 2)
|
||||
{
|
||||
if ("purge".equalsIgnoreCase(args[0]))
|
||||
{
|
||||
final String playerName = RollbackManager.findPlayer(args[1]);
|
||||
|
||||
if (playerName == null)
|
||||
{
|
||||
playerMsg(sender, "That player has no entries stored.");
|
||||
return true;
|
||||
}
|
||||
|
||||
playerMsg(sender, "Purged " + RollbackManager.purgeEntries(playerName) + " rollback history entries for " + playerName + ".");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ("undo".equalsIgnoreCase(args[0]))
|
||||
{
|
||||
final String playerName = RollbackManager.findPlayer(args[1]);
|
||||
|
||||
if (playerName == null)
|
||||
{
|
||||
playerMsg(sender, "That player hasn't been rolled back recently.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Utilities.adminAction(sender.getName(), "Reverting rollback for player: " + playerName, false);
|
||||
playerMsg(sender, "Reverted " + RollbackManager.undoRollback(playerName) + " edits for " + playerName + ".");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ package me.StevenLawson.TotalFreedomMod.commands;
|
|||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Commands {
|
||||
|
||||
public static void registerCommands(JavaPlugin plugin) {
|
||||
plugin.getCommand("adminmode").setExecutor(new Command_adminmode());
|
||||
plugin.getCommand("adminworld").setExecutor(new Command_adminworld());
|
||||
|
@ -76,7 +75,6 @@ public class Commands {
|
|||
plugin.getCommand("rd").setExecutor(new Command_rd());
|
||||
plugin.getCommand("report").setExecutor(new Command_report());
|
||||
plugin.getCommand("ro").setExecutor(new Command_ro());
|
||||
plugin.getCommand("rollback").setExecutor(new Command_rollback());
|
||||
plugin.getCommand("saconfig").setExecutor(new Command_saconfig());
|
||||
plugin.getCommand("say").setExecutor(new Command_say());
|
||||
plugin.getCommand("setl").setExecutor(new Command_setl());
|
||||
|
@ -109,6 +107,5 @@ public class Commands {
|
|||
plugin.getCommand("wipeuserdata").setExecutor(new Command_wipeuserdata());
|
||||
plugin.getCommand("whoami").setExecutor(new Command_whoami());
|
||||
plugin.getCommand("resetplayer").setExecutor(new Command_resetplayer());
|
||||
plugin.getCommand("vanish").setExecutor(new Command_vanish());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import me.StevenLawson.TotalFreedomMod.player.HeartBeat;
|
|||
import me.StevenLawson.TotalFreedomMod.player.PlayerData;
|
||||
import me.StevenLawson.TotalFreedomMod.util.Utilities;
|
||||
import me.StevenLawson.TotalFreedomMod.world.ProtectedArea;
|
||||
import me.StevenLawson.TotalFreedomMod.world.RollbackManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
@ -251,24 +250,6 @@ public class BlockListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onRollbackBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
if (!AdminList.isSuperAdmin(event.getPlayer()))
|
||||
{
|
||||
RollbackManager.blockBreak(event);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onRollbackBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
if (!AdminList.isSuperAdmin(event.getPlayer()))
|
||||
{
|
||||
RollbackManager.blockPlace(event);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockFromTo(BlockFromToEvent event)
|
||||
{
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,316 +0,0 @@
|
|||
package me.StevenLawson.TotalFreedomMod.world;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.Log;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
import me.StevenLawson.TotalFreedomMod.util.DeprecationUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class RollbackManager
|
||||
{
|
||||
private static final Map<String, List<RollbackEntry>> PLAYER_HISTORY = new HashMap<String, List<RollbackEntry>>();
|
||||
private static final List<String> REMOVE_ROLLBACK_HISTORY = new ArrayList<String>();
|
||||
|
||||
private RollbackManager()
|
||||
{
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static void blockPlace(org.bukkit.event.block.BlockPlaceEvent event)
|
||||
{
|
||||
storeEntry(event.getPlayer(), new RollbackEntry(event.getPlayer().getName(), event.getBlock(), EntryType.BLOCK_PLACE));
|
||||
}
|
||||
|
||||
public static void blockBreak(org.bukkit.event.block.BlockBreakEvent event)
|
||||
{
|
||||
storeEntry(event.getPlayer(), new RollbackEntry(event.getPlayer().getName(), event.getBlock(), EntryType.BLOCK_BREAK));
|
||||
}
|
||||
|
||||
private static void storeEntry(Player player, RollbackEntry entry)
|
||||
{
|
||||
List<RollbackEntry> playerEntryList = getEntriesByPlayer(player.getName());
|
||||
|
||||
if (playerEntryList != null)
|
||||
{
|
||||
playerEntryList.add(0, entry);
|
||||
}
|
||||
}
|
||||
|
||||
// May return null
|
||||
public static String findPlayer(String partial)
|
||||
{
|
||||
partial = partial.toLowerCase();
|
||||
|
||||
for (String player : PLAYER_HISTORY.keySet())
|
||||
{
|
||||
if (player.toLowerCase().equals(partial))
|
||||
{
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
for (String player : PLAYER_HISTORY.keySet())
|
||||
{
|
||||
if (player.toLowerCase().contains(partial))
|
||||
{
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int purgeEntries()
|
||||
{
|
||||
Iterator<List<RollbackEntry>> it = PLAYER_HISTORY.values().iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
List<RollbackEntry> playerEntryList = it.next();
|
||||
if (playerEntryList != null)
|
||||
{
|
||||
playerEntryList.clear();
|
||||
}
|
||||
}
|
||||
return PLAYER_HISTORY.size();
|
||||
}
|
||||
|
||||
public static int purgeEntries(String playerName)
|
||||
{
|
||||
List<RollbackEntry> playerEntryList = getEntriesByPlayer(playerName);
|
||||
|
||||
if (playerEntryList == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count = playerEntryList.size();
|
||||
playerEntryList.clear();
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
public static boolean canRollback(String playerName)
|
||||
{
|
||||
return PLAYER_HISTORY.containsKey(playerName.toLowerCase()) && !PLAYER_HISTORY.get(playerName.toLowerCase()).isEmpty();
|
||||
}
|
||||
|
||||
public static boolean canUndoRollback(String playerName)
|
||||
{
|
||||
return REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase());
|
||||
}
|
||||
|
||||
public static int rollback(final String playerName)
|
||||
{
|
||||
final List<RollbackEntry> entries = getEntriesByPlayer(playerName);
|
||||
if (entries == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count = entries.size();
|
||||
for (RollbackEntry entry : entries)
|
||||
{
|
||||
if (entry != null)
|
||||
{
|
||||
entry.restore();
|
||||
}
|
||||
}
|
||||
|
||||
if (!REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase()))
|
||||
{
|
||||
REMOVE_ROLLBACK_HISTORY.add(playerName.toLowerCase());
|
||||
}
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (REMOVE_ROLLBACK_HISTORY.contains(playerName.toLowerCase()))
|
||||
{
|
||||
REMOVE_ROLLBACK_HISTORY.remove(playerName.toLowerCase());
|
||||
purgeEntries(playerName);
|
||||
}
|
||||
}
|
||||
}.runTaskLater(TotalFreedomMod.plugin, 40L * 20L);
|
||||
return count;
|
||||
}
|
||||
|
||||
public static int undoRollback(String playerName)
|
||||
{
|
||||
final List<RollbackEntry> entries = getEntriesByPlayer(playerName);
|
||||
|
||||
if (entries == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
final int count = entries.size();
|
||||
|
||||
final ListIterator<RollbackEntry> it = entries.listIterator(count);
|
||||
while (it.hasPrevious())
|
||||
{
|
||||
RollbackEntry entry = it.previous();
|
||||
if (entry != null)
|
||||
{
|
||||
entry.redo();
|
||||
}
|
||||
}
|
||||
|
||||
REMOVE_ROLLBACK_HISTORY.remove(playerName.toLowerCase());
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public static List<RollbackEntry> getEntriesAtLocation(final Location location)
|
||||
{
|
||||
final int testX = location.getBlockX();
|
||||
final short testY = (short) location.getBlockY();
|
||||
final int testZ = location.getBlockZ();
|
||||
final String testWorldName = location.getWorld().getName();
|
||||
|
||||
List<RollbackEntry> entries = new ArrayList<RollbackEntry>();
|
||||
for (String playername : PLAYER_HISTORY.keySet())
|
||||
{
|
||||
for (RollbackEntry entry : PLAYER_HISTORY.get(playername.toLowerCase()))
|
||||
{
|
||||
if (testX == entry.x && testY == entry.y && testZ == entry.z && testWorldName.equals(entry.worldName))
|
||||
{
|
||||
entries.add(0, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
private static List<RollbackEntry> getEntriesByPlayer(String playerName)
|
||||
{
|
||||
playerName = playerName.toLowerCase();
|
||||
List<RollbackEntry> playerEntryList = PLAYER_HISTORY.get(playerName.toLowerCase());
|
||||
if (playerEntryList == null)
|
||||
{
|
||||
playerEntryList = new ArrayList<RollbackEntry>();
|
||||
PLAYER_HISTORY.put(playerName.toLowerCase(), playerEntryList);
|
||||
}
|
||||
return playerEntryList;
|
||||
}
|
||||
|
||||
public enum EntryType
|
||||
{
|
||||
BLOCK_PLACE("placed"),
|
||||
BLOCK_BREAK("broke");
|
||||
private final String action;
|
||||
|
||||
EntryType(String action)
|
||||
{
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.action;
|
||||
}
|
||||
}
|
||||
|
||||
public static class RollbackEntry
|
||||
{
|
||||
// Use of primitives to decrease overhead
|
||||
public final String author;
|
||||
public final String worldName;
|
||||
public final int x;
|
||||
public final short y;
|
||||
public final int z;
|
||||
public final byte data;
|
||||
public final Material blockMaterial;
|
||||
private final boolean isBreak;
|
||||
|
||||
private RollbackEntry(String author, Block block, EntryType entryType)
|
||||
{
|
||||
final Location location = block.getLocation();
|
||||
|
||||
this.x = location.getBlockX();
|
||||
this.y = (short) location.getBlockY();
|
||||
this.z = location.getBlockZ();
|
||||
this.worldName = location.getWorld().getName();
|
||||
this.author = author;
|
||||
|
||||
if (entryType == EntryType.BLOCK_BREAK)
|
||||
{
|
||||
this.blockMaterial = block.getType();
|
||||
this.data = DeprecationUtil.getData_Block(block);
|
||||
this.isBreak = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.blockMaterial = block.getType();
|
||||
this.data = DeprecationUtil.getData_Block(block);
|
||||
this.isBreak = false;
|
||||
}
|
||||
}
|
||||
|
||||
public Location getLocation()
|
||||
{
|
||||
try
|
||||
{
|
||||
return new Location(Bukkit.getWorld(worldName), x, (int) y, z);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.warning("Could not get location of rollback entry at (" + worldName + ":" + x + "," + y + "," + x + ")!");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Material getMaterial()
|
||||
{
|
||||
return blockMaterial;
|
||||
}
|
||||
|
||||
public EntryType getType()
|
||||
{
|
||||
return (isBreak ? EntryType.BLOCK_BREAK : EntryType.BLOCK_PLACE);
|
||||
}
|
||||
|
||||
public void restore()
|
||||
{
|
||||
final Block block = Bukkit.getWorld(worldName).getBlockAt(x, y, z);
|
||||
if (isBreak)
|
||||
{
|
||||
block.setType(getMaterial());
|
||||
DeprecationUtil.setData_Block(block, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
public void redo()
|
||||
{
|
||||
final Block block = Bukkit.getWorld(worldName).getBlockAt(x, y, z);
|
||||
|
||||
if (isBreak)
|
||||
{
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
else
|
||||
{
|
||||
block.setType(getMaterial());
|
||||
DeprecationUtil.setData_Block(block, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -287,10 +287,6 @@ commands:
|
|||
description: 'Mutes a player with brute force.'
|
||||
usage: '/<command> [<player> [-s] | list | purge | all]'
|
||||
aliases: 'mute'
|
||||
rollback:
|
||||
description: 'Issues a rollback on a player'
|
||||
usage: '/<command> <[partialname] | undo [partialname] purge [partialname] | purgeall>'
|
||||
aliases: 'rb'
|
||||
nickclean:
|
||||
description: 'Essentials Interface Command - Remove distracting things from nicknames of all players on server.'
|
||||
usage: '/<command>'
|
||||
|
|
Loading…
Reference in a new issue