diff --git a/libs/LibsDisguises.jar b/libs/LibsDisguises.jar
new file mode 100644
index 0000000..a8ac05d
Binary files /dev/null and b/libs/LibsDisguises.jar differ
diff --git a/pom.xml b/pom.xml
index c5174fa..397ae50 100644
--- a/pom.xml
+++ b/pom.xml
@@ -18,6 +18,10 @@
dmulloy2-repo
http://repo.dmulloy2.net/content/groups/public/
+
+ md_5-public
+ http://repo.md-5.net/content/groups/public/
+
@@ -41,10 +45,11 @@
${project.basedir}/libs/PaperSpigot-1.8.8-R0.1-SNAPSHOT-latest.jar
- com.comphenix.protocol
- ProtocolLib
- 3.6.5
- provided
+ LibsDisguises
+ LibsDisguises
+ 9.0.7
+ system
+ ${project.basedir}/libs/LibsDisguises.jar
diff --git a/src/main/java/com/leontg77/villagermobs/Main.java b/src/main/java/com/leontg77/villagermobs/Main.java
index 56a9477..466cc4e 100644
--- a/src/main/java/com/leontg77/villagermobs/Main.java
+++ b/src/main/java/com/leontg77/villagermobs/Main.java
@@ -28,7 +28,9 @@
package com.leontg77.villagermobs;
import com.leontg77.villagermobs.commands.VillagerMobsCommand;
-import com.leontg77.villagermobs.protocol.MobDisguiseAdapter;
+import com.leontg77.villagermobs.listeners.MobListener;
+import me.libraryaddict.disguise.disguisetypes.DisguiseType;
+import me.libraryaddict.disguise.disguisetypes.MobDisguise;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
@@ -43,8 +45,10 @@ public class Main extends JavaPlugin {
@Override
public void onEnable() {
- MobDisguiseAdapter disguise = new MobDisguiseAdapter(this);
- VillagerMobsCommand cmd = new VillagerMobsCommand(this, disguise);
+ MobDisguise mobDisguise = new MobDisguise(DisguiseType.VILLAGER, true, true);
+
+ MobListener listener = new MobListener(mobDisguise);
+ VillagerMobsCommand cmd = new VillagerMobsCommand(this, listener, mobDisguise);
// register command.
getCommand("villagermobs").setExecutor(cmd);
diff --git a/src/main/java/com/leontg77/villagermobs/commands/VillagerMobsCommand.java b/src/main/java/com/leontg77/villagermobs/commands/VillagerMobsCommand.java
index d4ab27a..1382511 100644
--- a/src/main/java/com/leontg77/villagermobs/commands/VillagerMobsCommand.java
+++ b/src/main/java/com/leontg77/villagermobs/commands/VillagerMobsCommand.java
@@ -27,17 +27,23 @@
package com.leontg77.villagermobs.commands;
-import com.comphenix.protocol.ProtocolLibrary;
-import com.comphenix.protocol.ProtocolManager;
import com.google.common.collect.Lists;
import com.leontg77.villagermobs.Main;
-import com.leontg77.villagermobs.protocol.MobDisguiseAdapter;
+import com.leontg77.villagermobs.listeners.MobListener;
+import me.libraryaddict.disguise.DisguiseAPI;
+import me.libraryaddict.disguise.disguisetypes.Disguise;
+import me.libraryaddict.disguise.disguisetypes.DisguiseType;
+import me.libraryaddict.disguise.disguisetypes.MobDisguise;
+import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.event.HandlerList;
+import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@@ -49,14 +55,16 @@
public class VillagerMobsCommand implements CommandExecutor, TabCompleter {
private static final String PERMISSION = "villagermobs.manage";
- private final MobDisguiseAdapter disguise;
+ private final MobListener listener;
private final Main plugin;
- private final ProtocolManager manager = ProtocolLibrary.getProtocolManager();
+ private final Disguise disguise;
- public VillagerMobsCommand(Main plugin, MobDisguiseAdapter disguise) {
- this.disguise = disguise;
+ public VillagerMobsCommand(Main plugin, MobListener listener, Disguise disguise) {
this.plugin = plugin;
+
+ this.listener = listener;
+ this.disguise = disguise;
}
private boolean enabled = false;
@@ -90,7 +98,14 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
plugin.broadcast(Main.PREFIX + "Villager Mobs has been enabled.");
enabled = true;
- manager.addPacketListener(disguise);
+ Bukkit.getPluginManager().registerEvents(listener, plugin);
+
+ Bukkit.getWorlds()
+ .forEach(world -> Arrays.stream(world.getLoadedChunks())
+ .forEach(chunk -> Arrays.stream(chunk.getEntities())
+ .filter(entity -> entity instanceof LivingEntity)
+ .filter(living -> !DisguiseAPI.isDisguised(living) || DisguiseAPI.getDisguise(living).getType() != DisguiseType.VILLAGER)
+ .forEach(living -> DisguiseAPI.disguiseToAll(living, disguise))));
return true;
}
@@ -108,7 +123,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
plugin.broadcast(Main.PREFIX + "Villager Mobs has been disabled.");
enabled = false;
- manager.removePacketListener(disguise);
+ HandlerList.unregisterAll(listener);
return true;
}
diff --git a/src/main/java/com/leontg77/villagermobs/listeners/MobListener.java b/src/main/java/com/leontg77/villagermobs/listeners/MobListener.java
new file mode 100644
index 0000000..af154e6
--- /dev/null
+++ b/src/main/java/com/leontg77/villagermobs/listeners/MobListener.java
@@ -0,0 +1,74 @@
+/*
+ * Project: VillagerMobs
+ * Class: com.leontg77.villagermobs.listener.MobListener
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2016 Leon Vaktskjold .
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package com.leontg77.villagermobs.listeners;
+
+import me.libraryaddict.disguise.DisguiseAPI;
+import me.libraryaddict.disguise.disguisetypes.Disguise;
+import me.libraryaddict.disguise.disguisetypes.DisguiseType;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.event.world.ChunkLoadEvent;
+
+import java.util.Arrays;
+
+/**
+ * Mob listener class.
+ *
+ * @author LeonTG77
+ */
+public class MobListener implements Listener {
+ private final Disguise disguise;
+
+ public MobListener(Disguise disguise) {
+ this.disguise = disguise;
+ }
+
+ @EventHandler
+ public void on(PlayerJoinEvent event) {
+ Player player = event.getPlayer();
+ DisguiseAPI.disguiseToAll(player, disguise);
+ }
+
+ @EventHandler
+ public void on(CreatureSpawnEvent event) {
+ LivingEntity entity = event.getEntity();
+ DisguiseAPI.disguiseToAll(entity, disguise);
+ }
+
+ @EventHandler
+ public void on(ChunkLoadEvent event) {
+ Arrays.stream(event.getChunk().getEntities())
+ .filter(entity -> entity instanceof LivingEntity)
+ .filter(living -> !DisguiseAPI.isDisguised(living) || DisguiseAPI.getDisguise(living).getType() != DisguiseType.VILLAGER)
+ .forEach(living -> DisguiseAPI.disguiseToAll(living, disguise));
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/leontg77/villagermobs/protocol/MobDisguiseAdapter.java b/src/main/java/com/leontg77/villagermobs/protocol/MobDisguiseAdapter.java
deleted file mode 100644
index 4f49994..0000000
--- a/src/main/java/com/leontg77/villagermobs/protocol/MobDisguiseAdapter.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Project: VillagerMobs
- * Class: com.leontg77.villagermobs.protocol.MobDisguiseAdapter
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2016 Leon Vaktskjold .
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package com.leontg77.villagermobs.protocol;
-
-import com.comphenix.protocol.PacketType;
-import com.comphenix.protocol.events.ListenerPriority;
-import com.comphenix.protocol.events.PacketAdapter;
-import com.comphenix.protocol.events.PacketEvent;
-import com.leontg77.villagermobs.Main;
-
-/**
- * Mob disguises class.
- *
- * @author LeonTG77
- */
-public class MobDisguiseAdapter extends PacketAdapter {
-
- public MobDisguiseAdapter(Main plugin) {
- super(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.SPAWN_ENTITY_LIVING);
- }
-
- @Override
- public void onPacketSending(PacketEvent event) {
- if (!event.getPacketType().equals(PacketType.Play.Server.SPAWN_ENTITY_LIVING)) {
- return;
- }
-
- event.getPacket().getBytes().write(0, (byte) 120);
- }
-}
\ No newline at end of file