Oh god this code is horrible, commented more

This commit is contained in:
alisolarflare 2016-10-30 01:26:32 -04:00
parent 43beadfcc1
commit dccf0a772e
5 changed files with 270 additions and 188 deletions

View file

@ -1,5 +1,4 @@
package alisolarflare.links;
import java.util.ArrayList;
import java.util.List;
import alisolarflare.AliPresents;
@ -8,25 +7,22 @@ import alisolarflare.links.commands.SetAliLink;
import alisolarflare.links.entities.Link;
public class AliLinkSubPlug{
public List<Link> linkList = new ArrayList<Link>();
public AliPresents plugin;
private SetAliLink setAliLink;
@SuppressWarnings("unchecked")
public AliLinkSubPlug(AliPresents plugin){
this.plugin = plugin;
linkList = (List<Link>) plugin.getConfig().getList("aliLinkList");
if(linkList == null || linkList.isEmpty()){
linkList = new ArrayList<Link>();
}
}
public void register(){
plugin.getCommand("pressalilink").setExecutor(new PressAliLink(this));
plugin.getCommand("setalilink").setExecutor(new SetAliLink(this));
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", linkList);
plugin.getConfig().set("aliLinkList", setAliLink.linkList);
}
@SuppressWarnings("unchecked")
public List<Link> loadLinkList(){

View file

@ -9,19 +9,21 @@ import alisolarflare.links.entities.Link;
public class PressAliLink implements CommandExecutor{
private AliLinkSubPlug subplugin;
public PressAliLink(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(subplugin.linkList.toString() + "over.");
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: subplugin.linkList){
for (Link link: setAliLink.linkList){
for (String inputlink: args){
if(inputlink.equals(link.frequency)){
link.press(subplugin);

View file

@ -1,6 +1,9 @@
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;
@ -8,14 +11,44 @@ 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 <frequency> [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<Link> linkList = new ArrayList<Link>();
AliLinkSubPlug subplugin;
public SetAliLink(AliLinkSubPlug plugin){
this.subplugin = plugin;
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");
@ -30,25 +63,30 @@ public class SetAliLink implements CommandExecutor{
Player player = (Player) sender;
if (args.length < 4){
player.sendMessage("short");
subplugin.linkList.add(new Link(args[0], player.getLocation()));
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]))));
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()));
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");
@ -67,5 +105,20 @@ public class SetAliLink implements CommandExecutor{
}
*/
}
/**
* Attempts to load the previous saved state of AliLinks, from the plugin
* configuration file
*/
@SuppressWarnings("unchecked")
private void load(){
try{
linkList = (List<Link>) plugin.getConfig().getList("aliLinkList");
if(linkList == null || linkList.isEmpty()){
linkList = new ArrayList<Link>();
}
}catch (Exception e){
e.printStackTrace();
}
}
}

View file

@ -10,7 +10,15 @@ 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
@ -20,7 +28,7 @@ public class AliShulker implements CommandExecutor {
return false;
}
Player player = (Player) sender;
if(!(player.getName().equals("iie"))){
if(!(player.getName().equals("iie") || player.getName().equals("alisolarflare"))){
return false;
}
Location location = player.getLocation();

View file

@ -13,20 +13,43 @@ import org.bukkit.entity.Player;
public class UHCMatch {
private List<String> matchPlayerUsernames = new ArrayList<String>();
/**
* Adds a player to an Ultrahardcore match, storing their name
* @param playername player.getName();
*/
public void addPlayerToMatch(String playername){
if (!(matchPlayerUsernames.contains(playername))){
matchPlayerUsernames.add(playername);
}
public void addPlayerToMatch(Player player){
matchPlayerUsernames.add(player.toString());
}
/**
* 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.toString());
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();
}