SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ahmedsystem.by.xXxAhMeDxXx;
  2.  
  3. import java.io.File;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9. import org.bukkit.Bukkit;
  10. import org.bukkit.command.Command;
  11. import org.bukkit.command.CommandSender;
  12. import org.bukkit.configuration.file.YamlConfiguration;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.EventHandler;
  15. import org.bukkit.event.Listener;
  16. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
  17. import org.bukkit.plugin.java.JavaPlugin;
  18.  
  19. public class CMDManager extends JavaPlugin implements Listener
  20. {
  21.   public void onEnable()
  22.   {
  23.     InputStream is = getResource("config.yml");
  24.     File df = getDataFolder();
  25.     df.mkdirs();
  26.     File file = new File(getDataFolder(), "/config.yml");
  27.    
  28.     if (!file.exists())
  29.     {
  30.       try {
  31.         FileOutputStream out = new FileOutputStream(file);
  32.         InputStream in = is;
  33.         int read = -1;
  34.         while ((read = in.read()) != -1)
  35.           out.write(read);
  36.         out.flush();
  37.         out.close();
  38.         in.close();
  39.       } catch (IOException e) {
  40.         e.printStackTrace();
  41.       }
  42.     }
  43.     Bukkit.getPluginManager().registerEvents(this, this);
  44.     if (getConfig().getBoolean("tab-complete.disabled")) {
  45.       File f = new File(Bukkit.getServer().getWorldContainer(), "spigot.yml");
  46.       if (!f.exists()) {
  47.         getLogger().info("[MegaBlocker] File 'spigot.yml' not found for disable tab complete. You are not using spigot server!");
  48.         return;
  49.       }
  50.       YamlConfiguration z = YamlConfiguration.loadConfiguration(f);
  51.      
  52.       if (z.getInt("commands.tab-complete") != -1) {
  53.         z.set("commands.tab-complete", Integer.valueOf(-1));
  54.       }
  55.      
  56.       try {
  57.         z.save(f);
  58.       } catch (IOException e) {
  59.         e.printStackTrace();
  60.       }
  61.     }
  62.   }
  63.  
  64.   @EventHandler
  65.   public void onCommand(PlayerCommandPreprocessEvent e) {
  66.     Player p = e.getPlayer();
  67.     String[] cmd = e.getMessage().replace("/", "").split(" ");
  68.     List<String> list = new ArrayList<String>();
  69.    
  70.     list = getConfig().getStringList("commands.enabled");
  71.    
  72.     if (list.contains(cmd[0])) {
  73.       return;
  74.     }
  75.    
  76.     if (cmd[0].equals("pl") || cmd[0].equals("plugins") || cmd[0].equals("bukkit:pl") || cmd[0].equals("bukkit:plugins")) {
  77.       if (p.hasPermission("mega.bypass")) {
  78.         return;
  79.       }
  80.       e.setCancelled(true);
  81.       p.sendMessage(getConfig().getString("plugins.message").replace("&", "�"));
  82.      
  83.       return;
  84.     }
  85.     if (!p.hasPermission("mega.bypass")) {
  86.       e.setCancelled(true);
  87.       p.sendMessage(getConfig().getString("commands.message").replace("&", "�"));
  88.     }
  89.   }
  90.  
  91.   public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  92.     if (!(sender instanceof Player)) {
  93.       return true;
  94.     }
  95.     Player p = (Player)sender;
  96.     if (cmd.getName().equalsIgnoreCase("megablocker")) {
  97.       if (args.length == 0) {
  98.         p.sendMessage("�7[�6MegaBlocker�7] Plugin by �6The_TadeSK");
  99.         p.sendMessage("�7[�6MegaBlocker�7] Version: �7" + getDescription().getVersion());
  100.         if (p.hasPermission("megablocker.reload")) {
  101.           p.sendMessage("�7[�6MegaBlocker�7] Use �6/megablocker reload �7to reload config file");
  102.         }
  103.       } else if (args[0].equalsIgnoreCase("reload")) {
  104.         if (!p.hasPermission("megablocker.reload")) {
  105.           return true;
  106.         }
  107.         saveConfig();
  108.         reloadConfig();
  109.         p.sendMessage("�7[�6MegaBlocker�7] Config reloaded");
  110.         if (getConfig().getBoolean("tab-complete.disabled")) {
  111.           File f = new File(Bukkit.getServer().getWorldContainer(), "spigot.yml");
  112.           if (!f.exists()) {
  113.             getLogger().info("[MegaBlocker] File 'spigot.yml' not found for disable tab complete. You are not using spigot server!");
  114.             return true;
  115.           }
  116.           YamlConfiguration z = YamlConfiguration.loadConfiguration(f);
  117.          
  118.           if (z.getInt("commands.tab-complete") != -1) {
  119.             z.set("commands.tab-complete", Integer.valueOf(-1));
  120.           }
  121.          
  122.           try {
  123.             z.save(f);
  124.           } catch (IOException e) {
  125.             e.printStackTrace();
  126.           }
  127.          
  128.           p.sendMessage("�7[�6MegaBlocker�7] Disabled Tab Complete, server need restart to apply that!");
  129.         }
  130.       }
  131.     }
  132.     return true;
  133.   }
  134. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top