TotalFreedomMod/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerData.java

525 lines
12 KiB
Java
Raw Normal View History

2011-10-01 17:59:46 +00:00
package me.StevenLawson.TotalFreedomMod;
2011-10-10 12:09:19 +00:00
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
2011-10-10 12:09:19 +00:00
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import me.StevenLawson.TotalFreedomMod.Bridge.TFM_EssentialsBridge;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
2011-10-16 06:00:37 +00:00
import org.bukkit.Bukkit;
2013-07-02 20:31:05 +00:00
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
2011-10-10 12:09:19 +00:00
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
2011-10-10 12:09:19 +00:00
2013-01-21 18:58:42 +00:00
public class TFM_PlayerData
2011-10-01 17:59:46 +00:00
{
2013-01-21 18:58:42 +00:00
public final static Map<Player, TFM_PlayerData> userinfo = new HashMap<Player, TFM_PlayerData>();
private final Player player;
private final String ip;
private final UUID uuid;
private boolean isFrozen = false;
private boolean isMuted = false;
private boolean isHalted = false;
private int messageCount = 0;
private int totalBlockDestroy = 0;
private int totalBlockPlace = 0;
private int freecamDestroyCount = 0;
private int freecamPlaceCount = 0;
private boolean isCaged = false;
private Location cagePosition;
private List<TFM_BlockData> cageHistory = new ArrayList<TFM_BlockData>();
private Material cageOuterMaterial = Material.GLASS;
private Material cageInnerMatterial = Material.AIR;
private boolean isOrbiting = false;
private double orbitStrength = 10.0;
private boolean mobThrowerEnabled = false;
private EntityType mobThrowerEntity = EntityType.PIG;
private double mobThrowerSpeed = 4.0;
private List<LivingEntity> mobThrowerQueue = new ArrayList<LivingEntity>();
private BukkitTask mp44ScheduleId = null;
private boolean mp44Armed = false;
private boolean mp44Firing = false;
private BukkitTask lockupScheduleId = null;
private String lastMessage = "";
private boolean inAdminchat = false;
private boolean allCommandsBlocked = false;
private boolean verifiedSuperadminId = false;
private String lastCommand = "";
private boolean cmdspyEnabled = false;
2013-08-12 10:26:49 +00:00
private String tag = null;
private int warningCount = 0;
2011-10-02 04:18:52 +00:00
2014-04-08 18:31:04 +00:00
private TFM_PlayerData(Player player)
2011-10-01 17:59:46 +00:00
{
2011-10-21 17:02:07 +00:00
this.player = player;
this.uuid = TFM_UuidManager.getUniqueId(player.getName());
this.ip = player.getAddress().getAddress().getHostAddress();
2011-10-01 17:59:46 +00:00
}
2013-08-14 14:01:42 +00:00
public static TFM_PlayerData getPlayerData(Player player)
2011-10-16 06:00:37 +00:00
{
2013-08-14 14:01:42 +00:00
TFM_PlayerData playerdata = TFM_PlayerData.userinfo.get(player);
if (playerdata != null)
{
return playerdata;
}
Iterator<Entry<Player, TFM_PlayerData>> it = userinfo.entrySet().iterator();
while (it.hasNext())
{
Entry<Player, TFM_PlayerData> pair = it.next();
TFM_PlayerData playerdataTest = pair.getValue();
if (playerdataTest.player.getName().equalsIgnoreCase(player.getName()))
{
if (Bukkit.getOnlineMode())
{
playerdata = playerdataTest;
break;
}
else
{
if (playerdataTest.ip.equalsIgnoreCase(player.getAddress().getAddress().getHostAddress()))
{
playerdata = playerdataTest;
break;
}
}
}
}
if (playerdata != null)
2011-10-16 06:00:37 +00:00
{
return playerdata;
2011-10-16 06:00:37 +00:00
}
playerdata = new TFM_PlayerData(player);
TFM_PlayerData.userinfo.put(player, playerdata);
2011-10-16 06:00:37 +00:00
return playerdata;
}
public String getIpAddress()
{
return this.ip;
}
public UUID getUniqueId()
{
return uuid;
}
2011-10-16 06:00:37 +00:00
public boolean isOrbiting()
{
return this.isOrbiting;
2011-10-16 06:00:37 +00:00
}
public void startOrbiting(double strength)
2011-10-16 06:00:37 +00:00
{
this.isOrbiting = true;
this.orbitStrength = strength;
2011-10-16 06:00:37 +00:00
}
2011-10-16 06:00:37 +00:00
public void stopOrbiting()
{
this.isOrbiting = false;
2011-10-16 06:00:37 +00:00
}
public double orbitStrength()
{
return this.orbitStrength;
2011-10-16 06:00:37 +00:00
}
2011-10-14 23:29:09 +00:00
2011-10-10 12:09:19 +00:00
public void setCaged(boolean state)
{
this.isCaged = state;
2011-10-10 12:09:19 +00:00
}
2011-10-14 23:29:09 +00:00
public void setCaged(boolean state, Location location, Material outer, Material inner)
2011-10-10 12:09:19 +00:00
{
this.isCaged = state;
this.cagePosition = location;
this.cageOuterMaterial = outer;
this.cageInnerMatterial = inner;
2011-10-10 12:09:19 +00:00
}
2011-10-14 23:29:09 +00:00
2011-10-10 12:09:19 +00:00
public boolean isCaged()
{
return this.isCaged;
2011-10-10 12:09:19 +00:00
}
2011-10-14 23:29:09 +00:00
public enum CageLayer
2011-10-10 12:09:19 +00:00
{
2011-10-14 23:29:09 +00:00
INNER, OUTER
}
public Material getCageMaterial(CageLayer layer)
{
switch (layer)
2011-10-10 12:09:19 +00:00
{
2011-10-14 23:29:09 +00:00
case OUTER:
return this.cageOuterMaterial;
2011-10-14 23:29:09 +00:00
case INNER:
return this.cageInnerMatterial;
2011-10-14 23:29:09 +00:00
default:
return this.cageOuterMaterial;
2011-10-10 12:09:19 +00:00
}
}
2011-10-14 23:29:09 +00:00
2011-10-10 12:09:19 +00:00
public Location getCagePos()
{
return this.cagePosition;
2011-10-10 12:09:19 +00:00
}
2011-10-14 23:29:09 +00:00
2011-10-10 12:09:19 +00:00
public void clearHistory()
{
this.cageHistory.clear();
2011-10-10 12:09:19 +00:00
}
2011-10-14 23:29:09 +00:00
2011-10-10 12:09:19 +00:00
public void insertHistoryBlock(Location location, Material material)
{
this.cageHistory.add(new TFM_BlockData(location, material));
2011-10-10 12:09:19 +00:00
}
2011-10-14 23:29:09 +00:00
2011-10-10 12:09:19 +00:00
public void regenerateHistory()
{
for (TFM_BlockData blockdata : this.cageHistory)
2011-10-10 12:09:19 +00:00
{
blockdata.location.getBlock().setType(blockdata.material);
}
}
2011-10-14 23:29:09 +00:00
private class TFM_BlockData
2011-10-10 12:09:19 +00:00
{
public Material material;
public Location location;
private TFM_BlockData(Location location, Material material)
2011-10-10 12:09:19 +00:00
{
this.location = location;
this.material = material;
}
}
2011-10-14 23:29:09 +00:00
2011-10-01 17:59:46 +00:00
public boolean isFrozen()
{
return this.isFrozen;
2011-10-01 17:59:46 +00:00
}
2011-10-02 04:18:52 +00:00
2011-10-01 17:59:46 +00:00
public void setFrozen(boolean fr)
{
this.isFrozen = fr;
2011-10-01 17:59:46 +00:00
}
public void resetMsgCount()
{
this.messageCount = 0;
2011-10-01 17:59:46 +00:00
}
2011-10-02 04:18:52 +00:00
public int incrementAndGetMsgCount()
2011-10-01 17:59:46 +00:00
{
return this.messageCount++;
2011-10-01 17:59:46 +00:00
}
2011-10-02 04:18:52 +00:00
public int incrementAndGetBlockDestroyCount()
2011-10-01 17:59:46 +00:00
{
return this.totalBlockDestroy++;
2011-10-01 17:59:46 +00:00
}
2011-10-02 04:18:52 +00:00
2011-10-01 17:59:46 +00:00
public void resetBlockDestroyCount()
{
this.totalBlockDestroy = 0;
2011-10-05 19:07:45 +00:00
}
public int incrementAndGetBlockPlaceCount()
2011-10-18 04:08:40 +00:00
{
return this.totalBlockPlace++;
2011-10-18 04:08:40 +00:00
}
public void resetBlockPlaceCount()
{
this.totalBlockPlace = 0;
2011-10-18 04:08:40 +00:00
}
2011-10-14 23:29:09 +00:00
public int incrementAndGetFreecamDestroyCount()
2011-10-05 19:07:45 +00:00
{
return this.freecamDestroyCount++;
2011-10-05 19:07:45 +00:00
}
public void resetFreecamDestroyCount()
{
this.freecamDestroyCount = 0;
2011-10-05 19:07:45 +00:00
}
2011-10-14 23:29:09 +00:00
public int incrementAndGetFreecamPlaceCount()
2011-10-05 19:07:45 +00:00
{
return this.freecamPlaceCount++;
2011-10-05 19:07:45 +00:00
}
public void resetFreecamPlaceCount()
{
this.freecamPlaceCount = 0;
2011-10-01 17:59:46 +00:00
}
2011-10-16 06:00:37 +00:00
public void enableMobThrower(EntityType mobThrowerCreature, double mobThrowerSpeed)
2011-10-16 06:00:37 +00:00
{
this.mobThrowerEnabled = true;
this.mobThrowerEntity = mobThrowerCreature;
this.mobThrowerSpeed = mobThrowerSpeed;
2011-10-16 06:00:37 +00:00
}
2011-10-16 06:00:37 +00:00
public void disableMobThrower()
{
this.mobThrowerEnabled = false;
2011-10-16 06:00:37 +00:00
}
2012-03-03 04:29:54 +00:00
public EntityType mobThrowerCreature()
2011-10-16 06:00:37 +00:00
{
return this.mobThrowerEntity;
2011-10-16 06:00:37 +00:00
}
public double mobThrowerSpeed()
{
return this.mobThrowerSpeed;
2011-10-16 06:00:37 +00:00
}
2011-10-16 06:00:37 +00:00
public boolean mobThrowerEnabled()
{
return this.mobThrowerEnabled;
2011-10-16 06:00:37 +00:00
}
2011-10-16 06:00:37 +00:00
public void enqueueMob(LivingEntity mob)
{
mobThrowerQueue.add(mob);
if (mobThrowerQueue.size() > 4)
2011-10-16 06:00:37 +00:00
{
LivingEntity oldmob = mobThrowerQueue.remove(0);
2011-10-16 06:00:37 +00:00
if (oldmob != null)
{
oldmob.damage(500.0);
2011-10-16 06:00:37 +00:00
}
}
}
2011-10-21 17:02:07 +00:00
public void startArrowShooter(TotalFreedomMod plugin)
2011-10-16 06:00:37 +00:00
{
2011-10-21 17:02:07 +00:00
this.stopArrowShooter();
this.mp44ScheduleId = new ArrowShooter(this.player).runTaskTimer(plugin, 1L, 1L);
this.mp44Firing = true;
2011-10-16 06:00:37 +00:00
}
2011-10-19 00:37:00 +00:00
public void stopArrowShooter()
2011-10-16 06:00:37 +00:00
{
if (this.mp44ScheduleId != null)
2011-10-16 06:00:37 +00:00
{
this.mp44ScheduleId.cancel();
this.mp44ScheduleId = null;
2011-10-16 06:00:37 +00:00
}
this.mp44Firing = false;
2011-10-21 17:02:07 +00:00
}
private class ArrowShooter extends BukkitRunnable
2011-10-21 17:02:07 +00:00
{
private Player player;
2014-04-08 18:31:04 +00:00
private ArrowShooter(Player player)
2011-10-21 17:02:07 +00:00
{
this.player = player;
2011-10-21 17:02:07 +00:00
}
@Override
public void run()
{
Arrow shot = player.launchProjectile(Arrow.class);
shot.setVelocity(shot.getVelocity().multiply(2.0));
2011-10-21 17:02:07 +00:00
}
}
2011-10-21 17:02:07 +00:00
public void armMP44()
{
this.mp44Armed = true;
2011-10-21 17:02:07 +00:00
this.stopArrowShooter();
}
2011-10-21 17:02:07 +00:00
public void disarmMP44()
{
this.mp44Armed = false;
2011-10-21 17:02:07 +00:00
this.stopArrowShooter();
}
2011-10-21 17:02:07 +00:00
public boolean isMP44Armed()
{
return this.mp44Armed;
2011-10-21 17:02:07 +00:00
}
2011-10-21 17:02:07 +00:00
public boolean toggleMP44Firing()
{
this.mp44Firing = !this.mp44Firing;
return mp44Firing;
2011-10-16 06:00:37 +00:00
}
public boolean isMuted()
{
return isMuted;
}
public void setMuted(boolean muted)
{
this.isMuted = muted;
}
2012-09-18 10:13:06 +00:00
public boolean isHalted()
{
return this.isHalted;
2012-09-18 10:13:06 +00:00
}
public void setHalted(boolean halted)
2012-09-18 10:13:06 +00:00
{
this.isHalted = halted;
2013-07-02 20:31:05 +00:00
if (halted)
2013-07-02 20:31:05 +00:00
{
player.setOp(false);
player.setGameMode(GameMode.SURVIVAL);
player.setFlying(false);
TFM_EssentialsBridge.setNickname(player.getName(), player.getName());
2013-07-02 20:31:05 +00:00
player.closeInventory();
player.setTotalExperience(0);
stopOrbiting();
setFrozen(true);
setMuted(true);
player.sendMessage(ChatColor.GRAY + "You have been halted, don't move!");
}
else
{
player.setOp(true);
player.setGameMode(GameMode.CREATIVE);
setFrozen(false);
setMuted(false);
player.sendMessage(ChatColor.GRAY + "You are no longer halted.");
}
2012-09-18 10:13:06 +00:00
}
public BukkitTask getLockupScheduleID()
{
return this.lockupScheduleId;
}
public void setLockupScheduleID(BukkitTask id)
{
this.lockupScheduleId = id;
}
2012-11-27 19:02:39 +00:00
public void setLastMessage(String message)
2012-11-27 19:02:39 +00:00
{
this.lastMessage = message;
2012-11-27 19:02:39 +00:00
}
public String getLastMessage()
{
return lastMessage;
2012-11-27 19:02:39 +00:00
}
public void setAdminChat(boolean inAdminchat)
{
this.inAdminchat = inAdminchat;
}
public boolean inAdminChat()
{
return this.inAdminchat;
}
2012-12-06 09:32:08 +00:00
public boolean allCommandsBlocked()
2012-12-06 09:32:08 +00:00
{
return this.allCommandsBlocked;
2012-12-06 09:32:08 +00:00
}
public void setCommandsBlocked(boolean commandsBlocked)
2012-12-06 09:32:08 +00:00
{
this.allCommandsBlocked = commandsBlocked;
2012-12-06 09:32:08 +00:00
}
// If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP.
// After the check for this is done in TFM_PlayerListener, never change it elsewhere.
public boolean isSuperadminIdVerified()
{
return this.verifiedSuperadminId;
}
// If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP.
// After the check for this is done in TFM_PlayerListener, never change it elsewhere.
public void setSuperadminIdVerified(boolean verifiedSuperadminId)
{
this.verifiedSuperadminId = verifiedSuperadminId;
}
public String getLastCommand()
{
return lastCommand;
}
public void setLastCommand(String lastCommand)
{
this.lastCommand = lastCommand;
}
2013-01-21 18:58:42 +00:00
public void setCommandSpy(boolean enabled)
2013-01-21 18:58:42 +00:00
{
this.cmdspyEnabled = enabled;
2013-01-21 18:58:42 +00:00
}
public boolean cmdspyEnabled()
{
return cmdspyEnabled;
2013-01-21 18:58:42 +00:00
}
2013-08-12 10:26:49 +00:00
public void setTag(String tag)
{
if (tag == null)
{
this.tag = null;
}
else
{
this.tag = TFM_Util.colorize(tag) + ChatColor.WHITE;
2013-08-12 10:26:49 +00:00
}
}
public String getTag()
{
return this.tag;
}
public int getWarningCount()
{
return this.warningCount;
}
public void incrementWarnings()
{
this.warningCount++;
if (this.warningCount % 2 == 0)
{
this.player.getWorld().strikeLightning(this.player.getLocation());
TFM_Util.playerMsg(this.player, ChatColor.RED + "You have been warned at least twice now, make sure to read the rules at " + TFM_ConfigEntry.SERVER_BAN_URL.getString());
}
}
2011-10-01 17:59:46 +00:00
}