From 7ad9b2ed58509039576d58eaff4f8bb3913848e4 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sat, 25 Feb 2012 03:51:22 -0800 Subject: [PATCH] Gutting out the old Party HUD. Lets make a new one. --- .../nossr50/listeners/mcPlayerListener.java | 3 - .../java/com/gmail/nossr50/party/Party.java | 17 -- .../com/gmail/nossr50/spout/mmoHelper.java | 269 ------------------ .../nossr50/spout/util/ArrayListString.java | 112 -------- .../gmail/nossr50/spout/util/GenericFace.java | 65 ----- .../spout/util/GenericLivingEntity.java | 227 --------------- 6 files changed, 693 deletions(-) delete mode 100644 src/main/java/com/gmail/nossr50/spout/mmoHelper.java delete mode 100644 src/main/java/com/gmail/nossr50/spout/util/ArrayListString.java delete mode 100644 src/main/java/com/gmail/nossr50/spout/util/GenericFace.java delete mode 100644 src/main/java/com/gmail/nossr50/spout/util/GenericLivingEntity.java diff --git a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java index 1e5910aa3..21224de7c 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java @@ -60,7 +60,6 @@ import com.gmail.nossr50.commands.general.XprateCommand; import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.runnables.RemoveProfileFromMemoryTask; import com.gmail.nossr50.spout.SpoutStuff; -import com.gmail.nossr50.spout.mmoHelper; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.locale.mcLocale; @@ -182,8 +181,6 @@ public class mcPlayerListener implements Listener { if(SpoutStuff.playerHUDs.containsKey(player)) SpoutStuff.playerHUDs.remove(player); - if(mmoHelper.containers.containsKey(player)) - mmoHelper.containers.remove(player); } //Bleed it out diff --git a/src/main/java/com/gmail/nossr50/party/Party.java b/src/main/java/com/gmail/nossr50/party/Party.java index b81edab69..a5b37e135 100644 --- a/src/main/java/com/gmail/nossr50/party/Party.java +++ b/src/main/java/com/gmail/nossr50/party/Party.java @@ -34,7 +34,6 @@ import com.gmail.nossr50.Users; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.mcLocale; -import com.gmail.nossr50.spout.util.ArrayListString; public class Party @@ -145,22 +144,6 @@ public class Party } return players; } - public ArrayListString getPartyMembersByName(Player player) - { - ArrayListString players = new ArrayListString(); - - for(Player p : Bukkit.getServer().getOnlinePlayers()) - { - if(p.isOnline()) - { - if(inSameParty(player, p)) - { - players.add(p.getName()); - } - } - } - return players; - } public void informPartyMembersOwnerChange(String newOwner) { Player newOwnerPlayer = plugin.getServer().getPlayer(newOwner); diff --git a/src/main/java/com/gmail/nossr50/spout/mmoHelper.java b/src/main/java/com/gmail/nossr50/spout/mmoHelper.java deleted file mode 100644 index ee9667c63..000000000 --- a/src/main/java/com/gmail/nossr50/spout/mmoHelper.java +++ /dev/null @@ -1,269 +0,0 @@ -/* - * This file is from mmoMinecraft (http://code.google.com/p/mmo-minecraft/). - * - * mmoMinecraft is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.gmail.nossr50.spout; - -import java.util.ArrayList; -import java.util.HashMap; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.World; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Tameable; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; -import org.bukkit.entity.*; -import org.getspout.spoutapi.gui.Container; -import org.getspout.spoutapi.gui.GenericContainer; -import org.getspout.spoutapi.gui.Widget; -import org.getspout.spoutapi.gui.WidgetAnchor; -import org.getspout.spoutapi.player.SpoutPlayer; - -import com.gmail.nossr50.Users; -import com.gmail.nossr50.config.LoadProperties; -import com.gmail.nossr50.party.Party; -import com.gmail.nossr50.spout.util.GenericLivingEntity; - -public class mmoHelper -{ - - /** - * A map of player containers, each container is their party bar - */ - public static HashMap containers = new HashMap(); - - /** - * Get the percentage health of a Player. - * @param player The Player we're interested in - * @return The percentage of max health - */ - public static int getHealth(Entity player) { - if (player != null && player instanceof LivingEntity) { - try { - return Math.min(((LivingEntity) player).getHealth() * 5, 100); - } catch (Exception e) { - } - } - return 0; - } - - /** - * Get the colour of a LivingEntity target from a player's point of view. - * @param player The player viewing the target - * @param target The target to name - * @return The name to use - */ - public static String getColor(Player player, LivingEntity target) { - if (target instanceof Player) { - if (((Player) target).isOp()) { - return ChatColor.GOLD.toString(); - } - return ChatColor.YELLOW.toString(); - } else { - if (target instanceof Monster) { - if (player != null && player.equals(((Monster) target).getTarget())) { - return ChatColor.RED.toString(); - } else { - return ChatColor.YELLOW.toString(); - } - } else if (target instanceof WaterMob) { - return ChatColor.GREEN.toString(); - } else if (target instanceof Flying) { - return ChatColor.YELLOW.toString(); - } else if (target instanceof Animals) { - if (player != null && player.equals(((Animals) target).getTarget())) { - return ChatColor.RED.toString(); - } else if (target instanceof Tameable) { - Tameable pet = (Tameable) target; - if (pet.isTamed()) { - return ChatColor.GREEN.toString(); - } else { - return ChatColor.YELLOW.toString(); - } - } else { - return ChatColor.GRAY.toString(); - } - } else { - return ChatColor.GRAY.toString(); - } - } - } - - /** - * Get the percentage armour of a Player. - * @param player The Player we're interested in - * @return The percentage of max armour - */ - public static int getArmor(Entity player) { - if (player != null && player instanceof Player) { - int armor = 0, max, multi[] = {15, 30, 40, 15}; - ItemStack inv[] = ((Player) player).getInventory().getArmorContents(); - for (int i = 0; i < inv.length; i++) { - max = inv[i].getType().getMaxDurability(); - if (max >= 0) { - armor += multi[i] * (max - inv[i].getDurability()) / max; - } - } - return armor; - } - return 0; - } - - public static String getSimpleName(LivingEntity target, boolean showOwner) { - String name = ""; - if (target instanceof Player) { - if (LoadProperties.showDisplayName) { - name += ((Player) target).getName(); - } else { - name += ((Player) target).getDisplayName(); - } - } else if (target instanceof HumanEntity) { - name += ((HumanEntity) target).getName(); - } else { - if (target instanceof Tameable) { - if (((Tameable) target).isTamed()) { - if (showOwner && ((Tameable) target).getOwner() instanceof Player) { - if (LoadProperties.showDisplayName) { - name += ((Player) ((Tameable) target).getOwner()).getName() + "'s "; - } else { - name += ((Player) ((Tameable) target).getOwner()).getDisplayName() + "'s "; - } - } else { - name += "Pet "; - } - } - } - if (target instanceof Chicken) { - name += "Chicken"; - } else if (target instanceof Cow) { - name += "Cow"; - } else if (target instanceof Creeper) { - name += "Creeper"; - } else if (target instanceof Ghast) { - name += "Ghast"; - } else if (target instanceof Giant) { - name += "Giant"; - } else if (target instanceof Pig) { - name += "Pig"; - } else if (target instanceof PigZombie) { - name += "PigZombie"; - } else if (target instanceof Sheep) { - name += "Sheep"; - } else if (target instanceof Slime) { - name += "Slime"; - } else if (target instanceof Skeleton) { - name += "Skeleton"; - } else if (target instanceof Spider) { - name += "Spider"; - } else if (target instanceof Squid) { - name += "Squid"; - } else if (target instanceof Wolf) { - name += "Wolf"; - } else if (target instanceof Zombie) { - name += "Zombie"; - } else if (target instanceof Monster) { - name += "Monster"; - } else if (target instanceof Creature) { - name += "Creature"; - } else { - name += "Unknown"; - } - } - return name; - } - - public static LivingEntity[] getPets(HumanEntity player) { - ArrayList pets = new ArrayList(); - if (player != null && (!(player instanceof Player) || ((Player) player).isOnline())) { - String name = player.getName(); - for (World world : Bukkit.getServer().getWorlds()) { - for (LivingEntity entity : world.getLivingEntities()) { - if (entity instanceof Tameable && ((Tameable) entity).isTamed() && ((Tameable) entity).getOwner() instanceof Player) { - if (name.equals(((Player) ((Tameable) entity).getOwner()).getName())) { - pets.add(entity); - } - } - } - } - } - LivingEntity[] list = new LivingEntity[pets.size()]; - pets.toArray(list); - return list; - } - - public static void update(Player player) - { - //boolean show_pets = true; - Container container = containers.get(player); - - if (container != null) - { - int index = 0; - Widget[] bars = container.getChildren(); - for (String name : Party.getInstance().getPartyMembersByName(player).meFirst(player.getName())) - { - GenericLivingEntity bar; - if (index >= bars.length) - { - container.addChild(bar = new GenericLivingEntity()); - } else { - bar = (GenericLivingEntity)bars[index]; - } - bar.setEntity(name, Party.getInstance().isPartyLeader(name, Users.getProfile(Bukkit.getServer().getPlayer(name)).getParty()) ? ChatColor.GREEN + "@" : ""); - //bar.setTargets(show_pets ? getPets(Bukkit.getServer().getPlayer(name)) : null); - index++; - } - while (index < bars.length) { - container.removeChild(bars[index++]); - } - container.updateLayout(); - } - } - - public static void initialize(SpoutPlayer sPlayer, Plugin plugin) - { - GenericContainer container = new GenericContainer(); - - container.setAlign(WidgetAnchor.TOP_LEFT) - .setAnchor(WidgetAnchor.TOP_LEFT) - .setX(3) - .setY(3) - .setWidth(427) - .setHeight(240) - .setFixed(true); - - mmoHelper.containers.put(sPlayer, container); - - sPlayer.getMainScreen().attachWidget(plugin, container); - } - /** - * Update all parties. - */ - public static void updateAll() { - for(Player x : Bukkit.getServer().getOnlinePlayers()) - { - if(Users.getProfile(x).inParty()) - { - update(x); - } - } - } - -} diff --git a/src/main/java/com/gmail/nossr50/spout/util/ArrayListString.java b/src/main/java/com/gmail/nossr50/spout/util/ArrayListString.java deleted file mode 100644 index 53a52f353..000000000 --- a/src/main/java/com/gmail/nossr50/spout/util/ArrayListString.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * This file is part of mmoMinecraft (http://code.google.com/p/mmo-minecraft/). - * - * mmoMinecraft is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.gmail.nossr50.spout.util; - -import java.util.ArrayList; - -/** - * Case insensitive ArrayList. - * Overrides the .contains(), .indexOf(), .lastIndexOf() and .remove() methods. - */ -public class ArrayListString extends ArrayList { - - private static final long serialVersionUID = -8111006526598412404L; - - /** - * Returns true if this list contains the specified string. - * @param o String whose presence in this list is to be tested - * @return true if this list contains the specified string - */ - public boolean contains(String o) { - for (String e : this) { - if (o == null ? e == null : o.equalsIgnoreCase(e)) { - return true; - } - } - return false; - } - - /** - * Returns the index of the first occurrence of the specified string in this list, or -1 if this list does not contain the string. - * @param o String to search for - * @return The index of the first occurrence of the specified string in this list, or -1 if this list does not contain the string - */ - public int indexOf(String o) { - for (int i = 0; i < this.size(); i++) { - if (o == null ? get(i) == null : o.equalsIgnoreCase(get(i))) { - return i; - } - } - return -1; - } - - /** - * Returns the index of the last occurrence of the specified string in this list, or -1 if this list does not contain the string. - * @param o String to search for - * @return The index of the last occurrence of the specified string in this list, or -1 if this list does not contain the string - */ - public int lastIndexOf(String o) { - for (int i = size() - 1; i >= 0; i--) { - if (o == null ? get(i) == null : o.equalsIgnoreCase(get(i))) { - return i; - } - } - return -1; - } - - /** - * Removes the first occurrence of the specified string from this list, if it is present. If the list does not contain the string, it is unchanged. - * @param o String to be removed from this list, if present - * @return true if this list contained the specified string - */ - public boolean remove(String o) { - int i = indexOf(o); - if (i != -1) { - remove(i); - return true; - } - return false; - } - - /** - * Returns the element at the specified position in this list. - * This is for finding the correct capitalisation of an element. - * @param index String to search for - * @return the correctly capitalised element - */ - public String get(String index) { - int i = this.indexOf(index); - if (i != -1) { - return this.get(i); - } - return null; - } - - public ArrayListString meFirst(String name) { - ArrayListString copy = new ArrayListString(); - if (this.contains(name)) { - copy.add(name); - } - for (String next : this) { - if (!next.equalsIgnoreCase(name)) { - copy.add(next); - } - } - return copy; - } -} \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/spout/util/GenericFace.java b/src/main/java/com/gmail/nossr50/spout/util/GenericFace.java deleted file mode 100644 index e061604ae..000000000 --- a/src/main/java/com/gmail/nossr50/spout/util/GenericFace.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file is part of mmoMinecraft (https://github.com/mmoMinecraftDev). - * - * mmoMinecraft is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.gmail.nossr50.spout.util; - -import org.getspout.spoutapi.gui.GenericTexture; - -import com.gmail.nossr50.config.LoadProperties; - -public final class GenericFace extends GenericTexture { - - private static String facePath = "http://face.rycochet.net/"; - private static int defaultSize = 8; - private String name; - - public GenericFace() { - this("", defaultSize); - } - - public GenericFace(String name) { - this(name, defaultSize); - } - - public GenericFace(String name, int size) { - if (LoadProperties.showFaces) { - this.setWidth(size).setHeight(size).setFixed(true); - setName(name); - } else { - this.setVisible(false); - } - } - - public String getName() { - return name; - } - - public GenericFace setName(String name) { - if (LoadProperties.showFaces) { - this.name = name == null ? "" : name; - super.setUrl(facePath + this.name + ".png"); - super.setDirty(true); - } - return this; - } - - public GenericFace setSize(int size) { - if (LoadProperties.showFaces) { - super.setWidth(size).setHeight(size); - } - return this; - } -} \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/spout/util/GenericLivingEntity.java b/src/main/java/com/gmail/nossr50/spout/util/GenericLivingEntity.java deleted file mode 100644 index 0594bee02..000000000 --- a/src/main/java/com/gmail/nossr50/spout/util/GenericLivingEntity.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * This file is part of mmoHelperMinecraft (https://github.com/mmoHelperMinecraftDev). - * - * mmoHelperMinecraft is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.gmail.nossr50.spout.util; - -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.getspout.spoutapi.gui.*; - -import com.gmail.nossr50.spout.mmoHelper; - -public class GenericLivingEntity extends GenericContainer { - - private Container _space; - private Label _label; - private Gradient _health; - private Gradient _armor; - private GenericFace _face; - private int health = 100; - private int armor = 100; - private int def_width = 80; - private int def_height = 14; - private boolean target = false; - String face = "~"; - String label = ""; - - public GenericLivingEntity() { - super(); - Color black = new Color(0, 0, 0, 0.75f); - - this.addChildren( - new GenericContainer( // Used for the bar, this.children with an index 1+ are targets - _space = (Container) new GenericContainer() - .setMinWidth(def_width / 4) - .setMaxWidth(def_width / 4) - .setVisible(target), - new GenericContainer( - new GenericGradient() - .setTopColor(black) - .setBottomColor(black) - .setPriority(RenderPriority.Highest), - new GenericContainer( - _health = (Gradient) new GenericGradient(), - _armor = (Gradient) new GenericGradient() - ) .setMargin(1) - .setPriority(RenderPriority.High), - new GenericContainer( - _face = (GenericFace) new GenericFace() - .setMargin(3, 0, 3, 3), - _label = (Label) new GenericLabel() - .setMargin(3) - ) .setLayout(ContainerType.HORIZONTAL) - ) .setLayout(ContainerType.OVERLAY) - ) .setLayout(ContainerType.HORIZONTAL) - .setMargin(0, 0, 1, 0) - .setFixed(true) - .setWidth(def_width) - .setHeight(def_height) - ) .setAlign(WidgetAnchor.TOP_LEFT) - .setFixed(true) - .setWidth(def_width) - .setHeight(def_height + 1); - - this.setHealthColor(new Color(1f, 0, 0, 0.75f)); - this.setArmorColor(new Color(0.75f, 0.75f, 0.75f, 0.75f)); - } - - /** - * Set the display from a possibly offline player - * @param name - * @return - */ - public GenericLivingEntity setEntity(String name) { - return setEntity(name, ""); - } - - /** - * Set the display from a possibly offline player - * @param name - * @param prefix Place before the name - * @return - */ - public GenericLivingEntity setEntity(String name, String prefix) { - Player player = this.getPlugin().getServer().getPlayer(name); - if (player != null && player.isOnline()) { - return setEntity(player, prefix); - } - setHealth(0); - setArmor(0); - setLabel((!"".equals(prefix) ? prefix : "") + mmoHelper.getColor(screen != null ? screen.getPlayer() : null, null) + name); - setFace("~" + name); - return this; - } - - /** - * Set the display from a player or living entity - * @param entity - * @return - */ - public GenericLivingEntity setEntity(LivingEntity entity) { - return setEntity(entity, ""); - } - - /** - * Set the display from a player or living entity - * @param entity - * @param prefix Place before the name - * @return - */ - public GenericLivingEntity setEntity(LivingEntity entity, String prefix) { - if (entity != null && entity instanceof LivingEntity) { - setHealth(mmoHelper.getHealth(entity)); // Needs a maxHealth() check - setArmor(mmoHelper.getArmor(entity)); - setLabel((!"".equals(prefix) ? prefix : "") + mmoHelper.getColor(screen != null ? screen.getPlayer() : null, entity) + mmoHelper.getSimpleName(entity, !target)); - setFace(entity instanceof Player ? ((Player)entity).getName() : "+" + mmoHelper.getSimpleName(entity,false).replaceAll(" ", "")); - } else { - setHealth(0); - setArmor(0); - setLabel(""); - setFace(""); - } - return this; - } - - /** - * Set the targets of this entity - either actual targets, or pets etc - * @param targets - * @return - */ - public GenericLivingEntity setTargets(LivingEntity... targets) { - Widget[] widgets = this.getChildren(); - if (targets == null) { - targets = new LivingEntity[0]; // zero-length array is easier to handle - } - for (int i=targets.length + 1; i i + 1) { - child = (GenericLivingEntity) widgets[i+1]; - } else { - this.addChild(child = new GenericLivingEntity()); - } - child.setTarget(true); - child.setEntity(targets[i]); - } - setHeight((targets.length + 1) * (def_height + 1)); - updateLayout(); - return this; - } - - public GenericLivingEntity setTarget(boolean target) { - if (this.target != target) { - this.target = target; - _space.setVisible(target); - updateLayout(); - } - return this; - } - - public GenericLivingEntity setHealth(int health) { - if (this.health != health) { - this.health = health; - updateLayout(); - } - return this; - } - - public GenericLivingEntity setHealthColor(Color color) { - _health.setTopColor(color).setBottomColor(color); - return this; - } - - public GenericLivingEntity setArmor(int armor) { - if (this.armor != armor) { - this.armor = armor; - updateLayout(); - } - return this; - } - - public GenericLivingEntity setArmorColor(Color color) { - _armor.setTopColor(color).setBottomColor(color); - return this; - } - - public GenericLivingEntity setLabel(String label) { - if (!this.label.equals(label)) { - this.label = label; - _label.setText(label).setDirty(true); - updateLayout(); - } - return this; - } - - public GenericLivingEntity setFace(String name) { - if (!this.face.equals(name)) { - this.face = name; - _face.setVisible(!name.isEmpty()); - _face.setName(name); - updateLayout(); - } - return this; - } - - @Override - public Container updateLayout() { - super.updateLayout(); - _armor.setWidth((_armor.getContainer().getWidth() * armor) / 100).setDirty(true); - _health.setWidth((_health.getContainer().getWidth() * health) / 100).setDirty(true); - return this; - } -} \ No newline at end of file