Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.95 KB | None | 0 0
  1. //This is where the bulk of the plugin is
  2. import java.util.logging.Logger;
  3. import java.util.logging.Level;
  4. public class vminecraft extends Plugin {
  5.     //settings Settings;
  6.     @Override
  7.     public void disable() {
  8.         //throw new UnsupportedOperationException("Not supported yet.");
  9.         //I have to include this to compile, not sure why.
  10.     }
  11.  
  12.     @Override
  13.     public void enable() {
  14.         //throw new UnsupportedOperationException("Not supported yet.");
  15.         //I have to include this to compile, not sure why.
  16.     }
  17.     static final Logger log = Logger.getLogger("Minecraft");
  18.  
  19.     @Override
  20.     public void onLogin(Player player)
  21.     {
  22.         settings.getInstance().loadSettings();
  23.     }
  24.  
  25.     public boolean onChat(Player player, String message){
  26.         //Settings.loadSettings();
  27.         settings.getInstance().loadSettings();
  28.         String playerb = player.getName(); //Used to get names from players, can't remember why I can't just use 'player'
  29.         String temp2 = "<" + player.getColor() + player.getName()  +  Colors.White +"> "; //Inserts a name before the message
  30.         String adminchat = Colors.DarkPurple + "{" + player.getColor() + player.getName()  +  Colors.DarkPurple +"}" + Colors.White + " "; //Inserts names admin chat style before the message
  31.         String message2 = ""; //Used for greentext and FFF
  32.         String check = temp2+message; //Calculates how long your message will be including your name in the equation, this prevents minecraft clients from crashing when a color code is inserted after a linebreak
  33.         if (settings.getInstance().adminchat()&&message.startsWith("@") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins"))) {
  34.             for (Player p : etc.getServer().getPlayerList()) {
  35.  
  36.                 if (p != null) {
  37.                     if (player.isInGroup("mods") || (player.isInGroup("admins")) || (player.isInGroup("superadmins"))) {
  38.                         String blaa = "";
  39.                         for ( int x = 1; x< message.length(); x++) {
  40.                         blaa+=message.charAt(x);
  41.                         }
  42.                         if (p.isInGroup("superadmins") || p.isInGroup("mods") || p.isInGroup("admins")){
  43.                         if (p != null) {
  44.                                 p.sendMessage(adminchat+blaa);
  45.                            }
  46.                         }
  47.                         log.log(Level.INFO, "@"+adminchat+blaa);
  48.                                                 }
  49.                                 }      
  50.                     }
  51.             return true;
  52.       }
  53.         //Greentext
  54.         if (settings.getInstance().greentext()&&message.startsWith(">")) {
  55.             id.a.log(Level.INFO, "<"+player.getName()+"> "+message);
  56.             message = Colors.LightGreen + message;
  57.             message2 = temp2 + message;
  58.             other.gmsg(message2);
  59.            
  60.             return true;
  61.         }
  62.         //FFF
  63.         if (settings.getInstance().FFF()&&message.startsWith("FFF")) {
  64.             id.a.log(Level.INFO, "<"+player.getName()+"> "+message);
  65.             message = Colors.Red + message;
  66.             message2 = temp2 + message;
  67.             other.gmsg(message2);
  68.            
  69.             return true;
  70.         }
  71.         //QuakeColors
  72.         if(settings.getInstance().quakeColors()&&message.length()>2 && lengthCheck(check)) {
  73.             String temp = "";
  74.             for(int x = 0; x< message.length(); x++)
  75.             {
  76.                 if(message.charAt(x)=='^'&&x!=message.length()-1)
  77.                 {
  78.                     temp+=colorChange(message.charAt(x+1));
  79.                     x+=1;
  80.                 }
  81.                 else{
  82.                     temp+=message.charAt(x);
  83.                 }
  84.             }
  85.                         log.log(Level.INFO, "<"+player.getName()+"> "+message);
  86.             message = temp2 + temp + " ";
  87.                         for (Player p : etc.getServer().getPlayerList()) {
  88.                                 if (p != null) {
  89.                                      other.gmsg(message);
  90.                                      
  91.                                      return true;
  92.                                 }
  93.                             }                                                
  94.         }
  95.         return false;
  96.     }
  97.     public boolean onCommand(Player player, String[] split) {
  98.         if(!player.canUseCommand(split[0])) {
  99.            return false;
  100.         }
  101.         //Fabulous
  102.         if (split[0].equalsIgnoreCase("/fabulous")&&settings.getInstance().cmdFabulous()) {
  103.             etc.getInstance().addCommand("/fabulous", "/fabulous <message>");
  104.                     if (split.length == 1) {return false;}
  105.                     String temp = "";
  106.                     String str = "";
  107.                     //str = paramString.substring(paramString.indexOf(" ")).trim();
  108.                     str = etc.combineSplit(1, split, " ");
  109.                     String temp2 = "<" + player.getName()  + "> "+str;
  110.                     String[] rainbow = new String[] {Colors.Red, Colors.Rose, Colors.Yellow, Colors.Green, Colors.Blue, Colors.LightPurple, Colors.Purple};
  111.                     int counter=0;
  112.                     if(lengthCheck(temp2))
  113.                     {
  114.                            id.a.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\"");
  115.                     for(int x=0; x<str.length(); x++)
  116.                     {
  117.                             temp+=rainbow[counter]+str.charAt(x);
  118.                             counter++;
  119.                             if(str.charAt(x)==' ') { counter--;}
  120.                             if(counter==-1){counter = 6; }
  121.                             if(counter==7){counter = 0; }
  122.                     }
  123.                     str = temp+" ";
  124.                     String message = "<" + player.getColor() + player.getName() + Colors.White + "> " + str;
  125.                            
  126.                             other.gmsg(message);
  127.                     } else {
  128.                             player.sendMessage(Colors.Rose + "Message is too long");
  129.                     }
  130.                 }
  131.         //Promote
  132.         else if (settings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote"))
  133. {
  134.     if(split.length != 2)
  135.     {
  136.         player.sendMessage(Colors.Rose + "Usage is /promote [Player]");
  137.     }
  138.  
  139.     Player playerTarget = null;
  140.  
  141.     for( Player p : etc.getServer().getPlayerList())
  142.     {
  143.         if (p.getName().equalsIgnoreCase(split[1]))
  144.         {
  145.             playerTarget = p;
  146.         }
  147.     }
  148.  
  149.     if( playerTarget!=null)
  150.     {
  151.         if(playerTarget.isInGroup("admins"))
  152.         {
  153.             player.sendMessage(Colors.Rose + "You can not promote " + split[1] + " any higher.");
  154.         }
  155.         if(playerTarget.isInGroup("mods") && (player.isInGroup("superadmins")))
  156.         {
  157.             playerTarget.setGroups(ranks.Admins);
  158.             etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  159.             String message = Colors.Yellow + split[1] + " was promoted to" + Colors.Rose + " Admin";
  160.             other.gmsg(message);
  161.         }
  162.         else if (playerTarget.isInGroup("trusted") && (player.isInGroup("admins") || player.isInGroup("superadmins")))
  163.         {
  164.             playerTarget.setGroups(ranks.Mods);
  165.             etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  166.             String message = Colors.Yellow + split[1] + " was promoted to" + Colors.DarkPurple + " Mod";
  167.             other.gmsg(message);
  168.         }
  169.         else if (playerTarget.isInGroup("default") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins")))
  170.         {
  171.             playerTarget.setGroups(ranks.Trusted);
  172.                         etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  173.                         String message = Colors.Yellow + split[1] + " was promoted to" + Colors.LightGreen + " Trusted";
  174.                         other.gmsg(message);
  175.         }
  176.     }
  177.     else{
  178.         player.sendMessage(Colors.Rose + "Player not found");
  179.     }
  180.     log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
  181. }
  182.         //Demote
  183.                 else if (settings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote"))
  184. {
  185.     if(split.length != 2)
  186.     {
  187.         player.sendMessage(Colors.Rose + "Usage is /demote [Player]");
  188.     }
  189.  
  190.     Player playerTarget = null;
  191.  
  192.     for( Player p : etc.getServer().getPlayerList())
  193.     {
  194.         if (p.getName().equalsIgnoreCase(split[1]))
  195.         {
  196.             playerTarget = p;
  197.         }
  198.     }
  199.  
  200.     if( playerTarget!=null)
  201.     {
  202.         if(playerTarget.isInGroup("admins") && (player.isInGroup("superadmins")))
  203.         {
  204.                     playerTarget.setGroups(ranks.Mods);
  205.                     etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  206.                     String message = Colors.Yellow + split[1] + " was demoted to" + Colors.DarkPurple + " Mod";
  207.                     other.gmsg(message);
  208.         }
  209.         if(playerTarget.isInGroup("mods") && (player.isInGroup("admins") || player.isInGroup("superadmins")))
  210.         {
  211.             playerTarget.setGroups(ranks.Trusted);
  212.             etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  213.             String message = Colors.Yellow + split[1] + " was demoted to" + Colors.LightGreen + " Trusted";
  214.             other.gmsg(message);
  215.         }
  216.         else if (playerTarget.isInGroup("trusted") && (player.isInGroup("mods") || player.isInGroup("superadmins") || player.isInGroup("admins")))
  217.         {
  218.             playerTarget.setGroups(ranks.Def);
  219.             etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  220.             String message = Colors.Yellow + split[1] + " was demoted to" + Colors.White + " Default";
  221.             other.gmsg(message);
  222.         }
  223.         else if (playerTarget.isInGroup("default") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins")))
  224.         {
  225.                 player.sendMessage(Colors.Rose + "You can not demote " + split[1] + " any lower.");
  226.         }
  227.     }
  228.     else{
  229.         player.sendMessage(Colors.Rose + "Player not found");
  230.     }
  231.     log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
  232. }
  233.           //Whois will display info about a player
  234.          else if (settings.getInstance().cmdWhoIs()&&split[0].equalsIgnoreCase("/whois")) {
  235.             String admin ="";
  236.             String group ="";
  237.             String ignore ="";
  238.                     log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
  239.                     etc.getInstance().addCommand("/whois", "/whois [user]");
  240.                 if (split.length < 2) {
  241.                     player.sendMessage(Colors.Rose + "Usage is /whois [player]");
  242.             }
  243.                     if (player.canIgnoreRestrictions()) {
  244.                         ignore = "True";
  245.                     } else {
  246.                             ignore ="False";
  247.                         }
  248.                     if (player.canIgnoreRestrictions()) {
  249.                         admin = "True";
  250.                     } else {
  251.                         admin = "False";
  252.             }
  253.                     if (player.isInGroup("superadmins")){
  254.                         group = "superadmins";
  255.             }else if(player.isInGroup("admins")){
  256.                 group = "admins";
  257.                     }else if(player.isInGroup("mods")){
  258.                         group = "mods";
  259.                     }else if(player.isInGroup("trusted")){
  260.                         group = "trusted";
  261.                     }else{
  262.                         group = "Default";
  263.                         }
  264.                     player.sendMessage(Colors.LightGreen + "Info for "+split[1]+": Admin("+admin+") Ignoresrestrictions("+ignore+") Group("+group+").");
  265.                   } else if(split[0].equalsIgnoreCase("/say")) {
  266.                       String sayan;
  267.                       sayan = etc.combineSplit(1, split, " ");
  268.                       other.gmsg(Colors.Yellow+sayan);
  269.                       //Should make a global message to all players
  270.                   }
  271.  
  272.          else {
  273.             return false;
  274.         }
  275.         return true;
  276.     }
  277.  
  278.     public void onKick(Player player, String reason)
  279.     {
  280.     }
  281.  
  282.  
  283.  
  284.  
  285.     //Calculates how long the specified String is to prevent linebreaks when using scripts that insert color codes, designed to be used with playername included
  286.     private boolean lengthCheck(String str)
  287.     {
  288.         int length = 0;
  289.         for(int x = 0; x<str.length(); x++)
  290.         {
  291.             if("i;,.:|!".indexOf(str.charAt(x)) != -1)
  292.             {
  293.                 length+=2;
  294.             }
  295.             else if("l'".indexOf(str.charAt(x)) != -1)
  296.             {
  297.                 length+=3;
  298.             }
  299.             else if("tI[]".indexOf(str.charAt(x)) != -1)
  300.             {
  301.                 length+=4;
  302.             }
  303.             else if("kf{}<>\"*()".indexOf(str.charAt(x)) != -1)
  304.             {
  305.                 length+=5;
  306.             }
  307.             else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1)
  308.             {
  309.                 length+=6;
  310.             }
  311.             else if("@~".indexOf(str.charAt(x)) != -1)
  312.             {
  313.                 length+=7;
  314.             }
  315.             else if(str.charAt(x)==' ')
  316.             {
  317.                 length+=4;
  318.             }
  319.         }
  320.         if(length<=316)
  321.         {
  322.             return true;
  323.         } else { return false; }
  324.  
  325.     }
  326.     //QuakeColors Part 2
  327.     private String colorChange(char colour)
  328.     {
  329.         String color = "";
  330.         switch(colour)
  331.         {
  332.             case '0':
  333.                 color = Colors.Black;
  334.                 break;
  335.             case '1':
  336.                 color = Colors.Navy;
  337.                 break;
  338.             case '2':
  339.                 color = Colors.Green;
  340.                 break;
  341.             case '3':
  342.                 color = Colors.Blue;
  343.                 break;
  344.             case '4':
  345.                 color = Colors.Red;
  346.                 break;
  347.             case '5':
  348.                 color = Colors.Purple;
  349.                 break;
  350.             case '6':
  351.                 color = Colors.Gold;
  352.                 break;
  353.             case '7':
  354.                 color = Colors.LightGray;
  355.                 break;
  356.             case '8':
  357.                 color = Colors.Gray;
  358.                 break;
  359.             case '9':
  360.                 color = Colors.DarkPurple;
  361.                 break;
  362.             case 'a':
  363.                 color = Colors.LightGreen;
  364.                 break;
  365.             case 'b':
  366.                 color = Colors.LightBlue;
  367.                 break;
  368.             case 'c':
  369.                 color = Colors.Rose;
  370.                 break;
  371.             case 'd':
  372.                 color = Colors.LightPurple;
  373.                 break;
  374.             case 'e':
  375.                 color = Colors.Yellow;
  376.                 break;
  377.             case 'f':
  378.                 color = Colors.White;
  379.                 break;
  380.             case 'A':
  381.                 color = Colors.LightGreen;
  382.                 break;
  383.             case 'B':
  384.                 color = Colors.LightBlue;
  385.                 break;
  386.             case 'C':
  387.                 color = Colors.Rose;
  388.                 break;
  389.             case 'D':
  390.                 color = Colors.LightPurple;
  391.                 break;
  392.             case 'E':
  393.                 color = Colors.Yellow;
  394.                 break;
  395.             case 'F':
  396.                 color = Colors.White;
  397.                 break;
  398.             default:
  399.                 color = Colors.White;
  400.                 break;
  401.         }
  402.         return color;
  403.     }
  404. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement