turt2live

Untitled

Jan 5th, 2012
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.80 KB | None | 0 0
  1. package me.turt2live;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.util.logging.Logger;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.ChatColor;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandSender;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.event.Event;
  13. import org.bukkit.plugin.PluginManager;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15.  
  16. public class AntiShare extends JavaPlugin {
  17.  
  18.     private ServerPlayerListener    pl;
  19.     private ServerBlockListener     bl;
  20.     private ServerEntityListener    el;
  21.  
  22.     public Logger                   log = Logger.getLogger("Minecraft");
  23.  
  24.     @Override
  25.     public void onDisable() {
  26.         pl = null;
  27.         bl = null;
  28.         el = null;
  29.         log.info("[" + getDescription().getFullName() + "] Disabled! (turt2live)");
  30.     }
  31.  
  32.     @Override
  33.     public void onEnable() {
  34.         File d = getDataFolder();
  35.         d.mkdirs();
  36.         File f2 = new File(getDataFolder(), "config.yml");
  37.         if (!f2.exists()) {
  38.             try {
  39.                 f2.createNewFile();
  40.             } catch (IOException e) {
  41.                 e.printStackTrace();
  42.             }
  43.             getConfig().set("events.block_break", "none");
  44.             getConfig().set("events.block_place", "57 41 42");
  45.             getConfig().set("events.death", "*");
  46.             getConfig().set("events.drop_item", "*");
  47.             getConfig().set("events.interact", "23 61 62 54 342");
  48.             getConfig().set("messages.block_break", "You can't do that!");
  49.             getConfig().set("messages.block_place", "You can't do that!");
  50.             getConfig().set("messages.death", "You can't do that!");
  51.             getConfig().set("messages.drop_item", "You can't do that!");
  52.             getConfig().set("messages.interact", "You can't do that!");
  53.             getConfig().set("other.only_if_creative", true);
  54.             getConfig().options().header("AntiShare Configuration:\n" +
  55.                     "Events:\n" +
  56.                     "   'block_place' - Blocks/items to deny for block placing\n" +
  57.                     "   'block_break' - Blocks/items to deny for block breaking\n" +
  58.                     "   'death' - Blocks/items to not allow to drop on death\n" +
  59.                     "   'drop_item' - Block/items to not allow to drop when a player presses (default) Q\n" +
  60.                     "   'interact' - Blocks/items to deny interactions to. (Left/Right click)\n" +
  61.                     "   -- Want all blocks/items to be denied? Put a *\n" +
  62.                     "   -- Want no blocks/items to be denied? Put: none\n" +
  63.                     "   -- Make sure item lists are space-seperated, not commas, periods, or fancy other things!" +
  64.                     "Messages:\n" +
  65.                     "   All messages are when they are declined an action.\n" +
  66.                     "   Chat colors are supported using the & sign (eg: &f = white)\n" +
  67.                     "Other:\n" +
  68.                     "   'only_if_creative' - Auto-decline if they are in creative, permissions still apply.\n" +
  69.                     "       (eg: A player doesn't have the allow or decline permission to place, and is in creative, places a block: declined)\n" +
  70.                     "Permissions:\n" +
  71.                     "   'AntiShare.*' - Deny all events\n" +
  72.                     "   'AntiShare.place' - Deny block placing\n" +
  73.                     "   'AntiShare.break' - Deny block breaking\n" +
  74.                     "   'AntiShare.death' - Deny item drops on death\n" +
  75.                     "   'AntiShare.drop' - Deny item dropping\n" +
  76.                     "   'AntiShare.interact' - Deny interactions\n" +
  77.                     "   -- If you want to allow an event, change the node to 'AntiShare.allow' (eg: 'AntiShare.allow.place' would allow placing)\n" +
  78.                     "   'AntiShare.reload' - Permission to use /antishare\n" +
  79.                     "Commands:\n" +
  80.                     "   '/antishare' - Reloads configuration\n" +
  81.                     "       Aliases: '/as', '/antis', '/ashare'\n" +
  82.                     "Notes:\n" +
  83.                     "   - Permissions default to all deny as true while all allow as OP or higher.\n" +
  84.                     "   - 'only_if_creative' will override the permissions meaning if a player is in survival-mode while 'only_if_creative' is true then \n" +
  85.                     "     the deny permissions will be ignored (eg: That survival player places a block: it is placed)\n" +
  86.                     "   - The default settings decline interactions with furnaces, chests, dispensers, and chest-minecarts\n" +
  87.                     "   - The event 'block_break' is set to 'none' because in creative-mode, no blocks are dropped when broken");
  88.             saveConfig();
  89.         }
  90.         reloadConfig();
  91.         pl = new ServerPlayerListener(this);
  92.         bl = new ServerBlockListener(this);
  93.         el = new ServerEntityListener(this);
  94.         PluginManager pm = Bukkit.getPluginManager();
  95.         pm.registerEvent(Event.Type.BLOCK_BREAK, bl, Event.Priority.Lowest, this);
  96.         pm.registerEvent(Event.Type.BLOCK_DAMAGE, bl, Event.Priority.Lowest, this);
  97.         pm.registerEvent(Event.Type.BLOCK_PLACE, bl, Event.Priority.Lowest, this);
  98.         pm.registerEvent(Event.Type.ENTITY_DEATH, el, Event.Priority.Lowest, this);
  99.         pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, pl, Event.Priority.Lowest, this);
  100.         log.info("[" + getDescription().getFullName() + "] Enabled! (turt2live)");
  101.     }
  102.  
  103.     public static String addColor(String message) {
  104.         String colorSeperator = "&";
  105.         message = message.replaceAll(colorSeperator + "0", ChatColor.getByCode(0x0).toString());
  106.         message = message.replaceAll(colorSeperator + "1", ChatColor.getByCode(0x1).toString());
  107.         message = message.replaceAll(colorSeperator + "2", ChatColor.getByCode(0x2).toString());
  108.         message = message.replaceAll(colorSeperator + "3", ChatColor.getByCode(0x3).toString());
  109.         message = message.replaceAll(colorSeperator + "4", ChatColor.getByCode(0x4).toString());
  110.         message = message.replaceAll(colorSeperator + "5", ChatColor.getByCode(0x5).toString());
  111.         message = message.replaceAll(colorSeperator + "6", ChatColor.getByCode(0x6).toString());
  112.         message = message.replaceAll(colorSeperator + "7", ChatColor.getByCode(0x7).toString());
  113.         message = message.replaceAll(colorSeperator + "8", ChatColor.getByCode(0x8).toString());
  114.         message = message.replaceAll(colorSeperator + "9", ChatColor.getByCode(0x9).toString());
  115.         message = message.replaceAll(colorSeperator + "a", ChatColor.getByCode(0xA).toString());
  116.         message = message.replaceAll(colorSeperator + "b", ChatColor.getByCode(0xB).toString());
  117.         message = message.replaceAll(colorSeperator + "c", ChatColor.getByCode(0xC).toString());
  118.         message = message.replaceAll(colorSeperator + "d", ChatColor.getByCode(0xD).toString());
  119.         message = message.replaceAll(colorSeperator + "e", ChatColor.getByCode(0xE).toString());
  120.         message = message.replaceAll(colorSeperator + "f", ChatColor.getByCode(0xF).toString());
  121.         message = message.replaceAll(colorSeperator + "A", ChatColor.getByCode(0xA).toString());
  122.         message = message.replaceAll(colorSeperator + "B", ChatColor.getByCode(0xB).toString());
  123.         message = message.replaceAll(colorSeperator + "C", ChatColor.getByCode(0xC).toString());
  124.         message = message.replaceAll(colorSeperator + "D", ChatColor.getByCode(0xD).toString());
  125.         message = message.replaceAll(colorSeperator + "E", ChatColor.getByCode(0xE).toString());
  126.         message = message.replaceAll(colorSeperator + "F", ChatColor.getByCode(0xF).toString());
  127.         return message;
  128.     }
  129.  
  130.     @Override
  131.     public boolean onCommand(CommandSender sender, Command command, String cmd, String[] args) {
  132.         if (sender instanceof Player) {
  133.             if (((Player) sender).hasPermission("AntiShare.reload")) if (cmd.equalsIgnoreCase("antishare") ||
  134.                     cmd.equalsIgnoreCase("as") ||
  135.                     cmd.equalsIgnoreCase("antis") ||
  136.                     cmd.equalsIgnoreCase("ashare")) {
  137.                 reloadConfig();
  138.                 ((Player) sender).sendMessage(ChatColor.GREEN + "AntiShare Reloaded.");
  139.             }
  140.             return false;
  141.         } else {
  142.             if (cmd.equalsIgnoreCase("antishare") ||
  143.                     cmd.equalsIgnoreCase("as") ||
  144.                     cmd.equalsIgnoreCase("antis") ||
  145.                     cmd.equalsIgnoreCase("ashare")) {
  146.                 reloadConfig();
  147.                 log.info("AntiShare Reloaded.");
  148.             }
  149.             return false;
  150.         }
  151.     }
  152.  
  153.     public static boolean isBlocked(String message, int id) {
  154.         boolean ret = false;
  155.         if (message.equalsIgnoreCase("none")) return false;
  156.         else if (message.equalsIgnoreCase("*")) return true;
  157.         String parts[] = message.split(" ");
  158.         String item = id + "";
  159.         for (String s : parts)
  160.             //System.out.println("ITEM: " + s);
  161.             if (s.equalsIgnoreCase(item)) {
  162.                 ret = true;
  163.                 break;
  164.             }
  165.         return ret;
  166.     }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment