From 9b145bef9aeffec50b370b7a57be971cdec9ff0f Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Sun, 21 May 2017 20:18:03 -0400 Subject: [PATCH] Made the simple simpler Following the KISS principle --- .../java/buttondevteam/presents/Main.java | 4 +-- ...lockCommand.java => UniversalCommand.java} | 2 +- .../hello/{Hello.java => HelloComponent.java} | 2 +- .../presents/hello/commands/HelloCommand.java | 16 ++-------- .../presents/hello/commands/HelloLoad.java | 16 ++-------- .../presents/hello/commands/HelloSave.java | 16 ++-------- .../presents/hello/commands/HelloTime.java | 32 +++++++------------ .../presents/hello/effects/HelloBlock.java | 6 +++- .../presents/hello/effects/HelloCow.java | 5 ++- .../hello/effects/HelloMagicPotato.java | 2 ++ 10 files changed, 32 insertions(+), 69 deletions(-) rename src/main/java/buttondevteam/presents/architecture/commands/{CommandBlockCommand.java => UniversalCommand.java} (85%) rename src/main/java/buttondevteam/presents/hello/{Hello.java => HelloComponent.java} (96%) diff --git a/src/main/java/buttondevteam/presents/Main.java b/src/main/java/buttondevteam/presents/Main.java index b24244f..66e0e21 100644 --- a/src/main/java/buttondevteam/presents/Main.java +++ b/src/main/java/buttondevteam/presents/Main.java @@ -5,7 +5,7 @@ import java.util.logging.Logger; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; -import buttondevteam.presents.hello.Hello; +import buttondevteam.presents.hello.HelloComponent; public class Main extends JavaPlugin{ public void onEnable(){ @@ -14,7 +14,7 @@ PluginDescriptionFile pdfFile = getDescription(); Logger logger = getLogger(); logger.info(pdfFile.getName() + " has been started (V." + pdfFile.getVersion()+ ")."); - new Hello().register(this); + new HelloComponent().register(this); logger.info(pdfFile.getName() + " has fully registered (V." + pdfFile.getVersion()+ ")."); } diff --git a/src/main/java/buttondevteam/presents/architecture/commands/CommandBlockCommand.java b/src/main/java/buttondevteam/presents/architecture/commands/UniversalCommand.java similarity index 85% rename from src/main/java/buttondevteam/presents/architecture/commands/CommandBlockCommand.java rename to src/main/java/buttondevteam/presents/architecture/commands/UniversalCommand.java index 68943be..183e65e 100644 --- a/src/main/java/buttondevteam/presents/architecture/commands/CommandBlockCommand.java +++ b/src/main/java/buttondevteam/presents/architecture/commands/UniversalCommand.java @@ -1,6 +1,6 @@ package buttondevteam.presents.architecture.commands; -public abstract class CommandBlockCommand extends BaseCommand{ +public abstract class UniversalCommand extends BaseCommand{ @Override public String[] GetHelpText(String alias){ return new String[] { diff --git a/src/main/java/buttondevteam/presents/hello/Hello.java b/src/main/java/buttondevteam/presents/hello/HelloComponent.java similarity index 96% rename from src/main/java/buttondevteam/presents/hello/Hello.java rename to src/main/java/buttondevteam/presents/hello/HelloComponent.java index 9afc375..433c8c1 100644 --- a/src/main/java/buttondevteam/presents/hello/Hello.java +++ b/src/main/java/buttondevteam/presents/hello/HelloComponent.java @@ -15,7 +15,7 @@ import buttondevteam.presents.hello.effects.HelloMagicPotato; import buttondevteam.presents.hello.effects.HelloParticle; import buttondevteam.presents.hello.effects.HelloSound; -public class Hello extends Component{ +public class HelloComponent extends Component{ @Override public void register(JavaPlugin plugin) { diff --git a/src/main/java/buttondevteam/presents/hello/commands/HelloCommand.java b/src/main/java/buttondevteam/presents/hello/commands/HelloCommand.java index 4f1bbbb..551bae5 100644 --- a/src/main/java/buttondevteam/presents/hello/commands/HelloCommand.java +++ b/src/main/java/buttondevteam/presents/hello/commands/HelloCommand.java @@ -2,27 +2,15 @@ package buttondevteam.presents.hello.commands; import org.bukkit.command.CommandSender; -import buttondevteam.presents.architecture.commands.BaseCommand; +import buttondevteam.presents.architecture.commands.UniversalCommand; -public class HelloCommand extends BaseCommand { +public class HelloCommand extends UniversalCommand { @Override public boolean OnCommand(CommandSender sender, String alias, String[] args) { sender.sendMessage("Hello World!"); return false; } - - @Override - public boolean GetPlayerOnly() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean GetModOnly() { - // TODO Auto-generated method stub - return false; - } @Override public String GetCommandPath(){ return "hello command"; diff --git a/src/main/java/buttondevteam/presents/hello/commands/HelloLoad.java b/src/main/java/buttondevteam/presents/hello/commands/HelloLoad.java index 1047e83..b367cf7 100644 --- a/src/main/java/buttondevteam/presents/hello/commands/HelloLoad.java +++ b/src/main/java/buttondevteam/presents/hello/commands/HelloLoad.java @@ -6,9 +6,9 @@ import java.util.List; import org.bukkit.command.CommandSender; -import buttondevteam.presents.architecture.commands.BaseCommand; +import buttondevteam.presents.architecture.commands.UniversalCommand; -public class HelloLoad extends BaseCommand { +public class HelloLoad extends UniversalCommand { @Override public boolean OnCommand(CommandSender sender, String alias, String[] args) { @@ -21,18 +21,6 @@ public class HelloLoad extends BaseCommand { } return true; } - - @Override - public boolean GetPlayerOnly() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean GetModOnly() { - // TODO Auto-generated method stub - return false; - } public String GetCommandPath(){ return "hello load"; } diff --git a/src/main/java/buttondevteam/presents/hello/commands/HelloSave.java b/src/main/java/buttondevteam/presents/hello/commands/HelloSave.java index 144edd0..47cc689 100644 --- a/src/main/java/buttondevteam/presents/hello/commands/HelloSave.java +++ b/src/main/java/buttondevteam/presents/hello/commands/HelloSave.java @@ -4,9 +4,9 @@ import java.util.Arrays; import org.bukkit.command.CommandSender; -import buttondevteam.presents.architecture.commands.BaseCommand; +import buttondevteam.presents.architecture.commands.UniversalCommand; -public class HelloSave extends BaseCommand { +public class HelloSave extends UniversalCommand { @Override public boolean OnCommand(CommandSender sender, String alias, String[] args) { if (args.length < 1){ @@ -23,18 +23,6 @@ public class HelloSave extends BaseCommand { } return false; } - - @Override - public boolean GetPlayerOnly() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean GetModOnly() { - // TODO Auto-generated method stub - return false; - } public String GetCommandPath(){ return "hello save"; } diff --git a/src/main/java/buttondevteam/presents/hello/commands/HelloTime.java b/src/main/java/buttondevteam/presents/hello/commands/HelloTime.java index b95eab1..0fcdf25 100644 --- a/src/main/java/buttondevteam/presents/hello/commands/HelloTime.java +++ b/src/main/java/buttondevteam/presents/hello/commands/HelloTime.java @@ -6,25 +6,27 @@ import java.util.Date; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; -import buttondevteam.presents.architecture.commands.BaseCommand; +import buttondevteam.presents.architecture.commands.UniversalCommand; -public class HelloTime extends BaseCommand { +public class HelloTime extends UniversalCommand { + final String path = "hellotime.lastincident"; @Override public boolean OnCommand(CommandSender sender, String alias, String[] args) { - String path = "hellotime.lastincident"; + FileConfiguration config = this.getPlugin().getConfig(); - if(!config.contains(path) || !config.isLong(path)){ - + + if(config.contains(path) && config.isLong(path)){ + sender.sendMessage("Last Time Incident: " + MillisToString(config.getLong(path))); + }else{ sender.sendMessage("Time Incident Occoured!"); sender.sendMessage("Setting..."); - + long time = System.currentTimeMillis(); config.set(path, time); - + sender.sendMessage("Time set to" + MillisToString(time)); } - sender.sendMessage("Days since last Time Incident: " + MillisToString(config.getLong(path))); return true; } public String MillisToString(long time){ @@ -32,19 +34,7 @@ public class HelloTime extends BaseCommand { SimpleDateFormat dateformatter = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z"); return dateformatter.format(dateTime); } - - - @Override - public boolean GetPlayerOnly() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean GetModOnly() { - // TODO Auto-generated method stub - return false; - } + public String GetCommandPath(){ return "hello time"; } diff --git a/src/main/java/buttondevteam/presents/hello/effects/HelloBlock.java b/src/main/java/buttondevteam/presents/hello/effects/HelloBlock.java index e977ad0..e53d881 100644 --- a/src/main/java/buttondevteam/presents/hello/effects/HelloBlock.java +++ b/src/main/java/buttondevteam/presents/hello/effects/HelloBlock.java @@ -1,6 +1,7 @@ package buttondevteam.presents.hello.effects; import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import buttondevteam.presents.architecture.commands.PlayerCommand; @@ -9,7 +10,10 @@ public class HelloBlock extends PlayerCommand { @Override public boolean OnCommand(Player player, String alias, String[] args) { - player.getWorld().getBlockAt(player.getLocation()).setType(Material.CAKE_BLOCK); + Block blockAtPlayer = player.getWorld().getBlockAt(player.getLocation()); + + blockAtPlayer.setType(Material.CAKE_BLOCK); + return false; } public String GetCommandPath(){ diff --git a/src/main/java/buttondevteam/presents/hello/effects/HelloCow.java b/src/main/java/buttondevteam/presents/hello/effects/HelloCow.java index 9e1e35f..64951c3 100644 --- a/src/main/java/buttondevteam/presents/hello/effects/HelloCow.java +++ b/src/main/java/buttondevteam/presents/hello/effects/HelloCow.java @@ -9,7 +9,10 @@ public class HelloCow extends PlayerCommand { @Override public boolean OnCommand(Player player, String alias, String[] args) { - player.getWorld().spawnEntity(player.getLocation(), EntityType.COW) ; + player.getWorld().spawnEntity( + player.getLocation(), + EntityType.COW + ); return true; } diff --git a/src/main/java/buttondevteam/presents/hello/effects/HelloMagicPotato.java b/src/main/java/buttondevteam/presents/hello/effects/HelloMagicPotato.java index 62e4c75..51e044a 100644 --- a/src/main/java/buttondevteam/presents/hello/effects/HelloMagicPotato.java +++ b/src/main/java/buttondevteam/presents/hello/effects/HelloMagicPotato.java @@ -24,9 +24,11 @@ public class HelloMagicPotato extends ModCommand { lore.add("There was a beautiful potato that ruled a fantastic kingdom. With its armies of french" + "fries and cannons of hash browns, it was unstopple."); lore.add("Until one fateful day..."); + meta.setLore(lore); potato.setItemMeta(meta); player.getInventory().addItem(potato); + return true; } public String GetCommandPath(){