Plugin Reqeust

Discussion in 'Archived: Plugin Requests' started by YoungKnight2CS, Jan 14, 2013.

  1. Offline

    YoungKnight2CS

    Greetings.
    I own a small RP server. With people getting a job at the King like Guard. And fight the other races too.
    But it will be awesome to have pigs to ride on!
    Of course you can get a pig from a dark corner in the world but it dies too quick!
    What i thought of is a Plugin that spawns a pig, a saddle and a carrot on a stick in ur hand


    As example:
    A Admin gives a player permission: /horseallow <playername>
    This command overrides any permissions and allows the player to spawn the mob.
    You cannot spawn a Pig in worldguard mob-spawning denied world.
    The player given permission for it does /horse spawn
    It spawns a pig randomly 2 blocks away from the player. Or maybe a custom location a player sets himself.
    It also spawns a saddle and a carrot on a stick in his invetory.
    The player goes to his pig, saddles him and rides him. The pig he spawned can be set the health of in the configuration. Like 20 health (10 hearths i think) so it doesn't die within 1 shot.


    I really hope this plugin will be made, or that it was already made!
     
  2. Offline

    evilmidget38

    YoungKnight2CS That's actually a really cool idea, I'd love to see it done. However, I don't think there needs to be the command to allow players to use it. Just use permissions. There's no need to implement something twice.
     
  3. Offline

    YoungKnight2CS

    Then lets hope someone will be there to make it. I don't know anyone that is pretty good in Java Coding.
     
  4. Offline

    evilmidget38

    YoungKnight2CS I could make it, although I'm at school atm, so there isn't really a way I could provide a download for it.
     
  5. Offline

    YoungKnight2CS

    Ok :L. Well if u could make it, please tell me i really really want/need this for my server :)
     
  6. Offline

    evilmidget38

    YoungKnight2CS
    Code:java
    1.  
    2. package com.evilmidget38.fearfulmount;
    3.  
    4. import java.util.HashMap;
    5. import java.util.Map;
    6. import java.util.Map.Entry;
    7. import java.util.Random;
    8. import java.util.UUID;
    9.  
    10. import org.bukkit.Bukkit;
    11. import org.bukkit.ChatColor;
    12. import org.bukkit.Location;
    13. import org.bukkit.Material;
    14. import org.bukkit.World;
    15. import org.bukkit.command.Command;
    16. import org.bukkit.command.CommandSender;
    17. import org.bukkit.entity.EntityType;
    18. import org.bukkit.entity.Pig;
    19. import org.bukkit.entity.Player;
    20. import org.bukkit.event.EventHandler;
    21. import org.bukkit.event.Listener;
    22. import org.bukkit.event.entity.EntityDeathEvent;
    23. import org.bukkit.event.player.PlayerChangedWorldEvent;
    24. import org.bukkit.event.player.PlayerQuitEvent;
    25. import org.bukkit.inventory.ItemStack;
    26. import org.bukkit.plugin.java.JavaPlugin;
    27.  
    28. public class FearfulMount extends JavaPlugin implements Listener {
    29. static String[] consolePig;
    30. static {
    31. // The stuff you find on the internet...
    32. consolePig = new String[13];
    33. consolePig[0] = " ^, ,^";
    34. consolePig[1] = " / ---- \\ ";
    35. consolePig[2] = " / _\\ /_ \\ Ful";
    36. consolePig[3] = " | / __ \\ |";
    37. consolePig[4] = " | /oo\\ | ,-.";
    38. consolePig[5] = " | \\__/ |____________.:'";
    39. consolePig[6] = " \\ .__. / \\ '";
    40. consolePig[7] = " '.______.' \\";
    41. consolePig[8] = " \\ |";
    42. consolePig[9] = " | /____...-----\\ |";
    43. consolePig[10] = " | | | |";
    44. consolePig[12] = " |^^| |^^| ";
    45. }
    46.  
    47. int health;
    48. Map<String, UUID> mounts = new HashMap<String, UUID>();
    49.  
    50. public void onEnable() {
    51. health = getConfig().getInt("mount-health", 20);
    52. getConfig().set("mount-health", health);
    53. saveConfig();
    54. }
    55.  
    56. public void onDisable() {
    57.  
    58. }
    59.  
    60. public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
    61. if (!(sender instanceof Player)) {
    62. for(String s : consolePig) {
    63. sender.sendMessage(s);
    64. }
    65. sender.sendMessage("There's your mount.");
    66. return true;
    67. }
    68. Player player = (Player)sender;
    69. Pig mount = getMount(mounts.get(player.getName()), player.getWorld());
    70. if (mount == null) {
    71. mount = (Pig) player.getWorld().spawnEntity(getRandomNearby(player.getLocation()), EntityType.PIG);
    72. mount.setSaddle(true);
    73. mounts.put(player.getName(), mount.getUniqueId());
    74. mount.setMaxHealth(health);
    75. mount.setHealth(health);
    76. }
    77. if (!player.getInventory().contains(Material.CARROT_STICK)) {
    78. player.getInventory().addItem(new ItemStack(Material.CARROT_STICK));
    79. }
    80. player.sendMessage(ChatColor.GREEN+"Ride on!");
    81. return true;
    82. }
    83.  
    84. @EventHandler
    85. public void onEntityDeath(EntityDeathEvent e) {
    86. if (e.getEntity() instanceof Pig) {
    87. String owner = null;
    88. for (Entry<String, UUID> entry : mounts.entrySet()) {
    89. if (entry.getValue().equals(e.getEntity().getUniqueId())) {
    90. Player player = Bukkit.getPlayer(entry.getKey());
    91. if (player != null) {
    92. player.sendMessage(ChatColor.RED+"Your valiant mount has died!");
    93. }
    94. owner = entry.getKey();
    95. }
    96. }
    97. if (owner != null) {
    98. mounts.remove(owner);
    99. }
    100. }
    101. }
    102.  
    103. @EventHandler(ignoreCancelled = true)
    104. public void onPlayerChangeWorld(PlayerChangedWorldEvent e) {
    105. Pig pig = getMount(mounts.get(e.getPlayer().getName()), e.getPlayer().getWorld());
    106. if (pig != null) {
    107. pig.remove();
    108. e.getPlayer().sendMessage(ChatColor.RED+"You're leaving the world, so we removed your mount.");
    109. mounts.remove(e.getPlayer().getName());
    110. }
    111. }
    112. @EventHandler(ignoreCancelled = true)
    113. public void onPlayerQuit(PlayerQuitEvent e) {
    114. Pig pig = getMount(mounts.get(e.getPlayer().getName()), e.getPlayer().getWorld());
    115. pig.remove();
    116. mounts.remove(e.getPlayer().getName());
    117. }
    118.  
    119. public Pig getMount(UUID id, World world) {
    120. for (Pig p : world.getEntitiesByClass(Pig.class)) {
    121. if (p.getUniqueId().equals(id)) {
    122. return p;
    123. }
    124. }
    125. return null;
    126. }
    127.  
    128. public Location getRandomNearby(Location loc) {
    129. Random rand = new Random();
    130. int x = rand.nextInt(4)-2;
    131. int z = rand.nextInt(4)-2;
    132. Location random = loc.add(x, loc.getWorld().getHighestBlockYAt(x, z), z);
    133. // This can only happen if the pig is too high or too low from the player.
    134. if (random.distanceSquared(loc) > 16) {
    135. return getRandomNearby(loc);
    136. }
    137. return random;
    138. }
    139.  
    140. }
    141.  
    142.  
    143.  


    Well, I finished it. I'll compile+upload to bukkitdev tonight.
     
  7. Offline

    YoungKnight2CS

    Awesome man, could u PM me a download? :D
     

Share This Page