Perfection Thread

Discussion in 'Plugin Development' started by HeartandSoul, Aug 24, 2016.

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

    HeartandSoul

    After all the help with this plugin, I have finally finished what I wanted!
    Helped Threads Related To This Plugin (open)


    Before I actually finalize everything, I want an experienced Bukkit API Programmer's opinion. No errors, but I just want to make sure that even someone who knows it more than I says "Everything looks great!"

    Pasting all the classes relating to my cases (The stages of the UHC), along with the events.

    Generation Case (open)

    Code:
    package me.kylethehacker.cases;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.WorldCreator;
    import org.bukkit.WorldType;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.Plugin;
    
    public class Generation{
        public void onGeneration(){
            Plugin plugin = Bukkit.getPluginManager().getPlugin("KTHC");
            FileConfiguration config = plugin.getConfig();
            String uhc = config.getString("world-name");
            final org.bukkit.World uhcw = Bukkit.getServer().getWorld(uhc);
            Bukkit.broadcastMessage(ChatColor.RED + "KTHC >> The UHC world is in generation! Name: " + uhc);
            if(uhcw == null){
                WorldCreator uhcGen = new WorldCreator(uhc);
                uhcGen.generateStructures(true);
                uhcGen.type(WorldType.NORMAL);
                uhcGen.environment(org.bukkit.World.Environment.NORMAL);
                Bukkit.getServer().createWorld(uhcGen);
            } else{
                System.out.println("World wasn't null! You can't use an existing one!");
            }
        }
    }
    

    Worldset Case (open)

    Code:
    package me.kylethehacker.cases;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Difficulty;
    import org.bukkit.World;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.Plugin;
    
    public class Worldset{
        public void onWorldCreation(){
            Plugin plugin = Bukkit.getPluginManager().getPlugin("KTHC");
            FileConfiguration config = plugin.getConfig();
            String uhc = config.getString("world-name");
            final World uhcw = Bukkit.getServer().getWorld(uhc);
            int uhcwb = config.getInt("world-border-size");
            int uhcwbd = config.getInt("world-border-damage");
            //The line below sets the size of the border in the UHC (1000 = 500 from the center)
            uhcw.getWorldBorder().setSize(uhcwb);
            uhcw.getWorldBorder().setWarningDistance(80);
            //The line below sets the amount of hearts to take when player reaches border line.
            uhcw.getWorldBorder().setDamageAmount(uhcwbd);
            uhcw.setDifficulty(Difficulty.HARD);
            uhcw.setGameRuleValue("naturalRegeneration", "false");
        }
    }
    

    Teleportation Case (open)

    Code:
    package me.kylethehacker.cases;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    
    public class Teleportation{
        public void onTeleport(){
            Plugin plugin = Bukkit.getPluginManager().getPlugin("KTHC");
            FileConfiguration config = plugin.getConfig();
            String uhc = config.getString("world-name");
            final World uhcw = Bukkit.getServer().getWorld(uhc);
            Location uhcloc = new Location(uhcw, 0.0, uhcw.getHighestBlockYAt(0, 0), 0.0);
            for(Player p : Bukkit.getOnlinePlayers()){
                p.teleport(uhcloc);
            }
        }
    }
    

    Grace Case (open)

    Code:
    package me.kylethehacker.cases;
    
    import me.kylethehacker.uhc.UhcStages;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.scheduler.BukkitRunnable;
    import org.bukkit.scheduler.BukkitTask;
    
    import java.util.Collection;
    
    public class Grace{
    
        private Plugin plugin = Bukkit.getPluginManager().getPlugin("KTHC");
    
        public void onGraceStart(){
            final UhcStages stages = new UhcStages();
            Plugin plugin = Bukkit.getPluginManager().getPlugin("KTHC");
            FileConfiguration config = plugin.getConfig();
            Collection <? extends Player> allp = Bukkit.getServer().getOnlinePlayers();
            final int[] grace = {config.getInt("grace")};
            for(Player p : allp){
                p.setNoDamageTicks(20 * 60 * grace[0]);
            }
            @SuppressWarnings("UnusedAssignment") BukkitTask task = new BukkitRunnable(){
                public void run(){
                    grace[0]--;
                    if(grace[0] >= 1){
                        Bukkit.broadcastMessage(ChatColor.GREEN + "KTHC >> Grace period active! " + grace[0] + " Minutes Remain!");
                    }else if(grace[0] == 0){
                        stages.uhcState(UhcStages.STATES.START);
                        this.cancel();
                    }
                }
            }.runTaskTimer(this.plugin, 0, 20 * 60);
        }
    }
    

    Start Case (open)

    Code:
    package me.kylethehacker.cases;
    
    import me.kylethehacker.uhc.UhcStages;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.World;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.scheduler.BukkitRunnable;
    import org.bukkit.scheduler.BukkitTask;
    
    public class Start{
    
        private Plugin plugin = Bukkit.getPluginManager().getPlugin("KTHC");
    
        public void onUhcBegin(){
        final UhcStages stages = new UhcStages();
        Plugin plugin = Bukkit.getPluginManager().getPlugin("KTHC");
        FileConfiguration config = plugin.getConfig();
        String uhc = config.getString("world-name");
        final World uhcw = Bukkit.getServer().getWorld(uhc);
        final int dmtime = config.getInt("time-before-deathmatch");
        final int players = config.getInt("players-before-deathmatch");
        final boolean playerCheck = config.getBoolean("enable-player-check");
        final boolean deathmatchCheck = config.getBoolean("enable-deathmatch");
        final int[] counter = {config.getInt("combat")};
        final int onlinePlayers = uhcw.getPlayers().size();
            @SuppressWarnings("UnusedAssignment") BukkitTask task1 = new BukkitRunnable(){
            public void run(){
                counter[0]--;
                Bukkit.broadcastMessage(ChatColor.GREEN + "KTHC >> Combat period active! " + counter[0] + " Minutes To DeathMatch!");
                //System.out.println("START >> Runnable: " + counter[0]);
                if(playerCheck){
                    if(onlinePlayers == 1 && counter[0] > 0){
                        String p = uhcw.getPlayers().get(0).getDisplayName();
                        Bukkit.broadcastMessage(ChatColor.BLUE + "KTHC >> UHC Ended as 1 player remains. Winner: " + p);
                        stages.uhcState(UhcStages.STATES.RETURNING);
                    }
                } else{
                    return;
                }
                if(deathmatchCheck){
                    if(counter[0] > 0 && counter[0] < dmtime){
                        if(onlinePlayers > 0 && onlinePlayers < players){
                            stages.uhcState(UhcStages.STATES.DEATHMATCH);
                        } else{
                            return;
                        }
                    } else{
                        return;
                    }
                } else{
                    return;
                }
                if(counter[0] == 0){
                    this.cancel();
                    stages.uhcState(UhcStages.STATES.RETURNING);
                }
            }
            }.runTaskTimer(this.plugin, 0, 20 * 60);
        }
    }
    

    Deathmatch Case (open)

    Code:
    package me.kylethehacker.cases;
    
    import me.kylethehacker.uhc.UhcStages;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    
    import java.util.Collection;
    
    public class Deathmatch{
    
        public void onDeathmatchStart(){
            final UhcStages stages = new UhcStages();
            Plugin plugin = Bukkit.getPluginManager().getPlugin("KTHC");
            FileConfiguration config = plugin.getConfig();
            final boolean deathmatchCheck = config.getBoolean("enable-deathmatch");
            Collection <? extends Player> allp = Bukkit.getServer().getOnlinePlayers();
            String dm = config.getString("world-deathmatch");
            World dmw = Bukkit.getServer().getWorld(dm);
            final int onlinePlayersDM = dmw.getPlayers().size();
            Location dmloc = new Location(dmw, 0.0, dmw.getHighestBlockYAt(0, 0), 0.0);
            if(deathmatchCheck){
                for(Player p2 : allp){
                    p2.teleport(dmloc);
                }
            } else{
                return;
            }
            if(onlinePlayersDM == 1){
                String p1 = dmw.getPlayers().get(0).getDisplayName();
                Bukkit.broadcastMessage(ChatColor.BLUE + "KTHC >> UHC Ended as 1 player remains. Winner: " + p1);
                stages.uhcState(UhcStages.STATES.RETURNING);
            }
        }
    }
    

    Returning Case (open)

    Code:
    package me.kylethehacker.cases;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    
    import java.util.Collection;
    
    public class Returning{
        public void onReturn(){
            Plugin plugin = Bukkit.getPluginManager().getPlugin("KTHC");
            FileConfiguration config = plugin.getConfig();
            @SuppressWarnings("UnusedAssignment") Collection <? extends Player> allp = Bukkit.getServer().getOnlinePlayers();
            String worldret = config.getString("world-returns");
            World back = Bukkit.getServer().getWorld(worldret);
            if(back == null){
                System.out.println("The world in 'world-returns' was null!");
                Bukkit.getServer().shutdown();
            }
            Bukkit.broadcastMessage(ChatColor.GREEN + "KTHC >> The UHC Has Ended!");
            Collection <? extends Player> allp2 = Bukkit.getServer().getOnlinePlayers();
            for(Player p : allp2){
                Location spawnloc = new Location(back, 0.0, back != null ? back.getHighestBlockYAt(0, 0) : 0, 0.0);
                p.teleport(spawnloc);
            }
        }
    }
    

    config.yml (open)

    Code:
    combat: 30
    grace: 10
    world-border-size: 1000
    world-border-damage: 4
    players-before-deathmatch: 5
    time-before-deathmatch: 5
    world-name: uhc
    world-deathmatch: nullworld
    world-returns: nullworld
    enable-deathmatch: false
    enable-player-check: false

    UhcStages (open)

    Code:
    package me.kylethehacker.uhc;
    
    import me.kylethehacker.KTHC;
    import me.kylethehacker.cases.*;
    import org.bukkit.event.Listener;
    
    public class UhcStages implements Listener{
    
        public UhcStages(){
        
        }
    
        public enum STATES{
            //These are in order, from World generation to end.
            GENERATION, WORLDSET, TELEPORTATION, GRACE, START, DEATHMATCH, RETURNING, END, CANCEL
        }
    
        KTHC plugin;
    
        public UhcStages(KTHC plugin){
            this.plugin = plugin;
        }
    
        public void uhcState(STATES state){
            Generation generation = new Generation();
            Worldset worldset = new Worldset();
            Teleportation teleportation = new Teleportation();
            Grace grace = new Grace();
            Start start = new Start();
            Deathmatch deathmatch = new Deathmatch();
            Returning returning = new Returning();
            switch (state){
                case GENERATION:
                    generation.onGeneration();
                    uhcState(STATES.WORLDSET);
                    break;
                case WORLDSET:
                    worldset.onWorldCreation();
                    uhcState(STATES.TELEPORTATION);
                    break;
                case TELEPORTATION:
                    teleportation.onTeleport();
                    uhcState(STATES.GRACE);
                    break;
                case GRACE:
                    grace.onGraceStart();
                    break;
                case START:
                    start.onUhcBegin();
                    break;
                case DEATHMATCH:
                    deathmatch.onDeathmatchStart();
                    uhcState(STATES.END);
                    break;
                case RETURNING:
                    returning.onReturn();
                    uhcState(STATES.END);
                    break;
                case END:
            
                case CANCEL:
                    System.out.println("UHC Cancelled (CANCEL case called)");
                    break;
            }
        }
    }
    

    Uhc (open)

    Code:
    package me.kylethehacker.uhc;
    
    import me.kylethehacker.KTHC;
    import me.kylethehacker.recipes.GoldenHead;
    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;
    import org.bukkit.event.Listener;
    import org.bukkit.scoreboard.*;
    
    public class Uhc extends UhcStages implements CommandExecutor, Listener{
    
        private final GoldenHead recipes = new GoldenHead();
    
        public Uhc(KTHC plugin){
            super(plugin);
        }
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String string, String[] args){
            if(sender instanceof Player){
                Player p = (Player) sender;
                if(cmd.getName().equalsIgnoreCase("uhc")){
                    if (args.length == 0){
                        return true;
                    }
                    //Args (/uhc <args>)
                    if (args[0].equalsIgnoreCase("begin")){
                        uhcState(STATES.GENERATION);
                        recipes.addRecipes();
                    }else if (args[0].equalsIgnoreCase("end")){
                        uhcState(STATES.END);
                    }else if (args[0].equalsIgnoreCase("recipe")){
                        if (args.length == 1){
                            return true;
                        }
                        //Recipe Args (/uhc recipe <args>)
                        if (args[1].equalsIgnoreCase("add")){
                            recipes.addRecipes();
                        }else if (args[1].equalsIgnoreCase("remove")){
                            recipes.removeRecipes();
                        }else if (args[1].equalsIgnoreCase("view")){
                            recipes.viewRecipes(p);
                        }
                    }else if (args[0].equalsIgnoreCase("scoreboard")){
                        if (args.length == 1){
                            return true;
                        }
                        //Scoreboard Args (/uhc scoreboard <args>)
                        if (args[1].equalsIgnoreCase("enable")){
                            ScoreboardManager manager = Bukkit.getScoreboardManager();
                            Scoreboard board = manager.getNewScoreboard();
                            Objective obje = board.registerNewObjective("main", "dummy");
                            obje.setDisplayName(ChatColor.GREEN + "KTHC");
                            obje.setDisplaySlot(DisplaySlot.SIDEBAR);
                            Objective obje2 = board.registerNewObjective("time", "dummy");
                            Score time = obje2.getScore(ChatColor.GREEN + "Time: ");
                            time.setScore(1);
                            obje2.setDisplaySlot(DisplaySlot.SIDEBAR);
                            Objective obje3 = board.registerNewObjective("kills", "dummy");
                            Score kills = obje3.getScore(ChatColor.GREEN + "Kills: ");
                            kills.setScore(1);
                            obje3.setDisplaySlot(DisplaySlot.SIDEBAR);
                            for (Player temp : Bukkit.getOnlinePlayers()) {
                                temp.setScoreboard(board);
                            }
                        }else if (args[1].equalsIgnoreCase("disable")) {
                            ScoreboardManager manager = Bukkit.getScoreboardManager();
                            for (Player temp : Bukkit.getOnlinePlayers()) {
                                temp.setScoreboard(manager.getNewScoreboard());
                            }
                        }
                    }
                }
            }
            return true;
        }
    }


    Events:

    GoldenHeadEat (open)

    Code:
    package me.kylethehacker.eventhc;
    
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class GoldenHeadEat implements Listener{
    
        @EventHandler(priority = EventPriority.LOW)
        public void onGoldenHeadEat(PlayerInteractEvent e){
            Player p = e.getPlayer();
            ItemStack p1 = p.getInventory().getItemInHand();
            ItemMeta gmeta = p1.getItemMeta();
            if(e.getAction() == Action.RIGHT_CLICK_AIR){
                if(p1.getType() == Material.SKULL_ITEM){
                    if(gmeta.getDisplayName().equals("§6§lGolden Head")){
                        System.out.println("onEat() Event Read!");
                        p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 20 * 5, 2));
                        gmeta.setDisplayName("§7Used Golden Head");
                        p1.setItemMeta(gmeta);
                        p1.setType(Material.COAL);
                    } else{
                        return;
                    }
                } else{
                    return;
                }
            } else{
                return;
            }
        }
    }
    

    SoulDrop (open)

    Code:
    package me.kylethehacker.eventhc;
    
    import me.kylethehacker.KTHC;
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class SoulDrop implements Listener{
    
        private final KTHC plugin;
    
        public SoulDrop(KTHC plugin){
            this.plugin = plugin;
        }
    
        @EventHandler(priority = EventPriority.LOW)
        public void onPlayerDeath(PlayerDeathEvent e){
            String uhc = plugin.getConfig().getString("world-name");
            World uhcw = Bukkit.getServer().getWorld(uhc);
            String dm = plugin.getConfig().getString("world-deathmatch");
            World dmw = Bukkit.getServer().getWorld(dm);
            Player deadp = e.getEntity();
            if(deadp != null){
                if(deadp.getWorld() == uhcw){
                    ItemStack soul = new ItemStack(Material.PRISMARINE_CRYSTALS, 1);
                    ItemMeta soulm = soul.getItemMeta();
                    soulm.setDisplayName("§r§l" + deadp.getDisplayName() + "'s Soul");
                    soul.setItemMeta(soulm);
                    e.getDrops().clear();
                    e.getDrops().add(soul);
                } else if(deadp.getWorld() == dmw){
                    return;
                } else{
                    return;
                }
            } else{
                return;
            }
        }
    }
    


    Recipes:

    GoldenHead (Contains All Recipes) (open)

    Code:
    package me.kylethehacker.recipes;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class GoldenHead implements Listener{
    
        private ShapedRecipe goldenHead(){
            ItemStack ghi = new ItemStack(Material.SKULL_ITEM, 1);
            ItemMeta ghm = ghi.getItemMeta();
            ghm.setDisplayName("§6§lGolden Head");
            ghi.setItemMeta(ghm);
            ShapedRecipe goldhead = new ShapedRecipe(ghi);
            goldhead.shape("GGG", "GHG", "GGG");
            goldhead.setIngredient('G', Material.GOLD_INGOT);
            goldhead.setIngredient('H', Material.PRISMARINE_CRYSTALS);
            return goldhead;
        }
    
        private ShapedRecipe swordExcalibur(){
            ItemStack exi = new ItemStack(Material.GOLD_SWORD, 1);
            exi.addEnchantment(Enchantment.DAMAGE_ALL, 5);
            exi.addEnchantment(Enchantment.DURABILITY, 1);
            ItemMeta exm = exi.getItemMeta();
            exm.setDisplayName("§6Excalibur");
            exi.setItemMeta(exm);
            ShapedRecipe excalibur = new ShapedRecipe(exi);
            excalibur.shape(" OG", " OG", " S ");
            excalibur.setIngredient('G', Material.GOLD_INGOT);
            excalibur.setIngredient('O', Material.OBSIDIAN);
            excalibur.setIngredient('S', Material.STICK);
            return excalibur;
        }
    
        private ShapedRecipe tarnHelm(){
            ItemStack thi = new ItemStack(Material.DIAMOND_HELMET, 1);
            thi.addEnchantment(Enchantment.DURABILITY, 1);
            thi.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 3);
            ItemMeta thm = thi.getItemMeta();
            thm.setDisplayName("§bTarnhelm");
            thi.setItemMeta(thm);
            ShapedRecipe tarnhelm = new ShapedRecipe(thi);
            tarnhelm.shape("DFD", "D D", "   ");
            tarnhelm.setIngredient('D', Material.DIAMOND);
            tarnhelm.setIngredient('F', Material.ANVIL);
            return tarnhelm;
        }
    
        public void addRecipes(){
            Bukkit.getServer().addRecipe(goldenHead());
            Bukkit.getServer().addRecipe(swordExcalibur());
            Bukkit.getServer().addRecipe(tarnHelm());
        }
    
        public void removeRecipes(){
            Bukkit.getServer().resetRecipes();
        }
    
        public void viewRecipes(Player p){
            Inventory inv = Bukkit.createInventory(null, 27, "UHC Recipes");
            //Golden Head
            ItemStack goldHead = new ItemStack(Material.SKULL_ITEM);
            ItemMeta goldHeadMeta = goldHead.getItemMeta();
            goldHeadMeta.setDisplayName("§6§lGolden Head");
            goldHead.setItemMeta(goldHeadMeta);
            //Excalibur
            ItemStack excalibur = new ItemStack(Material.GOLD_SWORD);
            ItemMeta excaliburMeta = excalibur.getItemMeta();
            excaliburMeta.setDisplayName("§6Excalibur");
            excalibur.setItemMeta(excaliburMeta);
            //Tarn Helm
            ItemStack tarnHelm = new ItemStack(Material.DIAMOND_HELMET);
            ItemMeta tarnHelmMeta = tarnHelm.getItemMeta();
            tarnHelmMeta.setDisplayName("§bTarnhelm");
            tarnHelm.setItemMeta(tarnHelmMeta);
            //=========================================================================
            inv.setItem(0, goldHead);
            inv.setItem(1, excalibur);
            inv.setItem(2, tarnHelm);
            p.openInventory(inv);
        }
    
        @EventHandler
        public void onInventoryClick(InventoryClickEvent e){
            //00 01 02 03 04 05 06 07 08
            //09 10 11 12 13 14 15 16 17
            //18 19 20 21 22 23 24 25 26
            @SuppressWarnings("UnusedAssignment") Player p1 = (Player) e.getWhoClicked();
            Inventory tempinv = e.getInventory();
            if(e.getInventory().getTitle().contains("UHC Recipes")){
                e.setCancelled(true);
                if(e.getCurrentItem() == null){
                    return;
                } else if(e.getCurrentItem().getType() == Material.SKULL_ITEM){
                    tempinv.setItem(0, new ItemStack(Material.GOLD_INGOT));
                    tempinv.setItem(1, new ItemStack(Material.GOLD_INGOT));
                    tempinv.setItem(2, new ItemStack(Material.GOLD_INGOT));
                    tempinv.setItem(9, new ItemStack(Material.GOLD_INGOT));
                    tempinv.setItem(10, new ItemStack(Material.PRISMARINE_CRYSTALS));
                    tempinv.setItem(11, new ItemStack(Material.GOLD_INGOT));
                    tempinv.setItem(18, new ItemStack(Material.GOLD_INGOT));
                    tempinv.setItem(19, new ItemStack(Material.GOLD_INGOT));
                    tempinv.setItem(20, new ItemStack(Material.GOLD_INGOT));
                    ItemStack goldHead = new ItemStack(Material.SKULL_ITEM);
                    ItemMeta goldHeadMeta = goldHead.getItemMeta();
                    goldHeadMeta.setDisplayName("§6§lGolden Head");
                    goldHead.setItemMeta(goldHeadMeta);
                    tempinv.setItem(13, goldHead);
                } else if(e.getCurrentItem().getType() == Material.GOLD_SWORD){
                    tempinv.setItem(0, new ItemStack(Material.AIR));
                    tempinv.setItem(1, new ItemStack(Material.OBSIDIAN));
                    tempinv.setItem(2, new ItemStack(Material.GOLD_INGOT));
                    tempinv.setItem(9, new ItemStack(Material.AIR));
                    tempinv.setItem(10, new ItemStack(Material.OBSIDIAN));
                    tempinv.setItem(11, new ItemStack(Material.GOLD_INGOT));
                    tempinv.setItem(18, new ItemStack(Material.AIR));
                    tempinv.setItem(19, new ItemStack(Material.STICK));
                    tempinv.setItem(20, new ItemStack(Material.AIR));
                    ItemStack excalibur = new ItemStack(Material.GOLD_SWORD);
                    ItemMeta excaliburMeta = excalibur.getItemMeta();
                    excaliburMeta.setDisplayName("§6Excalibur");
                    excalibur.setItemMeta(excaliburMeta);
                    tempinv.setItem(13, excalibur);
                } else if(e.getCurrentItem().getType() == Material.DIAMOND_HELMET){
                    tempinv.setItem(0, new ItemStack(Material.DIAMOND));
                    tempinv.setItem(1, new ItemStack(Material.ANVIL));
                    tempinv.setItem(2, new ItemStack(Material.DIAMOND));
                    tempinv.setItem(9, new ItemStack(Material.DIAMOND));
                    tempinv.setItem(10, new ItemStack(Material.AIR));
                    tempinv.setItem(11, new ItemStack(Material.DIAMOND));
                    tempinv.setItem(18, new ItemStack(Material.AIR));
                    tempinv.setItem(19, new ItemStack(Material.AIR));
                    tempinv.setItem(20, new ItemStack(Material.AIR));
                    ItemStack tarnHelm = new ItemStack(Material.DIAMOND_HELMET);
                    ItemMeta tarnHelmMeta = tarnHelm.getItemMeta();
                    tarnHelmMeta.setDisplayName("§bTarnhelm");
                    tarnHelm.setItemMeta(tarnHelmMeta);
                    tempinv.setItem(13, tarnHelm);
                }
            }
        }
    }


    You don't have to look at all the classes. Just looking for any fixes!

    To make sure those Copy-cats don't find this thread, I'll edit All this out when solved. You know, the kind that come to this forum, not knowing java.
     
  2. Offline

    aztk

    Few things from first class:

    1.
    Code:
    Plugin plugin = Bukkit.getPluginManager().getPlugin("KTHC");
            FileConfiguration config = plugin.getConfig();
    You add this in every class that uses config. It's not like must-do, but more clear is creating like class Config (or just adding it in Main and use Main.config) and in this class
    Code:
    public static FileConfiguration  getConfig = plugin.getConfig();
    You can even have variables like ints or strings in here and just use getSomething() and setSomething() but as I said it's just kinda cosmetic and additional.
    2.
    Code:
    final org.bukkit.World uhcw = Bukkit.getServer().getWorld(uhc)
    I don't exactly know why there's a final keyword, especially when the variable can change - it's get from the config, but whatever.
    3.
    Code:
    final org.bukkit.World uhcw = Bukkit.getServer().getWorld(uhc)
    Well, I'm pretty sure you can just replace this with World (imported from org.bukkit.World)
    4.By the way, I wouldn't use if(world==null) but rather something like this:
    Code:
    List<World> worlds = Bukkit.getServer().getWorlds();
    for(World w : worlds){
        if(w.getName() ==  "abc"){
            doSomething();
        }
    {
    if I have more time and desire I'll maybe post some more ;)
     
  3. Online

    timtower Administrator Administrator Moderator

    @HeartandSoul 1. Don't post your code if you are gonna remove it later.
    2. Use constructors to pass variables around
     
    ArsenArsen likes this.
  4. Offline

    HeartandSoul

    Thanks. Fixed all of your suggestions!

    1. I know that people aren't here to steal code, but there are some people who do it (I was when I was a noob at java).
    2. In what classes should I put these constructors?
     
  5. For (1), I totally understand you removing code just because say, if you're working on a big project and you've spent almost 1-2 months on it and someone steals most of the code, that would be annoying.
    For (2), you have a choice:

    1. In a totally separate class, named after what the constructors are for (e.g: Config).
    2. In the main class.
     
  6. Offline

    HeartandSoul

Thread Status:
Not open for further replies.

Share This Page