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

526 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;
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_address;
private final String player_name;
2011-10-01 17:59:46 +00:00
private boolean user_frozen = false;
private boolean is_muted = false;
2012-09-18 10:13:06 +00:00
private boolean is_halted = false;
2011-10-01 17:59:46 +00:00
private int msg_count = 0;
2011-10-05 19:07:45 +00:00
private int block_destroy_total = 0;
2011-10-18 04:08:40 +00:00
private int block_place_total = 0;
2011-10-05 19:07:45 +00:00
private int freecam_destroy_count = 0;
private int freecam_place_count = 0;
2011-10-10 12:09:19 +00:00
private boolean user_caged = false;
private Location user_cage_pos;
private List<TFM_BlockData> user_cage_history = new ArrayList<TFM_BlockData>();
2011-10-16 06:00:37 +00:00
private Material cage_material_outer = Material.GLASS;
private Material cage_material_inner = Material.AIR;
private boolean is_orbiting = false;
private double orbit_strength = 10.0;
private boolean mob_thrower_enabled = false;
2012-03-03 04:29:54 +00:00
private EntityType mob_thrower_creature = EntityType.PIG;
2011-10-16 06:00:37 +00:00
private double mob_thrower_speed = 4.0;
2011-10-18 04:08:40 +00:00
private List<LivingEntity> mob_thrower_queue = new ArrayList<LivingEntity>();
private BukkitTask mp44_schedule_id = null;
2011-10-21 17:02:07 +00:00
private boolean mp44_armed = false;
private boolean mp44_firing = false;
private BukkitTask lockup_schedule_id = null;
2012-11-27 19:02:39 +00:00
private String last_message = "";
private boolean in_adminchat = false;
private boolean all_commands_blocked = false;
private Boolean superadmin_id_verified = null;
private String last_command = "";
2013-01-21 18:58:42 +00:00
private boolean cmdspy_enabled = false;
2013-08-12 10:26:49 +00:00
private String tag = null;
2011-10-02 04:18:52 +00:00
2013-01-21 18:58:42 +00:00
public TFM_PlayerData(Player player)
2011-10-01 17:59:46 +00:00
{
2011-10-21 17:02:07 +00:00
this.player = player;
this.ip_address = player.getAddress().getAddress().getHostAddress();
this.player_name = player.getName();
2011-10-01 17:59:46 +00:00
}
2013-01-21 18:58:42 +00:00
public static TFM_PlayerData getPlayerData(Player p)
2011-10-16 06:00:37 +00:00
{
2013-01-21 18:58:42 +00:00
TFM_PlayerData playerdata = TFM_PlayerData.userinfo.get(p);
if (playerdata == null)
{
2013-01-21 18:58:42 +00:00
Iterator<Entry<Player, TFM_PlayerData>> it = userinfo.entrySet().iterator();
while (it.hasNext())
{
2013-01-21 18:58:42 +00:00
Entry<Player, TFM_PlayerData> pair = it.next();
TFM_PlayerData playerdata_test = pair.getValue();
if (playerdata_test.player_name.equalsIgnoreCase(p.getName()))
{
if (Bukkit.getOnlineMode())
{
playerdata = playerdata_test;
break;
}
else
{
if (playerdata_test.ip_address.equalsIgnoreCase(p.getAddress().getAddress().getHostAddress()))
{
playerdata = playerdata_test;
break;
}
}
}
}
}
2011-10-16 06:00:37 +00:00
if (playerdata == null)
{
2013-01-21 18:58:42 +00:00
playerdata = new TFM_PlayerData(p);
TFM_PlayerData.userinfo.put(p, playerdata);
2011-10-16 06:00:37 +00:00
}
2011-10-16 06:00:37 +00:00
return playerdata;
}
public String getIpAddress()
{
return ip_address;
}
public String getPlayerName()
{
return player_name;
}
2011-10-16 06:00:37 +00:00
public boolean isOrbiting()
{
2013-01-21 18:58:42 +00:00
return is_orbiting;
2011-10-16 06:00:37 +00:00
}
public void startOrbiting(double orbit_strength)
{
this.is_orbiting = true;
this.orbit_strength = orbit_strength;
}
2011-10-16 06:00:37 +00:00
public void stopOrbiting()
{
2013-01-21 18:58:42 +00:00
is_orbiting = false;
2011-10-16 06:00:37 +00:00
}
public double orbitStrength()
{
2013-01-21 18:58:42 +00:00
return orbit_strength;
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.user_caged = state;
}
2011-10-14 23:29:09 +00:00
2011-10-10 12:09:19 +00:00
public void setCaged(boolean state, Location location, Material material_outer, Material material_inner)
{
this.user_caged = state;
this.user_cage_pos = location;
this.cage_material_outer = material_outer;
this.cage_material_inner = material_inner;
}
2011-10-14 23:29:09 +00:00
2011-10-10 12:09:19 +00:00
public boolean isCaged()
{
2013-01-21 18:58:42 +00:00
return user_caged;
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.cage_material_outer;
case INNER:
return this.cage_material_inner;
default:
return this.cage_material_outer;
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()
{
2013-01-21 18:58:42 +00:00
return user_cage_pos;
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.user_cage_history.clear();
}
2011-10-14 23:29:09 +00:00
2011-10-10 12:09:19 +00:00
public void insertHistoryBlock(Location location, Material material)
{
this.user_cage_history.add(new TFM_BlockData(location, material));
}
2011-10-14 23:29:09 +00:00
2011-10-10 12:09:19 +00:00
public void regenerateHistory()
{
for (TFM_BlockData blockdata : this.user_cage_history)
{
blockdata.location.getBlock().setType(blockdata.material);
}
}
2011-10-14 23:29:09 +00:00
2011-10-10 12:09:19 +00:00
class TFM_BlockData
{
public Material material;
public Location location;
public TFM_BlockData(Location location, Material material)
{
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.user_frozen;
}
2011-10-02 04:18:52 +00:00
2011-10-01 17:59:46 +00:00
public void setFrozen(boolean fr)
{
this.user_frozen = fr;
}
public void resetMsgCount()
{
this.msg_count = 0;
}
2011-10-02 04:18:52 +00:00
2011-10-01 17:59:46 +00:00
public void incrementMsgCount()
{
this.msg_count++;
}
2011-10-02 04:18:52 +00:00
2011-10-01 17:59:46 +00:00
public int getMsgCount()
{
2013-01-21 18:58:42 +00:00
return msg_count;
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 incrementBlockDestroyCount()
{
2011-10-05 19:07:45 +00:00
this.block_destroy_total++;
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 int getBlockDestroyCount()
{
2013-01-21 18:58:42 +00:00
return block_destroy_total;
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()
{
2011-10-05 19:07:45 +00:00
this.block_destroy_total = 0;
}
2011-10-18 04:08:40 +00:00
public void incrementBlockPlaceCount()
{
this.block_place_total++;
}
public int getBlockPlaceCount()
{
2013-01-21 18:58:42 +00:00
return block_place_total;
2011-10-18 04:08:40 +00:00
}
public void resetBlockPlaceCount()
{
this.block_place_total = 0;
}
2011-10-14 23:29:09 +00:00
2011-10-05 19:07:45 +00:00
public void incrementFreecamDestroyCount()
{
this.freecam_destroy_count++;
}
public int getFreecamDestroyCount()
{
2013-01-21 18:58:42 +00:00
return freecam_destroy_count;
2011-10-05 19:07:45 +00:00
}
public void resetFreecamDestroyCount()
{
this.freecam_destroy_count = 0;
}
2011-10-14 23:29:09 +00:00
2011-10-05 19:07:45 +00:00
public void incrementFreecamPlaceCount()
{
this.freecam_place_count++;
}
public int getFreecamPlaceCount()
{
2013-01-21 18:58:42 +00:00
return freecam_place_count;
2011-10-05 19:07:45 +00:00
}
public void resetFreecamPlaceCount()
{
this.freecam_place_count = 0;
2011-10-01 17:59:46 +00:00
}
2011-10-16 06:00:37 +00:00
2012-03-03 04:29:54 +00:00
public void enableMobThrower(EntityType mob_thrower_creature, double mob_thrower_speed)
2011-10-16 06:00:37 +00:00
{
this.mob_thrower_enabled = true;
this.mob_thrower_creature = mob_thrower_creature;
this.mob_thrower_speed = mob_thrower_speed;
}
2011-10-16 06:00:37 +00:00
public void disableMobThrower()
{
this.mob_thrower_enabled = false;
}
2012-03-03 04:29:54 +00:00
public EntityType mobThrowerCreature()
2011-10-16 06:00:37 +00:00
{
2013-01-21 18:58:42 +00:00
return mob_thrower_creature;
2011-10-16 06:00:37 +00:00
}
public double mobThrowerSpeed()
{
2013-01-21 18:58:42 +00:00
return mob_thrower_speed;
2011-10-16 06:00:37 +00:00
}
2011-10-16 06:00:37 +00:00
public boolean mobThrowerEnabled()
{
2013-01-21 18:58:42 +00:00
return mob_thrower_enabled;
2011-10-16 06:00:37 +00:00
}
2011-10-16 06:00:37 +00:00
public void enqueueMob(LivingEntity mob)
{
2011-10-18 04:08:40 +00:00
mob_thrower_queue.add(mob);
if (mob_thrower_queue.size() > 4)
2011-10-16 06:00:37 +00:00
{
2011-10-18 04:08:40 +00:00
LivingEntity oldmob = mob_thrower_queue.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();
2013-07-28 17:15:51 +00:00
this.mp44_schedule_id = new ArrowShooter(this.player).runTaskTimer(plugin, 1L, 1L);
2011-10-21 17:02:07 +00:00
mp44_firing = 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.mp44_schedule_id != null)
2011-10-16 06:00:37 +00:00
{
this.mp44_schedule_id.cancel();
this.mp44_schedule_id = null;
2011-10-16 06:00:37 +00:00
}
2011-10-21 17:02:07 +00:00
mp44_firing = false;
}
private class ArrowShooter extends BukkitRunnable
2011-10-21 17:02:07 +00:00
{
private Player _player;
2011-10-21 17:02:07 +00:00
public ArrowShooter(Player player)
{
this._player = player;
}
@Override
public void run()
{
2012-03-03 20:48:41 +00:00
Arrow shot_arrow = _player.launchProjectile(Arrow.class);
2011-10-21 17:02:07 +00:00
shot_arrow.setVelocity(shot_arrow.getVelocity().multiply(2.0));
}
}
2011-10-21 17:02:07 +00:00
public void armMP44()
{
mp44_armed = true;
this.stopArrowShooter();
}
2011-10-21 17:02:07 +00:00
public void disarmMP44()
{
mp44_armed = false;
this.stopArrowShooter();
}
2011-10-21 17:02:07 +00:00
public boolean isMP44Armed()
{
2013-01-21 18:58:42 +00:00
return mp44_armed;
2011-10-21 17:02:07 +00:00
}
2011-10-21 17:02:07 +00:00
public boolean toggleMP44Firing()
{
this.mp44_firing = !this.mp44_firing;
2013-01-21 18:58:42 +00:00
return mp44_firing;
2011-10-16 06:00:37 +00:00
}
public boolean isMuted()
{
return is_muted;
}
public void setMuted(boolean is_muted)
{
this.is_muted = is_muted;
}
2012-09-18 10:13:06 +00:00
public boolean isHalted()
{
return is_halted;
2012-09-18 10:13:06 +00:00
}
2012-09-18 10:13:06 +00:00
public void setHalted(boolean is_halted)
{
this.is_halted = is_halted;
2013-07-02 20:31:05 +00:00
if (is_halted)
{
player.setOp(false);
player.setGameMode(GameMode.SURVIVAL);
player.setFlying(false);
player.setDisplayName(player_name);
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 lockup_schedule_id;
}
public void setLockupScheduleID(BukkitTask lockup_schedule_id)
{
this.lockup_schedule_id = lockup_schedule_id;
}
2012-11-27 19:02:39 +00:00
public void setLastMessage(String last_message)
{
this.last_message = last_message;
}
public String getLastMessage()
{
2013-01-21 18:58:42 +00:00
return last_message;
2012-11-27 19:02:39 +00:00
}
public void setAdminChat(boolean in_adminchat)
{
this.in_adminchat = in_adminchat;
}
public boolean inAdminChat()
{
2013-01-21 18:58:42 +00:00
return in_adminchat;
}
2012-12-06 09:32:08 +00:00
public boolean allCommandsBlocked()
2012-12-06 09:32:08 +00:00
{
2013-01-21 18:58:42 +00:00
return all_commands_blocked;
2012-12-06 09:32:08 +00:00
}
public void setCommandsBlocked(boolean commands_blocked)
{
this.all_commands_blocked = commands_blocked;
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 superadmin_id_verified;
}
//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 superadmin_id_verified)
{
this.superadmin_id_verified = superadmin_id_verified;
}
public String getLastCommand()
{
return last_command;
}
public void setLastCommand(String last_command)
{
this.last_command = last_command;
}
2013-01-21 18:58:42 +00:00
public void setCommandSpy(boolean cmdspy_enabled)
{
this.cmdspy_enabled = cmdspy_enabled;
}
public boolean cmdspyEnabled()
{
return cmdspy_enabled;
}
2013-08-12 10:26:49 +00:00
public void setTag(String tag)
{
if (tag == null)
{
this.tag = null;
}
else
{
this.tag = TFM_Util.colorise(tag) + ChatColor.WHITE;
}
}
public String getTag()
{
return this.tag;
}
2011-10-01 17:59:46 +00:00
}