/ Published in: Java
MyCharacter.java class
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
package me.NonameSL.CharacterLibrary; import java.util.HashMap; import java.util.HashSet; import java.util.Map.Entry; import java.util.Set; import org.bukkit.Bukkit; import org.bukkit.entity.Player; public class MyCharacter { private int maxhealth; public static HashMap<MyCharacter, Set<Player>> playersWithCharacters = new HashMap<>(); private HashMap<ActionTrigger, CharacterAction> skills = new HashMap<>(); this(name, maxhealth, new HashMap<ActionTrigger, CharacterAction>()); } public MyCharacter(int maxhealth) { this("", maxhealth); } public MyCharacter(int maxhealth, HashMap<ActionTrigger, CharacterAction> skills) { this("", maxhealth, skills); } this.name=name; this.maxhealth = maxhealth; this.skills = skills; if (!playersWithCharacters.containsKey(this)) playersWithCharacters.put(this, new HashSet<Player>()); } { return this.name; } this.name = name; } /** * * @return a clone of the skills map */ public HashMap<ActionTrigger, CharacterAction> getSkills() { return new HashMap<ActionTrigger, CharacterAction>(this.skills); } public void setSkill(ActionTrigger at, CharacterAction ca) { if (this.skills.containsKey(at)) removeSkill(at); addSkill(ca, at); } public void addSkill(CharacterAction ca, ActionTrigger at) { if (this.skills.containsKey(at)) { Bukkit.getServer().getConsoleSender().sendMessage("§2[§1CharacterLibrary§r§2]§4§uERROR:§r§4 Tried to add skill with " + at.toString().replace("_", " ").toLowerCase() + "tigger but character alraedy has one!"); return; } this.skills.put(at, ca); } public void removeSkill(ActionTrigger at) { if (this.skills.containsKey(at)) this.skills.remove(at); } public boolean removeSkillsFor(ActionTrigger at) { boolean breturn = false; for (Entry<?, ?> entry : this.skills.entrySet()) { if (at.equals(entry.getValue())) { this.skills.remove(entry.getKey()); breturn = true; } } return breturn; } public int getMaxHealth() { return this.maxhealth; } public void setMaxHealth(int maxhealth) { this.maxhealth = maxhealth; } public static enum ActionTrigger { LEFT_CLICK_BLOCK, RIGHT_CLICK_BLOCK, LEFT_CLICK_AIR, RIGHT_CLICK_AIR, SPRINT, SPLASH_POTION_EFFECT, CROUCH, HIT_BY_ENTITY, HIT_ENTITY, ITEM_DROP, EGG_THROW, DEATH; } }