Permalink
Browse files

9.0.0: new ActionBar

  • Loading branch information...
Sablednah committed Apr 19, 2015
1 parent 89b86c6 commit a8d908f5cc0a5f6b9cda1f6fa31d2b8cf2804752
View
12 pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>MobHealth</groupId>
<artifactId>MobHealth</artifactId>
<version>8.3.0</version>
<version>9.0.0</version>
<name>MobHealth</name>
<url>dev.bukkit.org/bukkit-plugins/mobhealth/</url>
<description>Minecraft Bukkit Sever Plugin to display Mobs health when damaged.</description>
@@ -40,12 +40,12 @@
<version>1.8-R0.1-SNAPSHOT</version>
</dependency> -->
<!--Bukkit API-->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8-R0.1-SNAPSHOT</version>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.8.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.spoutcraft</groupId>
<artifactId>spoutcraftplugin</artifactId>
@@ -0,0 +1,7 @@
package main.java.me.sablednah.MobHealth.API;
import org.bukkit.entity.Player;
public interface ActionBar {
public abstract boolean sendActionBar(String text, Player player);
}
@@ -0,0 +1,19 @@
package main.java.me.sablednah.MobHealth.API;
import net.minecraft.server.v1_8_R1.ChatSerializer;
import net.minecraft.server.v1_8_R1.IChatBaseComponent;
import net.minecraft.server.v1_8_R1.PacketPlayOutChat;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class ActionBar_1_8_1 implements ActionBar {
public boolean sendActionBar(String text, Player player) {
String output = "{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', text) + "\"}";
IChatBaseComponent baseChat = ChatSerializer.a(output);
PacketPlayOutChat actionbarPacket = new PacketPlayOutChat(baseChat, (byte) 2);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(actionbarPacket);
return true;
}
}
@@ -0,0 +1,18 @@
package main.java.me.sablednah.MobHealth.API;
import net.minecraft.server.v1_8_R2.IChatBaseComponent;
import net.minecraft.server.v1_8_R2.PacketPlayOutChat;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class ActionBar_1_8_3 implements ActionBar {
public boolean sendActionBar(String text, Player player) {
String output = "{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', text) + "\"}";
IChatBaseComponent baseChat = IChatBaseComponent.ChatSerializer.a(output);
PacketPlayOutChat actionbarPacket = new PacketPlayOutChat(baseChat, (byte) 2);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(actionbarPacket);
return true;
}
}
@@ -207,45 +207,49 @@ public void showNotification(Player player, String damageOutput, String mobtype,
if (spoutUsed) {
MobHealth.notifications++;
}
boolean useSimpleNotice = player.getListeningPluginChannels().contains("SimpleNotice");
if (!spoutUsed && (!MobHealth.disableChat || useSimpleNotice)) {
String ChatMessage;
if (!spoutUsed && (!MobHealth.disableChat || useSimpleNotice || MobHealth.useActionBar)) {
String chatMessage;
if (damagerMob instanceof Egg && (!(MobHealth.chatMessageEgg == null))) {
ChatMessage = MobHealth.chatMessageEgg;
chatMessage = MobHealth.chatMessageEgg;
} else if (damagerMob instanceof Snowball && (!(MobHealth.chatMessageSnowball == null))) {
ChatMessage = MobHealth.chatMessageSnowball;
chatMessage = MobHealth.chatMessageSnowball;
} else {
if (mobsHealth < 1) { // was "targetMob.isDead()"
if (skillName == null) {
ChatMessage = MobHealth.chatKilledMessage;
chatMessage = MobHealth.chatKilledMessage;
} else {
ChatMessage = MobHealth.heroesSkillChatKilledMessage;
ChatMessage = ChatMessage.replaceAll("%S", skillName);
chatMessage = MobHealth.heroesSkillChatKilledMessage;
chatMessage = chatMessage.replaceAll("%S", skillName);
}
} else {
if (skillName == null) {
ChatMessage = MobHealth.chatMessage;
chatMessage = MobHealth.chatMessage;
} else {
ChatMessage = MobHealth.heroesSkillChatMessage;
ChatMessage = ChatMessage.replaceAll("%S", skillName);
chatMessage = MobHealth.heroesSkillChatMessage;
chatMessage = chatMessage.replaceAll("%S", skillName);
}
if ((mobsHealth < 2) || (mobsHealth <= (mobsMaxHealth / 4))) {
ChatMessage = ChatMessage.replaceAll("%H", (ChatColor.DARK_RED) + Integer.toString(mobsHealth) + (ChatColor.WHITE));
chatMessage = chatMessage.replaceAll("%H", (ChatColor.DARK_RED) + Integer.toString(mobsHealth) + (ChatColor.WHITE));
} else {
ChatMessage = ChatMessage.replaceAll("%H", Integer.toString(mobsHealth));
chatMessage = chatMessage.replaceAll("%H", Integer.toString(mobsHealth));
}
}
}
ChatMessage = ChatMessage.replaceAll("%D", damageOutput);
ChatMessage = ChatMessage.replaceAll("%N", mobtype);
ChatMessage = ChatMessage.replaceAll("%M", Integer.toString(mobsMaxHealth));
ChatMessage = ChatColor.translateAlternateColorCodes('&', ChatMessage);
chatMessage = chatMessage.replaceAll("%D", damageOutput);
chatMessage = chatMessage.replaceAll("%N", mobtype);
chatMessage = chatMessage.replaceAll("%M", Integer.toString(mobsMaxHealth));
chatMessage = ChatColor.translateAlternateColorCodes('&', chatMessage);
if (useSimpleNotice) {
player.sendPluginMessage(plugin, "SimpleNotice", ChatMessage.getBytes(java.nio.charset.Charset.forName("UTF-8")));
player.sendPluginMessage(plugin, "SimpleNotice", chatMessage.getBytes(java.nio.charset.Charset.forName("UTF-8")));
} else {
player.sendMessage(ChatMessage);
if (MobHealth.useActionBar && plugin.actionBar!= null) {
plugin.actionBar.sendActionBar(chatMessage, player);
} else {
player.sendMessage(chatMessage);
}
}
MobHealth.notifications++;
}
@@ -35,6 +35,9 @@
import main.java.me.sablednah.MobHealth.Metrics.Graph;
import main.java.me.sablednah.MobHealth.Updater.UpdateType;
import main.java.me.sablednah.MobHealth.API.ActionBar;
import main.java.me.sablednah.MobHealth.API.ActionBar_1_8_1;
import main.java.me.sablednah.MobHealth.API.ActionBar_1_8_3;
import main.java.me.sablednah.MobHealth.API.MobHealthAPI;
import org.bukkit.ChatColor;
@@ -133,8 +136,8 @@
public static Map<UUID, Widget> hesGotASideIcon = new HashMap<UUID, Widget>();
public static String[] animalList = { "Rabbit", "Donkey", "Mule", "Horse", "Bat", "Pig", "Sheep", "Cow", "Chicken", "MushroomCow", "Golem", "IronGolem", "Snowman", "Squid", "Villager", "Wolf", "Ocelot" };
public static String[] monsterList = { "Endermite", "Guardian", "Witch", "Wither", "Blaze", "Zombie", "ZombieVillagerBaby", "ZombieVillager", "ZombieBaby", "Creeper", "Skeleton", "SkeletonWither", "Spider", "Ghast", "MagmaCube", "Slime",
"CaveSpider", "EnderDragon", "Enderman", "Giant", "PigZombie", "Silverfish", "Spider" };
public static String[] monsterList = { "Endermite", "Guardian", "Witch", "Wither", "Blaze", "Zombie", "ZombieVillagerBaby", "ZombieVillager", "ZombieBaby", "Creeper", "Skeleton", "SkeletonWither", "Spider", "Ghast",
"MagmaCube", "Slime", "CaveSpider", "EnderDragon", "Enderman", "Giant", "PigZombie", "Silverfish", "Spider" };
public String[] entityList = concat(animalList, monsterList);
@@ -152,6 +155,9 @@
public static SetHealth setHealths = null;
public static Boolean useActionBar = true;
public ActionBar actionBar = null;
@Override
public void onDisable() {
this.getServer().getScheduler().cancelTasks(this);
@@ -263,6 +269,11 @@ public void onEnable() {
showMobHeadHealth = false;
}
}
if (plugin.getServer().getClass().getPackage().getName().substring(23).equalsIgnoreCase("v1_8_R2")) {
actionBar = new ActionBar_1_8_3();
} else if (plugin.getServer().getClass().getPackage().getName().substring(23).equalsIgnoreCase("v1_8_R1")) {
actionBar = new ActionBar_1_8_1();
}
// Enable Metrics
try {
@@ -417,6 +428,8 @@ public void loadConfiguration() {
debugMode = getConfig().getBoolean("debugMode");
useActionBar = getConfig().getBoolean("useActionBar");
saveConfig();
getLangConfig();
@@ -730,6 +743,7 @@ public static void setMetaCustomName(Metadatable object, String name) {
public InputStream getResourcePublic(String string) {
return getResource(string);
}
public Reader getTextResourcePublic(String string) {
return getTextResource(string);
}
@@ -60,3 +60,4 @@ updateCheck: true
doUpdate: true
debugMode: false
useActionBar: true

0 comments on commit a8d908f

Please sign in to comment.