Advertisement
Guest User

PlayerData

a guest
Dec 9th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.69 KB | None | 0 0
  1. package de.gabik21.hospitalcore.types;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.util.ArrayList;
  5. import java.util.Collections;
  6. import java.util.HashSet;
  7. import java.util.List;
  8. import java.util.Set;
  9.  
  10. import net.md_5.bungee.api.chat.ClickEvent;
  11. import net.md_5.bungee.api.chat.ClickEvent.Action;
  12. import net.md_5.bungee.api.chat.ComponentBuilder;
  13. import net.md_5.bungee.api.chat.HoverEvent;
  14. import net.md_5.bungee.api.chat.TextComponent;
  15.  
  16. import org.bukkit.Bukkit;
  17. import org.bukkit.Location;
  18. import org.bukkit.Material;
  19. import org.bukkit.configuration.file.FileConfiguration;
  20. import org.bukkit.entity.Player;
  21. import org.bukkit.inventory.ItemStack;
  22. import org.bukkit.potion.PotionEffect;
  23.  
  24. import com.sk89q.worldguard.protection.regions.ProtectedRegion;
  25.  
  26. import de.gabik21.api.GabikAPI;
  27. import de.gabik21.hospitalcore.HospitalCore;
  28. import de.gabik21.hospitalcore.events.PlayerChangeWalkSpeedEvent;
  29.  
  30. public class PlayerData {
  31.  
  32.     public static ArrayList<PlayerData> list = new ArrayList<PlayerData>();
  33.     static final DecimalFormat COOLDOWN_FORMAT = new DecimalFormat("#0.0");
  34.  
  35.     private Player player, lastDamager = this.getPlayer(), lastDamaged;
  36.     private boolean adminmode = false, frozen = false, ingame = false,
  37.         in1v1 = false, disguised = false, challenge = false,
  38.         teamtag = false, chest = false, fakekits = false, hg = false;
  39.     private int currentArena = -1;
  40.     private Location frozenloc;
  41.     private AbstractGUI currentGui;
  42.     private long lastReport, cooldown, money, lasthit;
  43.     private String nick, lastmessage;
  44.     private List<String> duels = new ArrayList<String>();
  45.     private Team team, teaminvitation;
  46.     private Set<ProtectedRegion> currentregions = new HashSet<ProtectedRegion>();
  47.     private Kit kit = Kit.NONE;
  48.     private List<Kit> ownedkits = new ArrayList<Kit>();
  49.  
  50.     public PlayerData(Player p) {
  51.  
  52.     this.player = p;
  53.  
  54.     handleKits();
  55.     handleMoney();
  56.  
  57.     list.add(this);
  58.  
  59.     }
  60.  
  61.     private void handleMoney() {
  62.  
  63.     FileConfiguration moneycfg = HospitalCore.getInstance()
  64.         .getMoneyConfig();
  65.     this.money = moneycfg.getLong(player.getUniqueId().toString());
  66.  
  67.     }
  68.  
  69.     private void handleKits() {
  70.  
  71.     if (player.hasPermission("Donator")
  72.         || player.hasPermission("Supporter")
  73.         || player.hasPermission("Moderator")) {
  74.  
  75.         setFakekits(true);
  76.         for (Kit k : Kit.values())
  77.         this.ownedkits.add(k);
  78.  
  79.     } else {
  80.  
  81.         List<String> kits = HospitalCore.getInstance().getKitConfig()
  82.             .getStringList(player.getUniqueId().toString());
  83.  
  84.         Collections.sort(kits);
  85.  
  86.         for (String s : kits)
  87.         for (Kit k : Kit.values())
  88.             if (k.getName().equalsIgnoreCase(s))
  89.             this.ownedkits.add(k);
  90.     }
  91.  
  92.     if (!this.ownedkits.contains(Kit.PVP))
  93.         this.ownedkits.add(Kit.PVP);
  94.     }
  95.  
  96.     public void setWalkSpeed(float speed) {
  97.  
  98.     PlayerChangeWalkSpeedEvent e = new PlayerChangeWalkSpeedEvent(player,
  99.         player.getWalkSpeed(), speed);
  100.     Bukkit.getPluginManager().callEvent(e);
  101.     player.setWalkSpeed(speed);
  102.  
  103.     }
  104.  
  105.     public void delete() {
  106.  
  107.     list.remove(this);
  108.  
  109.     }
  110.  
  111.     public long getLasthit() {
  112.     return lasthit;
  113.     }
  114.  
  115.     public void hit() {
  116.     this.lasthit = System.currentTimeMillis();
  117.     }
  118.  
  119.     public boolean hasMoney(long amount) {
  120.  
  121.     return (getMoney() - amount >= 0);
  122.  
  123.     }
  124.  
  125.     public void addMoney(long amount) {
  126.  
  127.     this.money += amount;
  128.  
  129.     }
  130.  
  131.     public long getMoney() {
  132.  
  133.     return this.money;
  134.  
  135.     }
  136.  
  137.     public void setLastDamaged(Player lastdamaged) {
  138.  
  139.     this.lastDamaged = lastdamaged;
  140.  
  141.     }
  142.  
  143.     public Player getLastDamaged() {
  144.  
  145.     return this.lastDamaged;
  146.  
  147.     }
  148.  
  149.     public void sendCooldown(long ms) {
  150.  
  151.     long l = ms - (System.currentTimeMillis() - cooldown);
  152.     double display = ((double) l) / 1000;
  153.     player.sendMessage("§cYou're still on Cooldown: "
  154.         + COOLDOWN_FORMAT.format(display));
  155.  
  156.     }
  157.  
  158.     public boolean isOnCooldown(long ms) {
  159.  
  160.     return ((System.currentTimeMillis() - cooldown) < ms);
  161.  
  162.     }
  163.  
  164.     public void useKit() {
  165.  
  166.     this.cooldown = System.currentTimeMillis();
  167.  
  168.     }
  169.  
  170.     public void addKit(Kit k) {
  171.  
  172.     this.ownedkits.add(k);
  173.     Collections.sort(this.ownedkits);
  174.  
  175.     }
  176.  
  177.     public List<Kit> getOwnedKits() {
  178.  
  179.     return this.ownedkits;
  180.     }
  181.  
  182.     public void setKit(Kit kit) {
  183.  
  184.     this.cooldown = 0;
  185.     this.kit = kit;
  186.  
  187.     }
  188.  
  189.     public Kit getKit() {
  190.  
  191.     return this.kit;
  192.  
  193.     }
  194.  
  195.     public void updateRegions(Set<ProtectedRegion> newregions) {
  196.  
  197.     this.currentregions = newregions;
  198.  
  199.     }
  200.  
  201.     public Set<ProtectedRegion> getApplicableRegions() {
  202.  
  203.     return this.currentregions;
  204.  
  205.     }
  206.  
  207.     public void setTeam(Team team) {
  208.  
  209.     this.team = team;
  210.  
  211.     }
  212.  
  213.     public Team getTeam() {
  214.  
  215.     return this.team;
  216.     }
  217.  
  218.     public boolean isInTeamTag() {
  219.  
  220.     return this.teamtag;
  221.  
  222.     }
  223.  
  224.     public void setTeamTag(boolean mode) {
  225.  
  226.     this.teamtag = mode;
  227.  
  228.     }
  229.  
  230.     public List<String> getDuels() {
  231.  
  232.     return this.duels;
  233.  
  234.     }
  235.  
  236.     public boolean isInChallenge() {
  237.  
  238.     return this.challenge;
  239.  
  240.     }
  241.  
  242.     public void setInChallenge(boolean mode) {
  243.  
  244.     this.challenge = mode;
  245.  
  246.     }
  247.  
  248.     public String getLastMessage() {
  249.  
  250.     return this.lastmessage;
  251.  
  252.     }
  253.  
  254.     public void setLastMessage(String s) {
  255.  
  256.     this.lastmessage = s;
  257.  
  258.     }
  259.  
  260.     public String getNick() {
  261.  
  262.     if (this.nick != null)
  263.         return this.nick;
  264.     return player.getName();
  265.  
  266.     }
  267.  
  268.     public void setNick(String nick) {
  269.  
  270.     this.nick = nick;
  271.  
  272.     }
  273.  
  274.     public void duel(Player p) {
  275.  
  276.     duels.add(p.getName());
  277.  
  278.     }
  279.  
  280.     public void removeDuel(String s) {
  281.  
  282.     duels.remove(s);
  283.  
  284.     }
  285.  
  286.     public void report() {
  287.  
  288.     this.lastReport = System.currentTimeMillis();
  289.  
  290.     }
  291.  
  292.     public long getLastReport() {
  293.  
  294.     return this.lastReport;
  295.  
  296.     }
  297.  
  298.     public int getCurrentArena() {
  299.  
  300.     return this.currentArena;
  301.  
  302.     }
  303.  
  304.     public void setCurrentArena(int i) {
  305.  
  306.     this.currentArena = i;
  307.  
  308.     }
  309.  
  310.     public Player getLastDamager() {
  311.  
  312.     return this.lastDamager;
  313.  
  314.     }
  315.  
  316.     public void setLastDamager(Player p) {
  317.  
  318.     this.lastDamager = p;
  319.  
  320.     }
  321.  
  322.     public AbstractGUI getCurrentGui() {
  323.  
  324.     return this.currentGui;
  325.  
  326.     }
  327.  
  328.     public void setCurrentGui(AbstractGUI currentGui) {
  329.  
  330.     this.currentGui = currentGui;
  331.  
  332.     }
  333.  
  334.     public void setIn1v1(boolean mode) {
  335.  
  336.     this.in1v1 = mode;
  337.  
  338.     }
  339.  
  340.     public boolean isIn1v1() {
  341.  
  342.     return this.in1v1;
  343.  
  344.     }
  345.  
  346.     public void setDisguised(Boolean mode) {
  347.  
  348.     this.disguised = mode;
  349.  
  350.     }
  351.  
  352.     public Boolean isDisguised() {
  353.  
  354.     return this.disguised;
  355.  
  356.     }
  357.  
  358.     public void setIngame(boolean mode) {
  359.  
  360.     this.ingame = mode;
  361.  
  362.     }
  363.  
  364.     public boolean isIngame() {
  365.  
  366.     return this.ingame;
  367.     }
  368.  
  369.     public void setAdminmode(Boolean mode) {
  370.  
  371.     this.adminmode = mode;
  372.  
  373.     }
  374.  
  375.     public Boolean isInAdminmode() {
  376.  
  377.     return this.adminmode;
  378.  
  379.     }
  380.  
  381.     public void setFrozen(Boolean mode) {
  382.  
  383.     this.frozen = mode;
  384.  
  385.     }
  386.  
  387.     public Boolean isFrozen() {
  388.  
  389.     return this.frozen;
  390.  
  391.     }
  392.  
  393.     public Player getPlayer() {
  394.  
  395.     return this.player;
  396.  
  397.     }
  398.  
  399.     public void setFrozenLocation(Location loc) {
  400.  
  401.     this.frozenloc = loc;
  402.  
  403.     }
  404.  
  405.     public Location getFrozenLocation() {
  406.  
  407.     return this.frozenloc;
  408.  
  409.     }
  410.  
  411.     public Team getTeaminvitation() {
  412.     return teaminvitation;
  413.     }
  414.  
  415.     public void setTeaminvitation(Team teaminvitation) {
  416.     this.teaminvitation = teaminvitation;
  417.     }
  418.  
  419.     public void sendHoverableMessage(String msg, String hovermsg, String command) {
  420.  
  421.     TextComponent tc = new TextComponent();
  422.     tc.setText(msg);
  423.     if (command != null)
  424.         tc.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/" + command));
  425.  
  426.     tc.setHoverEvent(new HoverEvent(
  427.         net.md_5.bungee.api.chat.HoverEvent.Action.SHOW_TEXT,
  428.         new ComponentBuilder(hovermsg).create()));
  429.  
  430.     getPlayer().spigot().sendMessage(tc);
  431.  
  432.     }
  433.  
  434.     public TextComponent createComponent(String msg, String hovermsg,
  435.         String command) {
  436.  
  437.     TextComponent tc = new TextComponent();
  438.     tc.setText(msg);
  439.     if (command != null)
  440.         tc.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/" + command));
  441.  
  442.     tc.setHoverEvent(new HoverEvent(
  443.         net.md_5.bungee.api.chat.HoverEvent.Action.SHOW_TEXT,
  444.         new ComponentBuilder(hovermsg).create()));
  445.  
  446.     return tc;
  447.  
  448.     }
  449.  
  450.     public boolean isChest() {
  451.     return chest;
  452.     }
  453.  
  454.     public void setChest(boolean chest) {
  455.     this.chest = chest;
  456.     }
  457.  
  458.     public void spawn() {
  459.  
  460.     FileConfiguration config = HospitalCore.getInstance().getConfig();
  461.  
  462.     Location spawn = new Location(Bukkit.getWorlds().get(0),
  463.         config.getDouble("spawn.x"), config.getDouble("spawn.y") + 1,
  464.         config.getDouble("spawn.z"));
  465.     player.teleport(spawn);
  466.  
  467.     if (isInAdminmode())
  468.         player.performCommand("admin");
  469.  
  470.     ItemStack a = GabikAPI.createItem(Material.COMPASS, "§4Warps");
  471.     ItemStack b = GabikAPI.createItem(Material.ENCHANTMENT_TABLE, "§4Shop");
  472.  
  473.     this.setIngame(false);
  474.     this.setIn1v1(false);
  475.     this.setInChallenge(false);
  476.     this.setKit(Kit.NONE);
  477.     this.setCurrentArena(-1);
  478.     this.setHg(false);
  479.  
  480.     for (PlayerData all : PlayerData.list)
  481.         if (all.getLastDamaged() != null
  482.             && all.getLastDamaged().equals(player))
  483.         all.setLastDamaged(null);
  484.  
  485.     setWalkSpeed(0.2F);
  486.  
  487.     if (!player.isDead())
  488.         player.setHealth(20D);
  489.  
  490.     for (PotionEffect effect : player.getActivePotionEffects())
  491.         player.removePotionEffect(effect.getType());
  492.  
  493.     player.getInventory().clear();
  494.     player.getInventory().setArmorContents(null);
  495.  
  496.     player.getInventory().setItem(3, a);
  497.     player.getInventory().setItem(5, b);
  498.  
  499.     }
  500.  
  501.     public boolean isFakekits() {
  502.     return fakekits;
  503.     }
  504.  
  505.     public void setFakekits(boolean fakekits) {
  506.     this.fakekits = fakekits;
  507.     }
  508.  
  509.     public boolean isHg() {
  510.     return hg;
  511.     }
  512.  
  513.     public void setHg(boolean hg) {
  514.     this.hg = hg;
  515.     }
  516.  
  517. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement