mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Added /rollback
This commit is contained in:
parent
3b7a8d4d88
commit
4853cc439b
@ -1,5 +1,5 @@
|
||||
#Wed, 15 May 2013 15:22:48 +0200
|
||||
#Fri, 17 May 2013 22:55:47 +0200
|
||||
|
||||
program.VERSION=2.16
|
||||
program.BUILDNUM=190
|
||||
program.BUILDDATE=05/15/2013 03\:22 PM
|
||||
program.BUILDNUM=210
|
||||
program.BUILDDATE=05/17/2013 10\:55 PM
|
||||
|
@ -1,3 +1,3 @@
|
||||
#Build Number for ANT. Do not edit!
|
||||
#Wed May 15 15:22:48 CEST 2013
|
||||
build.number=191
|
||||
#Fri May 17 22:55:47 CEST 2013
|
||||
build.number=211
|
||||
|
@ -0,0 +1,88 @@
|
||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH, block_host_console = true)
|
||||
@CommandParameters(description = "Issues a rollback on a player", usage = "/<command> <[partialname] | purge [partialname] | purgeall>")
|
||||
public class Command_rollback extends TFM_Command {
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length > 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("purgeall"))
|
||||
{
|
||||
TFM_Util.adminAction(sender.getName(), "Puring all rollback data", false);
|
||||
playerMsg("Purged entries for " + TFM_RollbackManager.purgeEntries() + " players.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 2 && args[0].equalsIgnoreCase("purge"))
|
||||
{
|
||||
OfflinePlayer p;
|
||||
try
|
||||
{
|
||||
p = getPlayer(args[1]);
|
||||
}
|
||||
catch (CantFindPlayerException ex)
|
||||
{
|
||||
p = server.getOfflinePlayer(args[1]);
|
||||
if (!p.hasPlayedBefore())
|
||||
{
|
||||
playerMsg("Player is not online, or never joined the server.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!TFM_RollbackManager.canRollback(p.getName()))
|
||||
{
|
||||
playerMsg("No rollback data found for that player", ChatColor.RED);
|
||||
} else {
|
||||
playerMsg("Purged " + TFM_RollbackManager.purgeEntries(p.getName()) + " entries.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
OfflinePlayer p;
|
||||
try
|
||||
{
|
||||
p = getPlayer(args[0]);
|
||||
}
|
||||
catch (CantFindPlayerException ex)
|
||||
{
|
||||
p = server.getOfflinePlayer(args[0]);
|
||||
if (!p.hasPlayedBefore())
|
||||
{
|
||||
playerMsg("Player is not online, or never joined the server.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!TFM_RollbackManager.canRollback(p.getName()))
|
||||
{
|
||||
playerMsg("Player has no rollback data set.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
TFM_Util.adminAction(sender.getName(), "Rolling back player: " + p.getName(), false);
|
||||
playerMsg("Rolled back " + TFM_RollbackManager.rollback(p) + " blocks");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -3,12 +3,15 @@ package me.StevenLawson.TotalFreedomMod.Listener;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_RollbackEntry;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -24,7 +27,6 @@ public class TFM_BlockListener implements Listener
|
||||
if (!TotalFreedomMod.allowFireSpread)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,7 +36,6 @@ public class TFM_BlockListener implements Listener
|
||||
if (!TotalFreedomMod.allowFirePlace)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,7 +96,6 @@ public class TFM_BlockListener implements Listener
|
||||
if (TFM_ProtectedArea.isInProtectedArea(block_pos))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -180,7 +180,6 @@ public class TFM_BlockListener implements Listener
|
||||
p.sendMessage(ChatColor.GRAY + "Lava placement is currently disabled.");
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -199,7 +198,6 @@ public class TFM_BlockListener implements Listener
|
||||
p.sendMessage(ChatColor.GRAY + "Water placement is currently disabled.");
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -217,7 +215,6 @@ public class TFM_BlockListener implements Listener
|
||||
p.sendMessage(ChatColor.GRAY + "Fire placement is currently disabled.");
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -235,7 +232,6 @@ public class TFM_BlockListener implements Listener
|
||||
|
||||
p.sendMessage(ChatColor.GRAY + "TNT is currently disabled.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -250,6 +246,22 @@ public class TFM_BlockListener implements Listener
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockPlaceRollback(BlockPlaceEvent event)
|
||||
{
|
||||
TFM_RollbackEntry entry = new TFM_RollbackEntry();
|
||||
entry.setLocation(event.getBlock().getLocation());
|
||||
entry.setMaterial(Material.AIR);
|
||||
TFM_RollbackManager.blockUpdate(event.getPlayer(), entry);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockBreakRollback(BlockBreakEvent event)
|
||||
{
|
||||
TFM_RollbackManager.blockUpdate(event.getPlayer(), event.getBlock());
|
||||
}
|
||||
|
||||
// @EventHandler(priority = EventPriority.NORMAL)
|
||||
// public void onCommandBlockChangeEvent(CommandBlockChangeEvent event)
|
||||
// {
|
||||
|
@ -55,7 +55,6 @@ public class TFM_PlayerListener implements Listener
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
|
||||
player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
case POTION:
|
||||
{
|
||||
@ -81,7 +80,6 @@ public class TFM_PlayerListener implements Listener
|
||||
playerdata.enqueueMob(rezzed_mob);
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
54
src/me/StevenLawson/TotalFreedomMod/TFM_RollbackEntry.java
Normal file
54
src/me/StevenLawson/TotalFreedomMod/TFM_RollbackEntry.java
Normal file
@ -0,0 +1,54 @@
|
||||
package me.StevenLawson.TotalFreedomMod;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
|
||||
public class TFM_RollbackEntry
|
||||
{
|
||||
|
||||
private Location location;
|
||||
private Material material;
|
||||
private byte data;
|
||||
|
||||
public TFM_RollbackEntry()
|
||||
{
|
||||
}
|
||||
|
||||
public TFM_RollbackEntry(Block block)
|
||||
{
|
||||
location = block.getLocation();
|
||||
material = block.getType();
|
||||
data = block.getData();
|
||||
}
|
||||
|
||||
public void setBlock(Block block)
|
||||
{
|
||||
location = block.getLocation();
|
||||
material = block.getType();
|
||||
data = block.getData();
|
||||
}
|
||||
|
||||
public void setLocation(Location location)
|
||||
{
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public void setMaterial(Material material)
|
||||
{
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public void setData(byte data)
|
||||
{
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void restore()
|
||||
{
|
||||
Block b = location.getWorld().getBlockAt(location);
|
||||
b.setType(material);
|
||||
b.setData(data);
|
||||
}
|
||||
}
|
86
src/me/StevenLawson/TotalFreedomMod/TFM_RollbackManager.java
Normal file
86
src/me/StevenLawson/TotalFreedomMod/TFM_RollbackManager.java
Normal file
@ -0,0 +1,86 @@
|
||||
package me.StevenLawson.TotalFreedomMod;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
public class TFM_RollbackManager
|
||||
{
|
||||
public static Map<String, List<TFM_RollbackEntry>> entries = new HashMap<String, List<TFM_RollbackEntry>>();
|
||||
|
||||
public static void blockUpdate(OfflinePlayer player, Block block)
|
||||
{
|
||||
List <TFM_RollbackEntry> e;
|
||||
if (entries.containsKey(player.getName()))
|
||||
{
|
||||
e = entries.get(player.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
e = new ArrayList<TFM_RollbackEntry>();
|
||||
}
|
||||
e.add(new TFM_RollbackEntry(block));
|
||||
entries.put(player.getName(), e);
|
||||
}
|
||||
|
||||
public static void blockUpdate(OfflinePlayer player, TFM_RollbackEntry entry)
|
||||
{
|
||||
List <TFM_RollbackEntry> e;
|
||||
if (entries.containsKey(player.getName()))
|
||||
{
|
||||
e = entries.get(player.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
e = new ArrayList<TFM_RollbackEntry>();
|
||||
}
|
||||
e.add(entry);
|
||||
entries.put(player.getName(), e);
|
||||
}
|
||||
|
||||
public static int rollback(OfflinePlayer player)
|
||||
{
|
||||
if (!canRollback(player.getName()))
|
||||
{
|
||||
TFM_Log.severe("Could not rollback player: " + player.getName() + "! No entries are set");
|
||||
return 0;
|
||||
}
|
||||
|
||||
List<TFM_RollbackEntry> e = entries.get(player.getName());
|
||||
int counter = 0;
|
||||
for (TFM_RollbackEntry entry : e)
|
||||
{
|
||||
entry.restore();
|
||||
counter++;
|
||||
}
|
||||
entries.remove(player.getName());
|
||||
return counter;
|
||||
}
|
||||
|
||||
public static boolean canRollback(String player)
|
||||
{
|
||||
return entries.containsKey(player);
|
||||
}
|
||||
|
||||
public static int purgeEntries()
|
||||
{
|
||||
int counter = entries.size();
|
||||
entries.clear();
|
||||
return counter;
|
||||
}
|
||||
|
||||
public static int purgeEntries(String player)
|
||||
{
|
||||
if (!canRollback(player))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int counter = entries.get(player).size();
|
||||
entries.remove(player);
|
||||
return counter;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user