Minecraft PC IP: play.cubecraft.net

DrHam

Forum Veteran
Sep 15, 2015
3,615
4,165
518
Kepler-452b
The title is 10/10

Thi is a "guide"/tutorial/something that help you understand how "Advanced Reports" works, quite simple and easy to explain


There isn't the command executor thing, why? I am lazy.
Code:
package eu.hangar;
 
 
 
 
import java.util.List;
 
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
 
public class Main extends JavaPlugin implements Listener {
 
 
    public void onEnable(){   //config requirments
        getServer().getPluginManager().registerEvents(this, this);
        getConfig().options().copyDefaults(true);
        saveConfig();
        }
     
 
      List<String> Reports = getConfig().getStringList("Reports"); //creates the list
       public boolean onCommand(CommandSender sender, Command cmd, String aliases,
                String[] args) {
 
            if (cmd.getName().equalsIgnoreCase("report")) { //command
               Player p = (Player) sender;
                if (args.length == 0) { //gets the args
                    if(!p.hasPermission("report.staff")){ //! means no
                       p.sendMessage(ChatColor.GREEN +""+ ChatColor.STRIKETHROUGH +"=                                                   =");
                       p.sendMessage(ChatColor.BLUE + "Usage:");
                       p.sendMessage(ChatColor.BLUE + "/report player <playername> will report a player");
                       p.sendMessage(ChatColor.BLUE + "/report check <playername> will check if the player is reported");
                       p.sendMessage(ChatColor.GREEN +""+ ChatColor.STRIKETHROUGH +"=                                                   =");
                    }else{ //if they di have perms
                         p.sendMessage(ChatColor.GREEN +""+ ChatColor.STRIKETHROUGH +"=                                                   =");
                           p.sendMessage(ChatColor.BLUE + "Usage:");
                           p.sendMessage(ChatColor.BLUE + "/report player <playername> will report a player");
                           p.sendMessage(ChatColor.BLUE + "/report claim <playername> will remove the report. TO-DO: TP to the player");
                           p.sendMessage(ChatColor.BLUE + "/report check <playername> will check if the player is reported");
                           p.sendMessage(ChatColor.GREEN +""+ ChatColor.STRIKETHROUGH +"=                                                   =");
                     
                    }
                     
                }
                if (args.length == 2) {
                    Player target = Bukkit.getPlayer(args[1]); //the target, needs to be bungee
 
                 
                    if (args[0].equalsIgnoreCase("player")) {
                        if(target != null){ //checks if the target exists
                         if (!Reports.contains(args[1])){
                            p.sendMessage(ChatColor.BLUE + target.getName() + " was reported. Report ID " + target.getUniqueId());
                            Reports.add(target.getName().toString()); //adds the player to the list, reason of why it is not possible to bypass
                       
                         }else{ //the player is reported
                            p.sendMessage(ChatColor.RED + "That player is alredy reported! ");
                            return true;
                        }
                        }else{ //the targte doesn't exists
                            p.sendMessage(ChatColor.RED + "Invalid player");
                        }
                    }
 
                    if (args[0].equalsIgnoreCase("check")) {
                       if(target !=null){
                         
                       if(args.length !=2){ //missing arguments
                           p.sendMessage(ChatColor.RED + "Not enough arguments");
                       }
                       else if (!Reports.contains(args[1])) {//wheres that player?
                                p.sendMessage(ChatColor.BLUE + "That player was never reported");
                             }else{//the target is reported
                                 p.sendMessage(ChatColor.BLUE + "That player was reported");
                                 return true;
                        }
                    }else{
                        p.sendMessage(ChatColor.RED + "Invalid player");
                    }
                    }
                    if (args[0].equalsIgnoreCase("claim")) {
                      if(p.hasPermission("report.claim")){
                        if (target != null) {
                          Reports.remove(args[1]);//bye bye reported
                          p.sendMessage(ChatColor.BLUE + "Report claimed");
                          p.teleport(target); //;-;
                          return true;
                        }else{
                            p.sendMessage(ChatColor.RED + "Invalid player");
                    }
                }else{ //perms
                    p.sendMessage(ChatColor.RED + "Not enough permissions");
                }
            }
            return true;
        }
            return true;
 
    }
            return true;
}}


If someone could "improve" the code, give me tips, etc, I'd be very happy
 

DrHam

Forum Veteran
Sep 15, 2015
3,615
4,165
518
Kepler-452b
Traducido el funcionamineto a español


Code:
package eu.hangar;
 
 
 
 
import java.util.List;
 
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
 
