mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-06-12 13:53:54 +00:00
Mavenized project
This commit is contained in:
@ -0,0 +1,414 @@
|
||||
package me.totalfreedom.totalfreedommod.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.totalfreedom.totalfreedommod.caging.CageData;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.freeze.FreezeData;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
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;
|
||||
|
||||
public class FPlayer
|
||||
{
|
||||
public static final long AUTO_PURGE_TICKS = 5L * 60L * 20L;
|
||||
|
||||
@Getter
|
||||
private final String name;
|
||||
@Getter
|
||||
private final String ip;
|
||||
//
|
||||
@Setter
|
||||
private Player player;
|
||||
//
|
||||
private BukkitTask unmuteTask;
|
||||
private BukkitTask unfreezeTask;
|
||||
@Getter
|
||||
private final FreezeData freezeData = new FreezeData(this);
|
||||
@Getter
|
||||
private double fuckoffRadius = 0;
|
||||
private int messageCount = 0;
|
||||
private int totalBlockDestroy = 0;
|
||||
private int totalBlockPlace = 0;
|
||||
private int freecamDestroyCount = 0;
|
||||
private int freecamPlaceCount = 0;
|
||||
@Getter
|
||||
private final CageData cageData = new CageData(this);
|
||||
private boolean isOrbiting = false;
|
||||
private double orbitStrength = 10.0;
|
||||
private boolean mobThrowerEnabled = false;
|
||||
private EntityType mobThrowerEntity = EntityType.PIG;
|
||||
private double mobThrowerSpeed = 4.0;
|
||||
private final List<LivingEntity> mobThrowerQueue = new ArrayList<LivingEntity>();
|
||||
private BukkitTask mp44ScheduleTask = null;
|
||||
private boolean mp44Armed = false;
|
||||
private boolean mp44Firing = false;
|
||||
private BukkitTask lockupScheduleTask = null;
|
||||
private String lastMessage = "";
|
||||
private boolean inAdminchat = false;
|
||||
private boolean allCommandsBlocked = false;
|
||||
private boolean verifiedSuperadminId = false;
|
||||
private String lastCommand = "";
|
||||
private boolean cmdspyEnabled = false;
|
||||
private String tag = null;
|
||||
private int warningCount = 0;
|
||||
|
||||
public FPlayer(Player player)
|
||||
{
|
||||
this(player.getName(), Ips.getIp(player));
|
||||
}
|
||||
|
||||
private FPlayer(String name, String ip)
|
||||
{
|
||||
this.name = name;
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public Player getPlayer()
|
||||
{
|
||||
if (player != null && !player.isOnline())
|
||||
{
|
||||
player = null;
|
||||
}
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (Ips.getIp(onlinePlayer).equals(ip))
|
||||
{
|
||||
player = onlinePlayer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
public boolean isOrbiting()
|
||||
{
|
||||
return isOrbiting;
|
||||
}
|
||||
|
||||
public void startOrbiting(double strength)
|
||||
{
|
||||
this.isOrbiting = true;
|
||||
this.orbitStrength = strength;
|
||||
}
|
||||
|
||||
public void stopOrbiting()
|
||||
{
|
||||
this.isOrbiting = false;
|
||||
}
|
||||
|
||||
public double orbitStrength()
|
||||
{
|
||||
return orbitStrength;
|
||||
}
|
||||
|
||||
public boolean isFuckOff()
|
||||
{
|
||||
return fuckoffRadius > 0;
|
||||
}
|
||||
|
||||
public void setFuckoff(double radius)
|
||||
{
|
||||
this.fuckoffRadius = radius;
|
||||
}
|
||||
|
||||
public void disableFuckoff()
|
||||
{
|
||||
this.fuckoffRadius = 0;
|
||||
}
|
||||
|
||||
public void resetMsgCount()
|
||||
{
|
||||
this.messageCount = 0;
|
||||
}
|
||||
|
||||
public int incrementAndGetMsgCount()
|
||||
{
|
||||
return this.messageCount++;
|
||||
}
|
||||
|
||||
public int incrementAndGetBlockDestroyCount()
|
||||
{
|
||||
return this.totalBlockDestroy++;
|
||||
}
|
||||
|
||||
public void resetBlockDestroyCount()
|
||||
{
|
||||
this.totalBlockDestroy = 0;
|
||||
}
|
||||
|
||||
public int incrementAndGetBlockPlaceCount()
|
||||
{
|
||||
return this.totalBlockPlace++;
|
||||
}
|
||||
|
||||
public void resetBlockPlaceCount()
|
||||
{
|
||||
this.totalBlockPlace = 0;
|
||||
}
|
||||
|
||||
public int incrementAndGetFreecamDestroyCount()
|
||||
{
|
||||
return this.freecamDestroyCount++;
|
||||
}
|
||||
|
||||
public void resetFreecamDestroyCount()
|
||||
{
|
||||
this.freecamDestroyCount = 0;
|
||||
}
|
||||
|
||||
public int incrementAndGetFreecamPlaceCount()
|
||||
{
|
||||
return this.freecamPlaceCount++;
|
||||
}
|
||||
|
||||
public void resetFreecamPlaceCount()
|
||||
{
|
||||
this.freecamPlaceCount = 0;
|
||||
}
|
||||
|
||||
public void enableMobThrower(EntityType mobThrowerCreature, double mobThrowerSpeed)
|
||||
{
|
||||
this.mobThrowerEnabled = true;
|
||||
this.mobThrowerEntity = mobThrowerCreature;
|
||||
this.mobThrowerSpeed = mobThrowerSpeed;
|
||||
}
|
||||
|
||||
public void disableMobThrower()
|
||||
{
|
||||
this.mobThrowerEnabled = false;
|
||||
}
|
||||
|
||||
public EntityType mobThrowerCreature()
|
||||
{
|
||||
return this.mobThrowerEntity;
|
||||
}
|
||||
|
||||
public double mobThrowerSpeed()
|
||||
{
|
||||
return this.mobThrowerSpeed;
|
||||
}
|
||||
|
||||
public boolean mobThrowerEnabled()
|
||||
{
|
||||
return this.mobThrowerEnabled;
|
||||
}
|
||||
|
||||
public void enqueueMob(LivingEntity mob)
|
||||
{
|
||||
mobThrowerQueue.add(mob);
|
||||
if (mobThrowerQueue.size() > 4)
|
||||
{
|
||||
LivingEntity oldmob = mobThrowerQueue.remove(0);
|
||||
if (oldmob != null)
|
||||
{
|
||||
oldmob.damage(500.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void startArrowShooter(TotalFreedomMod plugin)
|
||||
{
|
||||
this.stopArrowShooter();
|
||||
this.mp44ScheduleTask = new ArrowShooter(this.player).runTaskTimer(plugin, 1L, 1L);
|
||||
this.mp44Firing = true;
|
||||
}
|
||||
|
||||
public void stopArrowShooter()
|
||||
{
|
||||
if (this.mp44ScheduleTask != null)
|
||||
{
|
||||
this.mp44ScheduleTask.cancel();
|
||||
this.mp44ScheduleTask = null;
|
||||
}
|
||||
this.mp44Firing = false;
|
||||
}
|
||||
|
||||
public void armMP44()
|
||||
{
|
||||
this.mp44Armed = true;
|
||||
this.stopArrowShooter();
|
||||
}
|
||||
|
||||
public void disarmMP44()
|
||||
{
|
||||
this.mp44Armed = false;
|
||||
this.stopArrowShooter();
|
||||
}
|
||||
|
||||
public boolean isMP44Armed()
|
||||
{
|
||||
return this.mp44Armed;
|
||||
}
|
||||
|
||||
public boolean toggleMP44Firing()
|
||||
{
|
||||
this.mp44Firing = !this.mp44Firing;
|
||||
return mp44Firing;
|
||||
}
|
||||
|
||||
public boolean isMuted()
|
||||
{
|
||||
return unmuteTask != null;
|
||||
}
|
||||
|
||||
public void setMuted(boolean muted)
|
||||
{
|
||||
FUtil.cancel(unmuteTask);
|
||||
unmuteTask = null;
|
||||
|
||||
if (!muted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
unmuteTask = new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
FUtil.adminAction("TotalFreedom", "Unmuting " + player.getName(), false);
|
||||
setMuted(false);
|
||||
}
|
||||
}.runTaskLater(TotalFreedomMod.plugin, AUTO_PURGE_TICKS);
|
||||
}
|
||||
|
||||
public BukkitTask getLockupScheduleID()
|
||||
{
|
||||
return this.lockupScheduleTask;
|
||||
}
|
||||
|
||||
public void setLockupScheduleID(BukkitTask id)
|
||||
{
|
||||
this.lockupScheduleTask = id;
|
||||
}
|
||||
|
||||
public void setLastMessage(String message)
|
||||
{
|
||||
this.lastMessage = message;
|
||||
}
|
||||
|
||||
public String getLastMessage()
|
||||
{
|
||||
return lastMessage;
|
||||
}
|
||||
|
||||
public void setAdminChat(boolean inAdminchat)
|
||||
{
|
||||
this.inAdminchat = inAdminchat;
|
||||
}
|
||||
|
||||
public boolean inAdminChat()
|
||||
{
|
||||
return this.inAdminchat;
|
||||
}
|
||||
|
||||
public boolean allCommandsBlocked()
|
||||
{
|
||||
return this.allCommandsBlocked;
|
||||
}
|
||||
|
||||
public void setCommandsBlocked(boolean commandsBlocked)
|
||||
{
|
||||
this.allCommandsBlocked = commandsBlocked;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
public void setCommandSpy(boolean enabled)
|
||||
{
|
||||
this.cmdspyEnabled = enabled;
|
||||
}
|
||||
|
||||
public boolean cmdspyEnabled()
|
||||
{
|
||||
return cmdspyEnabled;
|
||||
}
|
||||
|
||||
public void setTag(String tag)
|
||||
{
|
||||
if (tag == null)
|
||||
{
|
||||
this.tag = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.tag = FUtil.colorize(tag) + ChatColor.WHITE;
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
FUtil.playerMsg(this.player, ChatColor.RED + "You have been warned at least twice now, make sure to read the rules at " + ConfigEntry.SERVER_BAN_URL.getString());
|
||||
}
|
||||
}
|
||||
|
||||
private class ArrowShooter extends BukkitRunnable
|
||||
{
|
||||
private final Player player;
|
||||
|
||||
private ArrowShooter(Player player)
|
||||
{
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
Arrow shot = player.launchProjectile(Arrow.class);
|
||||
shot.setVelocity(shot.getVelocity().multiply(2.0));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package me.totalfreedom.totalfreedommod.player;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import java.util.Set;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.pravian.aero.base.ConfigLoadable;
|
||||
import net.pravian.aero.base.ConfigSavable;
|
||||
import net.pravian.aero.base.Validatable;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerData implements ConfigLoadable, ConfigSavable, Validatable
|
||||
{
|
||||
@Getter
|
||||
@Setter
|
||||
private String username;
|
||||
@Getter
|
||||
@Setter
|
||||
private long firstJoinUnix;
|
||||
@Getter
|
||||
@Setter
|
||||
private long lastJoinUnix;
|
||||
@Getter
|
||||
private final Set<String> ips = Sets.newHashSet();
|
||||
|
||||
public PlayerData(Player player)
|
||||
{
|
||||
this(player.getName());
|
||||
}
|
||||
|
||||
public PlayerData(String username)
|
||||
{
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFrom(ConfigurationSection cs)
|
||||
{
|
||||
this.username = cs.getString("username", username);
|
||||
this.ips.clear();
|
||||
this.ips.addAll(cs.getStringList("ips"));
|
||||
this.firstJoinUnix = cs.getLong("first_join", 0);
|
||||
this.lastJoinUnix = cs.getLong("last_join", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveTo(ConfigurationSection cs)
|
||||
{
|
||||
Validate.isTrue(isValid(), "Could not save player entry: " + username + ". Entry not valid!");
|
||||
cs.set("username", username);
|
||||
cs.set("ips", ips);
|
||||
cs.set("first_join", firstJoinUnix);
|
||||
cs.set("last_join", lastJoinUnix);
|
||||
}
|
||||
|
||||
// IP utils
|
||||
public boolean addIp(String ip)
|
||||
{
|
||||
return ips.add(ip);
|
||||
}
|
||||
|
||||
public boolean removeIp(String ip)
|
||||
{
|
||||
return ips.remove(ip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid()
|
||||
{
|
||||
return username != null
|
||||
&& firstJoinUnix != 0
|
||||
&& lastJoinUnix != 0
|
||||
&& !ips.isEmpty();
|
||||
}
|
||||
}
|
@ -0,0 +1,222 @@
|
||||
package me.totalfreedom.totalfreedommod.player;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import lombok.Getter;
|
||||
import me.totalfreedom.totalfreedommod.config.FConfig;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class PlayerList extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
public static final long AUTO_PURGE_TICKS = 20L * 60L * 5L;
|
||||
//
|
||||
@Getter
|
||||
public final Map<String, FPlayer> playerMap = Maps.newHashMap(); // ip,dataMap
|
||||
@Getter
|
||||
public final Map<String, PlayerData> dataMap = Maps.newHashMap(); // ip,dataMap
|
||||
@Getter
|
||||
private final File configFolder;
|
||||
|
||||
public PlayerList(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
|
||||
this.configFolder = new File(plugin.getDataFolder(), "players");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
playerMap.clear();
|
||||
dataMap.clear();
|
||||
|
||||
// Preload online playerMap
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
getPlayer(player);
|
||||
}
|
||||
|
||||
FLog.info("Loaded playerdata for " + playerMap.size() + " players");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
save();
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
for (PlayerData data : dataMap.values())
|
||||
{
|
||||
FConfig config = getConfig(data);
|
||||
data.saveTo(config);
|
||||
config.save();
|
||||
}
|
||||
}
|
||||
|
||||
public FPlayer getPlayerSync(Player player)
|
||||
{
|
||||
synchronized (playerMap)
|
||||
{
|
||||
return getPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
public String getIp(OfflinePlayer player)
|
||||
{
|
||||
if (player.isOnline())
|
||||
{
|
||||
return Ips.getIp(player.getPlayer());
|
||||
}
|
||||
|
||||
final PlayerData entry = getData(player.getName());
|
||||
|
||||
return (entry == null ? null : entry.getIps().iterator().next());
|
||||
}
|
||||
|
||||
// May not return null
|
||||
public FPlayer getPlayer(Player player)
|
||||
{
|
||||
FPlayer tPlayer = playerMap.get(Ips.getIp(player));
|
||||
if (tPlayer != null)
|
||||
{
|
||||
return tPlayer;
|
||||
}
|
||||
|
||||
tPlayer = new FPlayer(player);
|
||||
playerMap.put(Ips.getIp(player), tPlayer);
|
||||
|
||||
return tPlayer;
|
||||
}
|
||||
|
||||
// May not return null
|
||||
public PlayerData getData(Player player)
|
||||
{
|
||||
// Check already loaded
|
||||
PlayerData data = dataMap.get(Ips.getIp(player));
|
||||
if (data != null)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
// Load data
|
||||
data = getData(player.getName());
|
||||
|
||||
// Create data if nonexistent
|
||||
if (data == null)
|
||||
{
|
||||
FLog.info("Creating new player data entry for " + player.getName());
|
||||
|
||||
// Create new player
|
||||
final long unix = FUtil.getUnixTime();
|
||||
data = new PlayerData(player);
|
||||
data.setFirstJoinUnix(unix);
|
||||
data.setLastJoinUnix(unix);
|
||||
data.addIp(Ips.getIp(player));
|
||||
|
||||
// Store player
|
||||
dataMap.put(player.getName().toLowerCase(), data);
|
||||
|
||||
// Save player
|
||||
FConfig config = getConfig(data);
|
||||
data.saveTo(config);
|
||||
config.save();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// May return null
|
||||
public PlayerData getData(String username)
|
||||
{
|
||||
username = username.toLowerCase();
|
||||
|
||||
// Check if the player is a known player
|
||||
final File configFile = getConfigFile(username);
|
||||
if (!configFile.exists())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create and load entry
|
||||
final PlayerData data = new PlayerData(username);
|
||||
data.loadFrom(getConfig(data));
|
||||
|
||||
if (!data.isValid())
|
||||
{
|
||||
FLog.warning("Could not load player data entry: " + username + ". Entry is not valid!");
|
||||
configFile.delete();
|
||||
return null;
|
||||
}
|
||||
|
||||
// Only store data if the player is online
|
||||
for (String ip : data.getIps())
|
||||
{
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (Ips.getIp(onlinePlayer).equals(ip))
|
||||
{
|
||||
dataMap.put(ip, data);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
final String ip = Ips.getIp(event.getPlayer());
|
||||
playerMap.remove(ip);
|
||||
dataMap.remove(ip);
|
||||
}
|
||||
|
||||
public Collection<FPlayer> getLoadedPlayers()
|
||||
{
|
||||
return playerMap.values();
|
||||
}
|
||||
|
||||
public Collection<PlayerData> getLoadedData()
|
||||
{
|
||||
return dataMap.values();
|
||||
}
|
||||
|
||||
public int purgeAllData()
|
||||
{
|
||||
int deleted = 0;
|
||||
for (File file : getConfigFolder().listFiles())
|
||||
{
|
||||
deleted += file.delete() ? 1 : 0;
|
||||
}
|
||||
|
||||
dataMap.clear();
|
||||
return deleted;
|
||||
}
|
||||
|
||||
protected File getConfigFile(String name)
|
||||
{
|
||||
return new File(getConfigFolder(), name + ".yml");
|
||||
}
|
||||
|
||||
protected FConfig getConfig(PlayerData data)
|
||||
{
|
||||
final FConfig config = new FConfig(TotalFreedomMod.plugin, getConfigFile(data.getUsername().toLowerCase()), false);
|
||||
config.load();
|
||||
return config;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user