(Prison) GuardStick Plugin - Suggestion

Discussion in 'Archived: Plugin Requests' started by nuperu, Jun 21, 2014.

  1. Offline

    nuperu

    Plugin category: Prison Server Plugin

    Suggested name: GuardStick

    What I want: So, I'm not sure if this plugin has already been created (haven't seen it anywhere on bukkit.org), but, I've seen it on other prison servers.
    What I'd like this plugin to do is when you take a blaze rod (any type, whether it is from gm, the nether, etc), and click on a player holding a sword in their hand, it'll take the sword, putting it into your inventory, but with NO ENCHANTS (if there are any enchants that is).
    Also, in the config you may change the blaze rod to any item.

    Ideas for commands: No commands, just add a kit in the essentials config giving you a blaze rod.

    Ideas for permissions: - guardstick.use (gives perms for the player to use the blaze rod to take another player's sword away)

    When I'd like it by: Two days or less.
     
  2. Offline

    maved145

    Do you want a message to appear like, you have just stole a {sword} from {player}?
     
  3. Offline

    nuperu

    Sure, that'd be great.
     
  4. Offline

    maved145

    nuperu

    nuperu that message saying ‘Sure, that’d be great.’ only just showed up for me xD

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  5. Offline

    nuperu

    maved145 sorry just joined bukkit today, I'm pretty much a noob :p
     
  6. Offline

    maved145

    nuperu alright xD, the plugin will be finished in about 15 minutes, probably less.
     
  7. Offline

    nuperu

  8. Offline

    maved145

    nuperu
    <Edit by Moderator: Redacted mediafire url>

    It took longer than 15 minutes because i found a bug and fixed it real quick, if you find any bugs, which I’m pretty sure you won’t, then tell me. I’ll be adding a option in the config, that if you set the messages to ‘none’ a message won’t be displayed. Tell me if you want that version or not.

    Also if you got a prison server would you mind letting me play on it? :p xD

    Enjoy bud.
     
    Last edited by a moderator: Nov 2, 2016
  9. Offline

    nuperu

    maved145 Thanks again, the plugin is great as it is. My server IP is <removed advertising> , the only thing I really need to do on it is finish up the enjin site and set up some voting links.
     
  10. Offline

    maved145

    nuperu glad to hear you like it! also ip says can’t resolve host name :/
     
  11. Offline

    Geekxboy

    nuperu Your'e not allowed to advertise in this section
     
  12. Offline

    nuperu

    maved145 default players can take the swords also, and they don't even have blaze rods, just their fists :/
     
  13. Offline

    Geekxboy

    Don't bump within 24 hours
    If people don't respond immediately they may be busy as we do have lives outside Minecraft and Bukkit
     
  14. Offline

    nuperu

    Geekxboy Well, I do know that you all have lives outside of minecraft, so do I, but you don't have to be rude about saying it. This plugin is really all I need for my mc server to be finished so.. you know, I'm kinda anxious.
     
  15. Offline

    Geekxboy

    Just wait for maved145 to come back and he will fix any issues with the plugin
    Or if I get the okay from him then I'll fix any issues there might be
     
  16. Offline

    maved145

    Geekxboy i don’t really know whats going on. my code looks right to me, but if you want to do it its fine by me.
     
  17. Offline

    Geekxboy

    Alright ill take a look
     
  18. Offline

    maved145

    Geekxboy
    heres my code. The checking of the sword in the target players hand works, but the checking of the blaze rod, in the players hand doesn’t work. it lets you use anything to steal the sword.

    Code:java
    1. package me.Maved145.GuardStick;
    2.  
    3. import java.util.Map.Entry;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Material;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.enchantments.Enchantment;
    10. import org.bukkit.entity.HumanEntity;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.player.PlayerInteractEntityEvent;
    15. import org.bukkit.inventory.ItemStack;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. public class GuardStick extends JavaPlugin implements Listener
    19. {
    20. public void onEnable()
    21. {
    22. sendConsoleMessage("&bGuardStick &6v1.0 &dhas been Enabled!");
    23. sendConsoleMessage("&bGuardStick &dmade by Maved145!");
    24. getServer().getPluginManager().registerEvents(this, this);
    25. saveDefaultConfig();
    26. }
    27.  
    28. public void onDisable()
    29. {
    30. saveDefaultConfig();
    31. sendConsoleMessage("&bGuardStick &6v1.0 &dhas been Disabled!");
    32. sendConsoleMessage("&bGuardStick &dmade by Maved145!");
    33. }
    34.  
    35. public String sendConsoleMessage(String msg)
    36. {
    37. return sendMessage(Bukkit.getConsoleSender(), msg);
    38. }
    39.  
    40. public String sendMessage(CommandSender target, String msg)
    41. {
    42. target.sendMessage(msg.replace('&', '§'));
    43. return msg.replace('&', '§');
    44. }
    45.  
    46. @SuppressWarnings("deprecation")
    47. @EventHandler
    48. public void onPlayerClick(PlayerInteractEntityEvent event)
    49. {
    50. if ((event).getRightClicked() instanceof HumanEntity)
    51. {
    52. Player playerTarget = (Player) event.getRightClicked();
    53. Player player = (Player) event.getPlayer();
    54.  
    55. if (player.getItemInHand().getType() == Material.BLAZE_ROD && playerTarget.getItemInHand().getType() == Material.DIAMOND_SWORD || playerTarget.getItemInHand().getType() == Material.GOLD_SWORD || playerTarget.getItemInHand().getType() == Material.IRON_SWORD || playerTarget.getItemInHand().getType() == Material.STONE_SWORD || playerTarget.getItemInHand().getType() == Material.WOOD_SWORD)
    56. {
    57.  
    58. ItemStack ItemInHand = new ItemStack(playerTarget.getItemInHand());
    59. for (Entry<Enchantment, Integer> e : ItemInHand.getEnchantments().entrySet())
    60. {
    61. ItemInHand.removeEnchantment(e.getKey());
    62. }
    63.  
    64. playerTarget.getInventory().remove(playerTarget.getItemInHand());
    65. playerTarget.updateInventory();
    66.  
    67. player.getInventory().addItem((ItemInHand));
    68. player.updateInventory();
    69. String stolensword = ItemInHand.getType().toString();
    70. String messagetothief = getConfig().getString("Thief.message-to-user").replaceAll("&0", ChatColor.BLACK + "").replaceAll("&1", ChatColor.DARK_BLUE + "").replaceAll("&2", ChatColor.DARK_GREEN + "").replaceAll("&3", ChatColor.DARK_AQUA + "").replaceAll("&4", ChatColor.DARK_RED + "").replaceAll("&5", ChatColor.DARK_PURPLE + "").replaceAll("&6", ChatColor.GOLD + "").replaceAll("&7", ChatColor.GRAY + "").replaceAll("&8", ChatColor.DARK_GRAY + "").replaceAll("&9", ChatColor.BLUE + "").replaceAll("&a", ChatColor.GREEN + "").replaceAll("&b", ChatColor.AQUA + "").replaceAll("&c", ChatColor.RED + "").replaceAll("&d", ChatColor.LIGHT_PURPLE + "").replaceAll("&e", ChatColor.YELLOW + "").replaceAll("&f", ChatColor.WHITE + "").replaceAll("&l", ChatColor.BOLD + "").replaceAll("&n", ChatColor.UNDERLINE + "").replaceAll("&o", ChatColor.ITALIC + "").replaceAll("&k", ChatColor.MAGIC + "").replaceAll("&m", ChatColor.STRIKETHROUGH + "").replaceAll("&r", ChatColor.RESET + "").replaceAll("%stolensword%", stolensword).replaceAll("%victim%", playerTarget.getName()).replaceAll("%thief%", player.getName()).replaceAll("DIAMOND_SWORD", "Diamond Sword").replaceAll("GOLD_SWORD", "Gold Sword").replaceAll("IRON_SWORD", "Iron Sword").replaceAll("STONE_SWORD", "Stone Sword").replaceAll("WOOD_SWORD", "Wood Sword");
    71. String messagetovictim = getConfig().getString("Victim.message-to-user").replaceAll("&0", ChatColor.BLACK + "").replaceAll("&1", ChatColor.DARK_BLUE + "").replaceAll("&2", ChatColor.DARK_GREEN + "").replaceAll("&3", ChatColor.DARK_AQUA + "").replaceAll("&4", ChatColor.DARK_RED + "").replaceAll("&5", ChatColor.DARK_PURPLE + "").replaceAll("&6", ChatColor.GOLD + "").replaceAll("&7", ChatColor.GRAY + "").replaceAll("&8", ChatColor.DARK_GRAY + "").replaceAll("&9", ChatColor.BLUE + "").replaceAll("&a", ChatColor.GREEN + "").replaceAll("&b", ChatColor.AQUA + "").replaceAll("&c", ChatColor.RED + "").replaceAll("&d", ChatColor.LIGHT_PURPLE + "").replaceAll("&e", ChatColor.YELLOW + "").replaceAll("&f", ChatColor.WHITE + "").replaceAll("&l", ChatColor.BOLD + "").replaceAll("&n", ChatColor.UNDERLINE + "").replaceAll("&o", ChatColor.ITALIC + "").replaceAll("&k", ChatColor.MAGIC + "").replaceAll("&m", ChatColor.STRIKETHROUGH + "").replaceAll("&r", ChatColor.RESET + "").replaceAll("%stolensword%", stolensword).replaceAll("%victim%", playerTarget.getName()).replaceAll("%thief%", player.getName()).replaceAll("DIAMOND_SWORD", "Diamond Sword").replaceAll("GOLD_SWORD", "Gold Sword").replaceAll("IRON_SWORD", "Iron Sword").replaceAll("STONE_SWORD", "Stone Sword").replaceAll("WOOD_SWORD", "Wood Sword");
    72. player.sendMessage(messagetothief);
    73. playerTarget.sendMessage(messagetovictim);
    74. }
    75. else
    76. {
    77. return;
    78. }
    79. }
    80. else
    81. {
    82. return;
    83. }
    84.  
    85. }
    86.  
    87. }
    88.  
     
  19. Offline

    Geekxboy

    Small issue with your if statement so i broke the statement up into 2 parts

    nuperu Download below and I haven't tested it
    Download link
     
  20. Offline

    maved145

    Geekxboy
    Code? :p I’d like to see what the problem was.

    Geekxboy wow don’t matter, i see. so i couldn’t use && to do it, i had to make it a whole different if statement ;/ logic

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  21. Offline

    Geekxboy

    in your if statement of your PlayerInteractEntityEvent event there was no separation between your ANDs and ORs

    so they could have the perm and the guard stick OR have any of the swords
     
  22. Offline

    maved145

    nuperu i forgot to add the permission XD
     
  23. Offline

    Geekxboy

    It didnt need to be a whole different statement (you can use parenthesis to separate them) but i did it because i hate long if statements
     
  24. Offline

    maved145

  25. Offline

    Geekxboy

    No problem mate
     
  26. Offline

    maved145

    nuperu I sent you the most recent file on Skype with the permissions added in.

    Geekxboy
    Yeah i know what you mean, I should of thought about it really, I’m still a beginner so, i learn things new everyday :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  27. Offline

    XgXXSnipz

    Source Code for the config yml in eclipse -thanks
     
  28. Offline

    maved145

  29. Offline

    nuperu

    Sorry for all the struggle guys. Just want to say thank you so much! This plugin is exactly what I wanted and it fits perfectly.
     
  30. Offline

    Geekxboy

    That's good to hear
     

Share This Page