public class Main extends JavaPlugin implements Listener {
 
 
    public void onEnable(){   //config.yml
        getServer().getPluginManager().registerEvents(this, this);
        getConfig().options().copyDefaults(true);
        saveConfig();
        }
  
 
      List<String> Reports = getConfig().getStringList("Reports"); //crea la lista
       public boolean onCommand(CommandSender sender, Command cmd, String aliases,
                String[] args) {
 
            if (cmd.getName().equalsIgnoreCase("report")) { //comando
               Player p = (Player) sender;
                if (args.length == 0) { //gets the args
                    if(!p.hasPermission("report.staff")){ //! significa no
                       p.sendMessage(ChatColor.GREEN +""+ ChatColor.STRIKETHROUGH +"=                                                   =");
                       p.sendMessage(ChatColor.BLUE + "Usage:");
                       p.sendMessage(ChatColor.BLUE + "/report player <playername> will report a player");
                       p.sendMessage(ChatColor.BLUE + "/report check <playername> will check if the player is reported");
                       p.sendMessage(ChatColor.GREEN +""+ ChatColor.STRIKETHROUGH +"=                                                   =");
                    }else{ //if they di have perms
                         p.sendMessage(ChatColor.GREEN +""+ ChatColor.STRIKETHROUGH +"=                                                   =");
                           p.sendMessage(ChatColor.BLUE + "Usage:");
                           p.sendMessage(ChatColor.BLUE + "/report player <playername> will report a player");
                           p.sendMessage(ChatColor.BLUE + "/report claim <playername> will remove the report. TO-DO: TP to the player");
                           p.sendMessage(ChatColor.BLUE + "/report check <playername> will check if the player is reported");
                           p.sendMessage(ChatColor.GREEN +""+ ChatColor.STRIKETHROUGH +"=                                                   =");
                  
                    }
                  
                }
                if (args.length == 2) {
                    Player target = Bukkit.getPlayer(args[1]); //crea el objetivo
 
              
                    if (args[0].equalsIgnoreCase("player")) {
                        if(target != null){ //checks if the target exists
                         if (!Reports.contains(args[1])){
                            p.sendMessage(ChatColor.BLUE + target.getName() + " was reported. Report ID " + target.getUniqueId());
                            Reports.add(target.getName().toString()); //añade el reporte a la lista

                         }else{ //si el jugador ha sidonreportado....
                            p.sendMessage(ChatColor.RED + "That player is alredy reported! ");
                            return true;
                        }
                        }else{ //the targte doesn't exists
                            p.sendMessage(ChatColor.RED + "Invalid player");
                        }
                    }
 
                    if (args[0].equalsIgnoreCase("check")) {
                       if(target !=null){
                      
                       if(args.length !=2){ //faltan argumentos!
                           p.sendMessage(ChatColor.RED + "Not enough arguments");
                       }
                       else if (!Reports.contains(args[1])) {//El jugador nunca ha sido denunciado
                                p.sendMessage(ChatColor.BLUE + "That player was never reported");
                             }else{//el jugador ha sido reportado
                                 p.sendMessage(ChatColor.BLUE + "That player was reported");
                                 return true;
                        }
                    }else{
                        p.sendMessage(ChatColor.RED + "Invalid player");
                    }
                    }
                    if (args[0].equalsIgnoreCase("claim")) {
                      if(p.hasPermission("report.claim")){
                        if (target != null) {
                          Reports.remove(args[1]);//adios denuncia
                          p.sendMessage(ChatColor.BLUE + "Report claimed");
                          p.teleport(target); //;-;
                          return true;
                        }else{
                            p.sendMessage(ChatColor.RED + "Invalid player");
                    }
                }else{ //permisos
                    p.sendMessage(ChatColor.RED + "Not enough permissions");
                }
            }
            return true;
        }
            return true;
 
    }
            return true;
}}

@HackersDontWin
 

betty's oldies

Forum Expert
It's actually easy. Made it while I was ill, 69/10 coding abilities.




Kids, do not do that unless you want to lose a week of school/high school/college
It's all OOP. The basics aren't hard to learn. It's first with object creation/handling and inheritance. There's much more of course but I don't know the rest besides those.
 
  • Like
Reactions: DrHam
Members Online

Team online

Latest profile posts

Reesle wrote on treegirl0194's profile.
Happy Birthday! 🎂
Reesle wrote on Pro Gamer672's profile.
Happy Birthday! 🎉
Reesle wrote on kfccaleb's profile.
Thank you for the follow, Pro! :D
Casualpoalrbear wrote on PolarBear's profile.
My guy somehow haven't posted a single message or had a single reaction and is somehow a well known member 💀
Top Bottom