/Dwarflater/src/me/luuxx/Dwarflater/Dwarflater.java

https://github.com/luuxx/Dwarflater · Java · 136 lines · 114 code · 22 blank · 0 comment · 19 complexity · 6e34ff7ada58249ee0011d13cab82fc0 MD5 · raw file

  1. package me.luuxx.Dwarflater;
  2. import java.util.logging.Logger;
  3. import com.nijiko.permissions.PermissionHandler;
  4. import com.nijikokun.bukkit.Permissions.Permissions;
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.command.Command;
  7. import org.bukkit.command.CommandException;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.event.Event;
  11. import org.bukkit.plugin.Plugin;
  12. import org.bukkit.plugin.PluginDescriptionFile;
  13. import org.bukkit.plugin.PluginManager;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15. public class Dwarflater extends JavaPlugin{
  16. public static Dwarflater plugin;
  17. public final Logger logger = Logger.getLogger("Minecraft");
  18. public Property woords = new Property("plugins/Dwarflater/dwarven.txt", this);
  19. public static PermissionHandler permissionHandler;
  20. public boolean dwAuto = false;
  21. public final ServerChatPlayerListener playerListener = new ServerChatPlayerListener(this);
  22. @Override
  23. public void onDisable(){
  24. PluginDescriptionFile pdfFile = this.getDescription();
  25. this.logger.info(pdfFile.getName() + " is now disabled.");
  26. }
  27. @Override
  28. public void onEnable(){
  29. PluginManager pm = getServer().getPluginManager();
  30. PluginDescriptionFile pdfFile = this.getDescription();
  31. this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enablad");
  32. try
  33. {
  34. linkToPermissions();
  35. pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Event.Priority.High, this);
  36. woords.load();
  37. this.logger.info(pdfFile.getName() + "loaded woords");
  38. }
  39. catch(Exception e)
  40. {
  41. this.logger.info(pdfFile.getName() + "failed to loads woords");
  42. this.logger.info(e.getMessage());
  43. }
  44. }
  45. public void linkToPermissions(){
  46. Plugin permissionsPlugin = this.getServer().getPluginManager().getPlugin("Permissions");
  47. if (permissionsPlugin == null) {
  48. this.logger.info("Permission system not detected, defaulting to OP");
  49. return;
  50. }
  51. permissionHandler = ((Permissions) permissionsPlugin).getHandler();
  52. this.logger.info("Found and will use plugin "+((Permissions)permissionsPlugin).getDescription().getFullName());
  53. }
  54. public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] arg){
  55. readCommand((Player) sender, commandLable, arg);
  56. return false;
  57. }
  58. public void readCommand(Player player, String cmd, String[] arg){
  59. try
  60. {
  61. if(cmd.equalsIgnoreCase("dwarf") && !player.hasPermission("Dwarflater.Dwarf") && !Dwarflater.permissionHandler.has(player, "Dwarflater.Dwarf")){
  62. player.sendMessage("Dwarven is not in your dictionary. Learn it from your admins or do a self study");
  63. return ;
  64. }
  65. if(cmd.equalsIgnoreCase("dwarfauto") && !player.hasPermission("Dwarflater.DwarfAuto") && !Dwarflater.permissionHandler.has(player, "Dwarflater.DwarfAuto")){
  66. player.sendMessage("You do not have permission to use the dwarven transelate rune.");
  67. return ;
  68. }
  69. String newWords = "dwarf";
  70. if(cmd.equalsIgnoreCase("dwarf")){
  71. if(arg != null && arg.length != 0){
  72. newWords = TranselateWoord(arg[0]);
  73. for(int i = 1; i < arg.length; i++){
  74. newWords += " "+TranselateWoord(arg[i]);
  75. }
  76. if(!newWords.equals(""))
  77. player.chat(newWords);
  78. else
  79. return ;
  80. }
  81. else {
  82. player.sendMessage(ChatColor.RED + "/dwarf <string>");
  83. }
  84. }
  85. if(cmd.equalsIgnoreCase("dwarfauto")){
  86. this.dwAuto = !this.dwAuto;
  87. if(this.dwAuto)
  88. player.sendMessage(ChatColor.GOLD + "Dwarven transelate rune is enabled. Your words will automatically be transelated to dwarven");
  89. else
  90. player.sendMessage(ChatColor.GOLD + "Dwarven transelate rune is disebled. Your words won't be transelated to dwarven");
  91. }
  92. } catch(CommandException e){
  93. logger.info("Dwarven is not supported by the consele. go ingame or transelate by hand.");
  94. }
  95. }
  96. public String TranselateWoord(String woord){
  97. String newwoord = "";
  98. try
  99. {
  100. if(woords.keyExists(woord.toLowerCase())){
  101. newwoord = woords.getString(woord.toLowerCase());
  102. }
  103. else
  104. {
  105. newwoord = woord;
  106. }
  107. return newwoord;
  108. }
  109. catch(Exception Nulle)
  110. {
  111. return woord;
  112. }
  113. }
  114. }