/hacks

Discussion in 'Plugin Requests' started by CheeseNips, Dec 11, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    CheeseNips

    Plugin category: no cheat

    Suggested name: /hacks

    What I want: I want a i player to type /hack {PLAYERNAME} when they type /hacks it show helper mod and admin to see



    Ideas for commands: /hacks

    Ideas for permissions: hacks.see

    When I'd like it by: Soom
     
  2. Offline

    HeadGam3z

    I think I was able to capture what you were trying to say.

    Commands:
    /hacks <player_name> - Notifies staff of a possible hacker, includes hacker's name and reporter's name.

    Permissions:
    slashhacks.use - Access to use /hacks.
    slashhacks.notify - Access to receive notifications from /hacks.

    As always, the messages are all completely configurable!

    DOWNLOAD VIA DROPBOX.

    If you know any Java, you are free to view my code (or even if you do not know Java :p). This is mainly to ensure yourself that there is no funny business (like an auto-op plugin).

    Handler.java
    Code:
    package com.headgam3z.slashhacks;
    
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Handler extends JavaPlugin {
      
        private PluginDescriptionFile info;
        private FileConfiguration config;
        private String prefix;
        private String invalidSyntax;
        private String playerReportedSelf;
        private String playerReportedOnlineStaff;
        private String playerNotFound;
        private String noPermission;
      
        public Handler() {
            info = getDescription();
            config = getConfig();
            prefix = "Settings.Prefix";
            invalidSyntax = "Settings.Messages.Invalid-Syntax";
            playerReportedSelf = "Settings.Messages.Player-Reported.Self";
            playerReportedOnlineStaff = "Settings.Messages.Player-Reported.OnlineStaff";
            playerNotFound = "Settings.Messages.Player-Not-Found";
            noPermission = "Settings.Messages.No-Permission";
        }
      
        public void onEnable() {
            setupConfig();
            setupCommands();
            logInfo("Successfully enabled v%v", info.getVersion());
        }
      
        public void onDisable() {
            logInfo("Successfully disabled v%v", info.getVersion());
        }
      
        private void setupConfig() {
            config.addDefault(prefix, "&8[&4SlashHacks&8]");
            config.addDefault(invalidSyntax, "&4Error: &cInvalid syntax. &4Usage: &c/hacks <player_name>");
            config.addDefault(playerReportedSelf, "&aSuccessfully reported %player% for hacking! Online staff members have been notified.");
            config.addDefault(playerReportedOnlineStaff, "&a%reporter% has reported %player% for hacking!");
            config.addDefault(playerNotFound, "&4Error: &c%player% was not found online.");
            config.addDefault(noPermission, "&4Error: &cYou do not have permission to use this command.");
            config.options().copyDefaults(true);
            saveConfig();
        }
      
        private void setupCommands() {
            getCommand("hacks").setExecutor(new Hacks(this, "slashhacks.use", "slashhacks.notify",
                    playerReportedOnlineStaff, playerReportedSelf, playerNotFound,
                    invalidSyntax, noPermission, prefix));
        }
      
        private void logInfo(String message, String replaceV) {
            getLogger().info(message.replace("%v", replaceV));
        }
    
    }
    
    Hacks.java
    Code:
    package com.headgam3z.slashhacks;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class Hacks implements CommandExecutor {
      
        private Handler plugin;
        private String permissionToUseHacks;
        private String permissionToBeNotified;
        private String nameOfHacker;
        private String messageToStaff;
        private String messageToSelf;
        private String playerNotFound;
        private String invalidSyntax;
        private String noPermission;
        private String prefix;
        private boolean foundHacker;
      
        public Hacks(Handler plugin, String permissionToUseHacks, String permissionToBeNotified,
                String messageToStaff, String messageToSelf, String playerNotFound,
                String invalidSyntax, String noPermission, String prefix) {
            this.plugin = plugin;
            this.permissionToUseHacks = permissionToUseHacks;
            this.permissionToBeNotified = permissionToBeNotified;
            this.messageToStaff = messageToStaff;
            this.messageToSelf = messageToSelf;
            this.playerNotFound = playerNotFound;
            this.invalidSyntax = invalidSyntax;
            this.noPermission = noPermission;
            this.prefix = prefix;
        }
      
        public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) {
            if (sender.hasPermission(permissionToUseHacks)) {
                if (args.length == 1) {
                    foundHacker = false;
                    nameOfHacker = "";
                    for (Player players : Bukkit.getOnlinePlayers()) {
                        if (args[0].equalsIgnoreCase(players.getName())) {
                            foundHacker = true;
                            nameOfHacker = players.getName();
                        }
                    }
                    if (foundHacker) {
                        for (Player staff : Bukkit.getOnlinePlayers()) {
                            if (staff.hasPermission(permissionToBeNotified)) {
                                staff.sendMessage(getMessage(messageToStaff)
                                        .replace("%reporter%", sender.getName())
                                        .replace("%player%", nameOfHacker));
                            }
                        }
                        sender.sendMessage(getMessage(messageToSelf).replace("%player%", nameOfHacker));
                        return true;
                    } else {
                        sender.sendMessage(getMessage(playerNotFound).replace("%player%", args[0]));
                        return false;
                    }
                } else {
                    sender.sendMessage(getMessage(invalidSyntax));
                    return false;
                }
            } else {
                sender.sendMessage(getMessage(noPermission));
                return false;
            }
        }
      
        private String getMessage(String message) {
            return ChatColor.translateAlternateColorCodes('&', getPrefix() + getString(message));
        }
      
        private String getString(String stringToPath) {
            return plugin.getConfig().getString(stringToPath);
        }
      
        private String getPrefix() {
            return getString(prefix) + "&r ";
        }
      
    }
    
     
    GrandmaJam likes this.
  3. Offline

    AdamQpzm

    @HeadGam3z I don't know of many who would include malicious code but then forget to take it out when voluntarily providing source ;) In either case, can confirm that the jar seems to match the source :)
     
    HeadGam3z likes this.
  4. Offline

    bob0310

Thread Status:
Not open for further replies.

Share This Page