Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.gabik21.hospitalcore.types;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Set;
- import net.md_5.bungee.api.chat.ClickEvent;
- import net.md_5.bungee.api.chat.ClickEvent.Action;
- import net.md_5.bungee.api.chat.ComponentBuilder;
- import net.md_5.bungee.api.chat.HoverEvent;
- import net.md_5.bungee.api.chat.TextComponent;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.potion.PotionEffect;
- import com.sk89q.worldguard.protection.regions.ProtectedRegion;
- import de.gabik21.api.GabikAPI;
- import de.gabik21.hospitalcore.HospitalCore;
- import de.gabik21.hospitalcore.events.PlayerChangeWalkSpeedEvent;
- public class PlayerData {
- public static ArrayList<PlayerData> list = new ArrayList<PlayerData>();
- static final DecimalFormat COOLDOWN_FORMAT = new DecimalFormat("#0.0");
- private Player player, lastDamager = this.getPlayer(), lastDamaged;
- private boolean adminmode = false, frozen = false, ingame = false,
- in1v1 = false, disguised = false, challenge = false,
- teamtag = false, chest = false, fakekits = false, hg = false;
- private int currentArena = -1;
- private Location frozenloc;
- private AbstractGUI currentGui;
- private long lastReport, cooldown, money, lasthit;
- private String nick, lastmessage;
- private List<String> duels = new ArrayList<String>();
- private Team team, teaminvitation;
- private Set<ProtectedRegion> currentregions = new HashSet<ProtectedRegion>();
- private Kit kit = Kit.NONE;
- private List<Kit> ownedkits = new ArrayList<Kit>();
- public PlayerData(Player p) {
- this.player = p;
- handleKits();
- handleMoney();
- list.add(this);
- }
- private void handleMoney() {
- FileConfiguration moneycfg = HospitalCore.getInstance()
- .getMoneyConfig();
- this.money = moneycfg.getLong(player.getUniqueId().toString());
- }
- private void handleKits() {
- if (player.hasPermission("Donator")
- || player.hasPermission("Supporter")
- || player.hasPermission("Moderator")) {
- setFakekits(true);
- for (Kit k : Kit.values())
- this.ownedkits.add(k);
- } else {
- List<String> kits = HospitalCore.getInstance().getKitConfig()
- .getStringList(player.getUniqueId().toString());
- Collections.sort(kits);
- for (String s : kits)
- for (Kit k : Kit.values())
- if (k.getName().equalsIgnoreCase(s))
- this.ownedkits.add(k);
- }
- if (!this.ownedkits.contains(Kit.PVP))
- this.ownedkits.add(Kit.PVP);
- }
- public void setWalkSpeed(float speed) {
- PlayerChangeWalkSpeedEvent e = new PlayerChangeWalkSpeedEvent(player,
- player.getWalkSpeed(), speed);
- Bukkit.getPluginManager().callEvent(e);
- player.setWalkSpeed(speed);
- }
- public void delete() {
- list.remove(this);
- }
- public long getLasthit() {
- return lasthit;
- }
- public void hit() {
- this.lasthit = System.currentTimeMillis();
- }
- public boolean hasMoney(long amount) {
- return (getMoney() - amount >= 0);
- }
- public void addMoney(long amount) {
- this.money += amount;
- }
- public long getMoney() {
- return this.money;
- }
- public void setLastDamaged(Player lastdamaged) {
- this.lastDamaged = lastdamaged;
- }
- public Player getLastDamaged() {
- return this.lastDamaged;
- }
- public void sendCooldown(long ms) {
- long l = ms - (System.currentTimeMillis() - cooldown);
- double display = ((double) l) / 1000;
- player.sendMessage("§cYou're still on Cooldown: "
- + COOLDOWN_FORMAT.format(display));
- }
- public boolean isOnCooldown(long ms) {
- return ((System.currentTimeMillis() - cooldown) < ms);
- }
- public void useKit() {
- this.cooldown = System.currentTimeMillis();
- }
- public void addKit(Kit k) {
- this.ownedkits.add(k);
- Collections.sort(this.ownedkits);
- }
- public List<Kit> getOwnedKits() {
- return this.ownedkits;
- }
- public void setKit(Kit kit) {
- this.cooldown = 0;
- this.kit = kit;
- }
- public Kit getKit() {
- return this.kit;
- }
- public void updateRegions(Set<ProtectedRegion> newregions) {
- this.currentregions = newregions;
- }
- public Set<ProtectedRegion> getApplicableRegions() {
- return this.currentregions;
- }
- public void setTeam(Team team) {
- this.team = team;
- }
- public Team getTeam() {
- return this.team;
- }
- public boolean isInTeamTag() {
- return this.teamtag;
- }
- public void setTeamTag(boolean mode) {
- this.teamtag = mode;
- }
- public List<String> getDuels() {
- return this.duels;
- }
- public boolean isInChallenge() {
- return this.challenge;
- }
- public void setInChallenge(boolean mode) {
- this.challenge = mode;
- }
- public String getLastMessage() {
- return this.lastmessage;
- }
- public void setLastMessage(String s) {
- this.lastmessage = s;
- }
- public String getNick() {
- if (this.nick != null)
- return this.nick;
- return player.getName();
- }
- public void setNick(String nick) {
- this.nick = nick;
- }
- public void duel(Player p) {
- duels.add(p.getName());
- }
- public void removeDuel(String s) {
- duels.remove(s);
- }
- public void report() {
- this.lastReport = System.currentTimeMillis();
- }
- public long getLastReport() {
- return this.lastReport;
- }
- public int getCurrentArena() {
- return this.currentArena;
- }
- public void setCurrentArena(int i) {
- this.currentArena = i;
- }
- public Player getLastDamager() {
- return this.lastDamager;
- }
- public void setLastDamager(Player p) {
- this.lastDamager = p;
- }
- public AbstractGUI getCurrentGui() {
- return this.currentGui;
- }
- public void setCurrentGui(AbstractGUI currentGui) {
- this.currentGui = currentGui;
- }
- public void setIn1v1(boolean mode) {
- this.in1v1 = mode;
- }
- public boolean isIn1v1() {
- return this.in1v1;
- }
- public void setDisguised(Boolean mode) {
- this.disguised = mode;
- }
- public Boolean isDisguised() {
- return this.disguised;
- }
- public void setIngame(boolean mode) {
- this.ingame = mode;
- }
- public boolean isIngame() {
- return this.ingame;
- }
- public void setAdminmode(Boolean mode) {
- this.adminmode = mode;
- }
- public Boolean isInAdminmode() {
- return this.adminmode;
- }
- public void setFrozen(Boolean mode) {
- this.frozen = mode;
- }
- public Boolean isFrozen() {
- return this.frozen;
- }
- public Player getPlayer() {
- return this.player;
- }
- public void setFrozenLocation(Location loc) {
- this.frozenloc = loc;
- }
- public Location getFrozenLocation() {
- return this.frozenloc;
- }
- public Team getTeaminvitation() {
- return teaminvitation;
- }
- public void setTeaminvitation(Team teaminvitation) {
- this.teaminvitation = teaminvitation;
- }
- public void sendHoverableMessage(String msg, String hovermsg, String command) {
- TextComponent tc = new TextComponent();
- tc.setText(msg);
- if (command != null)
- tc.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/" + command));
- tc.setHoverEvent(new HoverEvent(
- net.md_5.bungee.api.chat.HoverEvent.Action.SHOW_TEXT,
- new ComponentBuilder(hovermsg).create()));
- getPlayer().spigot().sendMessage(tc);
- }
- public TextComponent createComponent(String msg, String hovermsg,
- String command) {
- TextComponent tc = new TextComponent();
- tc.setText(msg);
- if (command != null)
- tc.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/" + command));
- tc.setHoverEvent(new HoverEvent(
- net.md_5.bungee.api.chat.HoverEvent.Action.SHOW_TEXT,
- new ComponentBuilder(hovermsg).create()));
- return tc;
- }
- public boolean isChest() {
- return chest;
- }
- public void setChest(boolean chest) {
- this.chest = chest;
- }
- public void spawn() {
- FileConfiguration config = HospitalCore.getInstance().getConfig();
- Location spawn = new Location(Bukkit.getWorlds().get(0),
- config.getDouble("spawn.x"), config.getDouble("spawn.y") + 1,
- config.getDouble("spawn.z"));
- player.teleport(spawn);
- if (isInAdminmode())
- player.performCommand("admin");
- ItemStack a = GabikAPI.createItem(Material.COMPASS, "§4Warps");
- ItemStack b = GabikAPI.createItem(Material.ENCHANTMENT_TABLE, "§4Shop");
- this.setIngame(false);
- this.setIn1v1(false);
- this.setInChallenge(false);
- this.setKit(Kit.NONE);
- this.setCurrentArena(-1);
- this.setHg(false);
- for (PlayerData all : PlayerData.list)
- if (all.getLastDamaged() != null
- && all.getLastDamaged().equals(player))
- all.setLastDamaged(null);
- setWalkSpeed(0.2F);
- if (!player.isDead())
- player.setHealth(20D);
- for (PotionEffect effect : player.getActivePotionEffects())
- player.removePotionEffect(effect.getType());
- player.getInventory().clear();
- player.getInventory().setArmorContents(null);
- player.getInventory().setItem(3, a);
- player.getInventory().setItem(5, b);
- }
- public boolean isFakekits() {
- return fakekits;
- }
- public void setFakekits(boolean fakekits) {
- this.fakekits = fakekits;
- }
- public boolean isHg() {
- return hg;
- }
- public void setHg(boolean hg) {
- this.hg = hg;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement