diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 5b52a23d1..fc07a9fce 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -23,6 +23,7 @@ import org.bukkit.entity.Chicken; import org.bukkit.entity.Cow; import org.bukkit.entity.Egg; import org.bukkit.entity.Entity; +import org.bukkit.entity.Horse; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Pig; import org.bukkit.entity.Player; @@ -40,6 +41,7 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -72,6 +74,8 @@ import mineplex.core.portal.Portal; import mineplex.core.task.TaskManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.hub.commands.HorseSpawn; +import mineplex.hub.modules.MountManager; import mineplex.hub.party.Party; import mineplex.hub.party.PartyManager; import mineplex.hub.tutorial.TutorialManager; @@ -116,6 +120,7 @@ public class HubManager extends MiniClientPlugin _textCreator = new TextCreator(this); new Dragon(this); + new MountManager(this); _partyManager = new PartyManager(this); _tutorialManager = new TutorialManager(this, donationManager, taskManager, _textCreator); @@ -476,7 +481,7 @@ public class HubManager extends MiniClientPlugin player.setFoodLevel(20); } } - + @EventHandler public void UpdateWeather(UpdateEvent event) { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Stacker.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Stacker.java index b9182f5fe..63888084d 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Stacker.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Stacker.java @@ -7,6 +7,7 @@ import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.entity.Entity; +import org.bukkit.entity.Horse; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -114,6 +115,9 @@ public class Stacker extends MiniPlugin implements IThrown if (stackee == null) return; + if (stackee instanceof Horse) + return; + if (stackee instanceof Player && ((Player)stackee).getGameMode() != GameMode.SURVIVAL) return; diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/HorseSpawn.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/HorseSpawn.java new file mode 100644 index 000000000..a85a81411 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/HorseSpawn.java @@ -0,0 +1,21 @@ +package mineplex.hub.commands; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.hub.modules.MountManager; + +public class HorseSpawn extends CommandBase +{ + public HorseSpawn(MountManager plugin) + { + super(plugin, Rank.OWNER, new String[] {"horse"}); + } + + @Override + public void Execute(Player caller, String[] args) + { + Plugin.HorseCommand(caller, args); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/MountManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/MountManager.java new file mode 100644 index 000000000..5e1e85ee6 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/MountManager.java @@ -0,0 +1,337 @@ +package mineplex.hub.modules; + +import java.util.ArrayList; +import java.util.HashMap; + +import mineplex.core.MiniPlugin; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.hub.HubManager; +import mineplex.hub.commands.HorseSpawn; + +import org.bukkit.Material; +import org.bukkit.entity.Horse; +import org.bukkit.entity.Player; +import org.bukkit.entity.Horse.Color; +import org.bukkit.entity.Horse.Style; +import org.bukkit.entity.Horse.Variant; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; + +public class MountManager extends MiniPlugin +{ + private HubManager Manager; + + private HashMap _mounts = new HashMap(); + + public MountManager(HubManager manager) + { + super("Mount Manager", manager.GetPlugin()); + + Manager = manager; + } + + @Override + public void AddCommands() + { + AddCommand(new HorseSpawn(this)); + } + + @EventHandler + public void HorseInteract(PlayerInteractEntityEvent event) + { + if (!(event.getRightClicked() instanceof Horse)) + return; + + Player player = event.getPlayer(); + Horse horse = (Horse)event.getRightClicked(); + + //Not Owner + if (!_mounts.containsKey(player) || !_mounts.get(player).equals(horse)) + { + UtilPlayer.message(player, F.main("Mount", "This is not your mount!")); + event.setCancelled(true); + return; + } + } + + @EventHandler + public void PlayerQuit(PlayerQuitEvent event) + { + Horse horse = _mounts.remove(event.getPlayer()); + if (horse != null) + horse.remove(); + } + + @EventHandler + public void PlayerJoin(PlayerJoinEvent event) + { + if (!Manager.GetClients().Get(event.getPlayer()).GetRank().Has(Rank.OWNER)) + return; + + final Player fPlayer = event.getPlayer(); + Manager.GetPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.GetPlugin(), new Runnable() + { + public void run() + { + Spawn(fPlayer, Variant.HORSE).setPassenger(fPlayer); + } + }, 5); + } + + public void HorseCommand(Player caller, String[] args) + { + if (args == null || args.length == 0) + { + UtilPlayer.message(caller, F.main("Mount", "Mount Commands;")); + UtilPlayer.message(caller, "spawn / kill / leash / unleash"); + UtilPlayer.message(caller, "age / color / style / armor"); + return; + } + + if (args[0].equalsIgnoreCase("spawn")) + { + Variant var = Variant.HORSE; + if (args.length > 1) + { + try + { + var = Variant.valueOf(args[1].toUpperCase());; + } + catch (Exception e) + { + + } + } + + Spawn(caller, var); + return; + } + + Horse horse = _mounts.get(caller); + if (horse == null) + { + UtilPlayer.message(caller, F.main("Mount", "You do not have a mount.")); + return; + } + + //Leash + else if (args[0].equalsIgnoreCase("leash")) + { + horse.setLeashHolder(caller); + } + + //UnLeash + else if (args[0].equalsIgnoreCase("unleash")) + { + horse.setLeashHolder(null); + } + + //Kill + else if (args[0].equalsIgnoreCase("kill")) + { + horse.remove(); + _mounts.remove(caller); + } + + //Age + else if (args[0].equalsIgnoreCase("age")) + { + if (args.length >= 2) + { + try + { + if (args[1].equalsIgnoreCase("adult")) + { + horse.setAdult(); + } + else if (args[1].equalsIgnoreCase("baby")) + { + horse.setBaby(); + } + return; + } + catch (Exception e) + { + + } + } + + UtilPlayer.message(caller, F.main("Mount", F.value("Age", "baby adult"))); + } + + //Color + else if (args[0].equalsIgnoreCase("color")) + { + if (args.length >= 2) + { + Color color = GetColor(caller, args[1]); + if (color != null) + horse.setColor(color); + } + } + + //Style + else if (args[0].equalsIgnoreCase("style")) + { + if (args.length >= 2) + { + Style style = GetStyle(caller, args[1]); + if (style != null) + horse.setStyle(style); + } + } + + //Variant + else if (args[0].equalsIgnoreCase("variant") || args[0].equalsIgnoreCase("var")) + { + if (args.length >= 2) + { + Variant variant = GetVariant(caller, args[1]); + if (variant != null) + horse.setVariant(variant); + } + } + + //Armor + else if (args[0].equalsIgnoreCase("armor")) + { + if (args.length >= 2) + { + try + { + if (args[1].equalsIgnoreCase("iron")) + { + horse.getInventory().setArmor(new ItemStack(Material.IRON_BARDING)); + return; + } + if (args[1].equalsIgnoreCase("gold")) + { + horse.getInventory().setArmor(new ItemStack(Material.GOLD_BARDING)); + return; + } + if (args[1].equalsIgnoreCase("diamond")) + { + horse.getInventory().setArmor(new ItemStack(Material.DIAMOND_BARDING)); + return; + } + + } + catch (Exception e) + { + + } + } + + UtilPlayer.message(caller, F.main("Mount", F.value("Armor", "iron gold diamond"))); + } + } + + public Style GetStyle(Player caller, String arg) + { + ArrayList