From dccf0a772e029b9ce28187c70b2b8bc454fc52c1 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Sun, 30 Oct 2016 01:26:32 -0400 Subject: [PATCH] Oh god this code is horrible, commented more --- src/alisolarflare/links/AliLinkSubPlug.java | 68 +++--- .../links/commands/PressAliLink.java | 70 ++++--- .../links/commands/SetAliLink.java | 195 +++++++++++------- src/alisolarflare/shulker/AliShulker.java | 86 ++++---- src/alisolarflare/uhc/UHCMatch.java | 39 +++- 5 files changed, 270 insertions(+), 188 deletions(-) diff --git a/src/alisolarflare/links/AliLinkSubPlug.java b/src/alisolarflare/links/AliLinkSubPlug.java index 08be881..f5e2843 100644 --- a/src/alisolarflare/links/AliLinkSubPlug.java +++ b/src/alisolarflare/links/AliLinkSubPlug.java @@ -1,36 +1,32 @@ -package alisolarflare.links; -import java.util.ArrayList; -import java.util.List; - -import alisolarflare.AliPresents; -import alisolarflare.links.commands.PressAliLink; -import alisolarflare.links.commands.SetAliLink; -import alisolarflare.links.entities.Link; - -public class AliLinkSubPlug{ - public List linkList = new ArrayList(); - public AliPresents plugin; - - @SuppressWarnings("unchecked") - public AliLinkSubPlug(AliPresents plugin){ - this.plugin = plugin; - linkList = (List) plugin.getConfig().getList("aliLinkList"); - if(linkList == null || linkList.isEmpty()){ - linkList = new ArrayList(); - } - - } - public void register(){ - plugin.getCommand("pressalilink").setExecutor(new PressAliLink(this)); - plugin.getCommand("setalilink").setExecutor(new SetAliLink(this)); - - } - public void saveLinkList(){ - plugin.getConfig().set("aliLinkList", linkList); - } - @SuppressWarnings("unchecked") - public List loadLinkList(){ - return (List) plugin.getConfig().getList("aliLinkList"); - } - -} +package alisolarflare.links; +import java.util.List; + +import alisolarflare.AliPresents; +import alisolarflare.links.commands.PressAliLink; +import alisolarflare.links.commands.SetAliLink; +import alisolarflare.links.entities.Link; + +public class AliLinkSubPlug{ + public AliPresents plugin; + private SetAliLink setAliLink; + + public AliLinkSubPlug(AliPresents plugin){ + this.plugin = plugin; + + + } + public void register(){ + setAliLink = new SetAliLink(this.plugin); + plugin.getCommand("setalilink").setExecutor(setAliLink); + plugin.getCommand("pressalilink").setExecutor(new PressAliLink(this, setAliLink)); + + } + public void saveLinkList(){ + plugin.getConfig().set("aliLinkList", setAliLink.linkList); + } + @SuppressWarnings("unchecked") + public List loadLinkList(){ + return (List) plugin.getConfig().getList("aliLinkList"); + } + +} diff --git a/src/alisolarflare/links/commands/PressAliLink.java b/src/alisolarflare/links/commands/PressAliLink.java index ba39b6e..de76443 100644 --- a/src/alisolarflare/links/commands/PressAliLink.java +++ b/src/alisolarflare/links/commands/PressAliLink.java @@ -1,34 +1,36 @@ -package alisolarflare.links.commands; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; - -import alisolarflare.links.AliLinkSubPlug; -import alisolarflare.links.entities.Link; - -public class PressAliLink implements CommandExecutor{ - private AliLinkSubPlug subplugin; - public PressAliLink(AliLinkSubPlug subplugin){ - this.subplugin = subplugin; - } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - - subplugin.plugin.getServer().broadcastMessage(subplugin.linkList.toString() + "over."); - - if (args.length < 1){ - sender.sendMessage("You must specify a link frequency"); - sender.sendMessage("/pressalilink [frequency]"); - } - for (Link link: subplugin.linkList){ - for (String inputlink: args){ - if(inputlink.equals(link.frequency)){ - link.press(subplugin); - } - } - } - return false; - } - -} +package alisolarflare.links.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +import alisolarflare.links.AliLinkSubPlug; +import alisolarflare.links.entities.Link; + +public class PressAliLink implements CommandExecutor{ + private AliLinkSubPlug subplugin; + private SetAliLink setAliLink; + public PressAliLink(AliLinkSubPlug subplugin, SetAliLink setAliLink){ + this.subplugin = subplugin; + this.setAliLink = setAliLink; + } + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + subplugin.plugin.getServer().broadcastMessage(setAliLink.linkList.toString() + "over."); + + if (args.length < 1){ + sender.sendMessage("You must specify a link frequency"); + sender.sendMessage("/pressalilink [frequency]"); + } + for (Link link: setAliLink.linkList){ + for (String inputlink: args){ + if(inputlink.equals(link.frequency)){ + link.press(subplugin); + } + } + } + return false; + } + +} diff --git a/src/alisolarflare/links/commands/SetAliLink.java b/src/alisolarflare/links/commands/SetAliLink.java index 1df6d82..5fd5fa7 100644 --- a/src/alisolarflare/links/commands/SetAliLink.java +++ b/src/alisolarflare/links/commands/SetAliLink.java @@ -1,71 +1,124 @@ -package alisolarflare.links.commands; - - -import org.apache.commons.lang3.StringUtils; -import org.bukkit.Location; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import alisolarflare.links.AliLinkSubPlug; -import alisolarflare.links.entities.Link; - -public class SetAliLink implements CommandExecutor{ - AliLinkSubPlug subplugin; - public SetAliLink(AliLinkSubPlug plugin){ - this.subplugin = plugin; - } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - sender.sendMessage("you pressed shit"); - if (args == null || args.length < 1){ - sender.sendMessage("You must specify a link frequency"); - sender.sendMessage("/pressalilink [name]"); - return false; - } - if (!(sender instanceof Player)){ - sender.sendMessage("You must be a player to use this command!"); - } - Player player = (Player) sender; - if (args.length < 4){ - player.sendMessage("short"); - subplugin.linkList.add(new Link(args[0], player.getLocation())); - save(player); - player.sendMessage("end"); - return false; - } - if (StringUtils.isNumericSpace(args[1]) && StringUtils.isNumericSpace(args[2]) && StringUtils.isNumericSpace(args[3])){ - player.sendMessage("CUUUSTOM"); - subplugin.linkList.add(new Link(args[0],new Location(player.getWorld(), Double.parseDouble(args[1]), Double.parseDouble(args[2]), Double.parseDouble(args[3])))); - save(player); - player.sendMessage("FINISHED"); - }else{ - player.sendMessage("UNCUSTOOM"); - subplugin.linkList.add(new Link(args[0], player.getLocation())); - save(player); - player.sendMessage("UNFINISHED"); - return false; - } - return false; - } - private void save(Player player){ - player.sendMessage("SAAAVING"); - player.sendMessage("SAVE FAILED: TELL ALI TO FIX THE SAVE AND UN-COMMENT THE PARAGRAPH SHE COMMENTED"); - player.sendMessage("Link will only last until next server restart"); - return; - /* - subplugin.plugin.getConfig().set("aliLinkList", subplugin.linkList); - try { - player.sendMessage("SAVIN"); - subplugin.plugin.saveConfig(); - player.sendMessage("GOOD SAVE"); - } catch (Exception e) { - player.sendMessage("YOU FUCKED STUFF UP"); - // TODO Auto-generated catch block - e.printStackTrace(); - } - */ - } - -} +package alisolarflare.links.commands; + + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import alisolarflare.AliPresents; +import alisolarflare.links.AliLinkSubPlug; +import alisolarflare.links.entities.Link; + +/** + * This class manages the command /SetAliLink [x] [y] [z]. This command creates an Ali-Link, + * a location in a world that when called on by {@link Class#PressAliLink}, creates a temporary redstone block, + * enabling wireless redstone + * + * @see Class#PressAliLink + * @author Alisolarflare + * + */ +public class SetAliLink implements CommandExecutor{ + public List linkList = new ArrayList(); + AliLinkSubPlug subplugin; + private AliPresents plugin; + + /** + * Constructs the SetAliLink class + * @param plugin The plugin that contains the configuration file of AliPresents + */ + public SetAliLink(AliPresents plugin){ + this.plugin = plugin; + load(); + } + /** + * This command creates an Ali-Link which, when activated by the command /PressAliLink, + * creates a temporary redstone block if and only if /PressAliLink [frequency] matches the frequency + * saved when /SetAliLink [frequency] is called. + * + * @see Class#PressAliLink + * @param sender Player who sent the command + * @param command Command Object created + * @param label Name of the command + * @param args Arguments: [frequency] [x-coordinate] [y-coordinate] [z-coordinate], where the coordinates point + * to the intended location of the Ali-Link + */ + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + sender.sendMessage("you pressed shit"); + if (args == null || args.length < 1){ + sender.sendMessage("You must specify a link frequency"); + sender.sendMessage("/pressalilink [name]"); + return false; + } + if (!(sender instanceof Player)){ + sender.sendMessage("You must be a player to use this command!"); + } + Player player = (Player) sender; + if (args.length < 4){ + player.sendMessage("short"); + linkList.add(new Link(args[0], player.getLocation())); + save(player); + player.sendMessage("end"); + return false; + } + if (StringUtils.isNumericSpace(args[1]) && StringUtils.isNumericSpace(args[2]) && StringUtils.isNumericSpace(args[3])){ + player.sendMessage("CUUUSTOM"); + linkList.add(new Link(args[0],new Location(player.getWorld(), Double.parseDouble(args[1]), Double.parseDouble(args[2]), Double.parseDouble(args[3])))); + save(player); + player.sendMessage("FINISHED"); + }else{ + player.sendMessage("UNCUSTOOM"); + linkList.add(new Link(args[0], player.getLocation())); + save(player); + player.sendMessage("UNFINISHED"); + return false; + } + return false; + } + /** + * Tries to save the entire SetAliLink class into memory, which includes + * all of the current Ali-links saved and in use. + * @param player + */ + private void save(Player player){ + player.sendMessage("SAAAVING"); + player.sendMessage("SAVE FAILED: TELL ALI TO FIX THE SAVE AND UN-COMMENT THE PARAGRAPH SHE COMMENTED"); + player.sendMessage("Link will only last until next server restart"); + return; + /* + subplugin.plugin.getConfig().set("aliLinkList", subplugin.linkList); + try { + player.sendMessage("SAVIN"); + subplugin.plugin.saveConfig(); + player.sendMessage("GOOD SAVE"); + } catch (Exception e) { + player.sendMessage("YOU FUCKED STUFF UP"); + // TODO Auto-generated catch block + e.printStackTrace(); + } + */ + } + /** + * Attempts to load the previous saved state of AliLinks, from the plugin + * configuration file + */ + @SuppressWarnings("unchecked") + private void load(){ + try{ + linkList = (List) plugin.getConfig().getList("aliLinkList"); + if(linkList == null || linkList.isEmpty()){ + linkList = new ArrayList(); + } + }catch (Exception e){ + e.printStackTrace(); + } + } + +} diff --git a/src/alisolarflare/shulker/AliShulker.java b/src/alisolarflare/shulker/AliShulker.java index 5e8ee83..6f503a9 100644 --- a/src/alisolarflare/shulker/AliShulker.java +++ b/src/alisolarflare/shulker/AliShulker.java @@ -1,39 +1,47 @@ -package alisolarflare.shulker; - -import org.bukkit.Location; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.entity.Shulker; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -public class AliShulker implements CommandExecutor { - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)){ - sender.sendMessage("You must be a player to use this command!"); - return false; - } - Player player = (Player) sender; - if(!(player.getName().equals("iie"))){ - return false; - } - Location location = player.getLocation(); - Entity entity = player.getWorld().spawnEntity(location, EntityType.SHULKER); - Shulker shulker = (Shulker) entity; - shulker.setHealth(10); - - shulker.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 1728000, 5, false)); - shulker.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1728000, 5, false)); - shulker.setAI(false); - shulker.setGlowing(true); - - return false; - } - -} +package alisolarflare.shulker; + +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.Shulker; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +/** + * @author Alisolarflare + * This class is responsible for the command /aliShulker, which in-game spawns + * a shulker that: + * Has a health of 10 + * Has a wither and invisibility effect present + * Has noAI + * And is Glowing + */ +public class AliShulker implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)){ + sender.sendMessage("You must be a player to use this command!"); + return false; + } + Player player = (Player) sender; + if(!(player.getName().equals("iie") || player.getName().equals("alisolarflare"))){ + return false; + } + Location location = player.getLocation(); + Entity entity = player.getWorld().spawnEntity(location, EntityType.SHULKER); + Shulker shulker = (Shulker) entity; + shulker.setHealth(10); + + shulker.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 1728000, 5, false)); + shulker.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1728000, 5, false)); + shulker.setAI(false); + shulker.setGlowing(true); + + return false; + } + +} diff --git a/src/alisolarflare/uhc/UHCMatch.java b/src/alisolarflare/uhc/UHCMatch.java index 3eff51d..f4e6ccc 100644 --- a/src/alisolarflare/uhc/UHCMatch.java +++ b/src/alisolarflare/uhc/UHCMatch.java @@ -13,20 +13,43 @@ import org.bukkit.entity.Player; public class UHCMatch { private List matchPlayerUsernames = new ArrayList(); + /** + * Adds a player to an Ultrahardcore match, storing their name + * @param playername player.getName(); + */ public void addPlayerToMatch(String playername){ - matchPlayerUsernames.add(playername); - } - public void addPlayerToMatch(Player player){ - matchPlayerUsernames.add(player.toString()); - } - public void removePlayerFromMatch(Player player){ - if (matchPlayerUsernames.contains(player)){ - matchPlayerUsernames.remove(player.toString()); + if (!(matchPlayerUsernames.contains(playername))){ + matchPlayerUsernames.add(playername); } } + /** + * Adds a player to an Ultrahardcore match, storing their name + * @param player Player to be added + */ + public void addPlayerToMatch(Player player){ + if (!(matchPlayerUsernames.contains(player.getName()))){ + matchPlayerUsernames.add(player.getName()); + } + } + /** + * Removes a player from an Ultrahardcore match, removing their username from the list + * @param player + */ + public void removePlayerFromMatch(Player player){ + if (matchPlayerUsernames.contains(player)){ + matchPlayerUsernames.remove(player.getName()); + } + } + + /** + * Removes all players from the match + */ public void removeAllPlayersFromMatch(){ matchPlayerUsernames.clear(); } + /** + * Fully de-loads and clears out this match, reverting all values to the initialized setting + */ public void endMatch(){ matchPlayerUsernames.clear(); }