Added Mount Manager

This commit is contained in:
Chiss 2013-09-07 16:01:10 +10:00
parent a24a80e5a5
commit ff0e39067a
6 changed files with 376 additions and 2 deletions

View File

@ -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<HubClient>
_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<HubClient>
player.setFoodLevel(20);
}
}
@EventHandler
public void UpdateWeather(UpdateEvent event)
{

View File

@ -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;

View File

@ -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<MountManager>
{
public HorseSpawn(MountManager plugin)
{
super(plugin, Rank.OWNER, new String[] {"horse"});
}
@Override
public void Execute(Player caller, String[] args)
{
Plugin.HorseCommand(caller, args);
}
}

View File

@ -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<Player, Horse> _mounts = new HashMap<Player, Horse>();
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<Style> match = new ArrayList<Style>();
for (Style var : Style.values())
{
if (var.name().equals(arg.toUpperCase()))
return var;
if (var.name().contains(arg.toUpperCase()))
match.add(var);
}
if (match.size() == 1)
return match.get(0);
String valids = "";
for (Style valid : Style.values())
valids += valid.name() + " ";
UtilPlayer.message(caller, F.main("Mount", F.value("Styles", valids)));
return null;
}
public Color GetColor(Player caller, String arg)
{
ArrayList<Color> match = new ArrayList<Color>();
for (Color var : Color.values())
{
if (var.name().equals(arg.toUpperCase()))
return var;
if (var.name().contains(arg.toUpperCase()))
match.add(var);
}
if (match.size() == 1)
return match.get(0);
String valids = "";
for (Color valid : Color.values())
valids += valid.name() + " ";
UtilPlayer.message(caller, F.main("Mount", F.value("Colors", valids)));
return null;
}
public Variant GetVariant(Player caller, String arg)
{
ArrayList<Variant> match = new ArrayList<Variant>();
for (Variant var : Variant.values())
{
if (var.name().equals(arg.toUpperCase()))
return var;
if (var.name().contains(arg.toUpperCase()))
match.add(var);
}
if (match.size() == 1)
return match.get(0);
String valids = "";
for (Variant valid : Variant.values())
valids += valid.name() + " ";
UtilPlayer.message(caller, F.main("Mount", F.value("Variants", valids)));
return null;
}
public Horse Spawn(Player caller, Variant var)
{
Horse horse = _mounts.remove(caller);
if (horse != null) horse.remove();
horse = caller.getWorld().spawn(caller.getLocation(), Horse.class);
horse.setAdult();
horse.setAgeLock(true);
horse.setColor(Color.DARK_BROWN);
horse.setStyle(Style.WHITE_DOTS);
horse.setVariant(var);
horse.setOwner(caller);
horse.setMaxDomestication(1);
horse.setJumpStrength(1);
horse.getInventory().setSaddle(new ItemStack(Material.SADDLE));
horse.setCustomName(caller.getName() + "'s Mount");
horse.setCustomNameVisible(true);
_mounts.put(caller, horse);
return horse;
}
@EventHandler
public void LeashSpawn(ItemSpawnEvent event)
{
if (event.getEntity().getItemStack().getType() == Material.LEASH)
event.setCancelled(true);
}
}

View File

@ -61,6 +61,12 @@ public class Party
{
_scoreboard.getTeam(Manager.Manager.GetClients().Get(player).GetRank().Name).addPlayer(player);
}
//Owners
_scoreboard.getTeam(Rank.OWNER.Name).addPlayer(Bukkit.getOfflinePlayer("Chiss"));
_scoreboard.getTeam(Rank.OWNER.Name).addPlayer(Bukkit.getOfflinePlayer("defek7"));
_scoreboard.getTeam(Rank.OWNER.Name).addPlayer(Bukkit.getOfflinePlayer("Spu_"));
_scoreboard.getTeam(Rank.OWNER.Name).addPlayer(Bukkit.getOfflinePlayer("sterling_"));
}
public void JoinParty(Player player)

View File

@ -73,8 +73,9 @@ public class PerkWitherImage extends Perk
skel.setSkeletonType(SkeletonType.WITHER);
skel.getEquipment().setArmorContents(player.getInventory().getArmorContents());
skel.getEquipment().setItemInHand(player.getItemInHand());
skel.setMaxHealth(50);
skel.setHealth(skel.getMaxHealth());
skel.setCustomName(C.cYellow + player.getName());
skel.setCustomNameVisible(true);