diff --git a/src/main/java/net/poweredbyhate/trollplus/TrollPlus.java b/src/main/java/net/poweredbyhate/trollplus/TrollPlus.java index 461816f..4368775 100644 --- a/src/main/java/net/poweredbyhate/trollplus/TrollPlus.java +++ b/src/main/java/net/poweredbyhate/trollplus/TrollPlus.java @@ -1,51 +1,47 @@ package net.poweredbyhate.trollplus; -import net.poweredbyhate.trollplus.Trolls.CommandBolt; -import net.poweredbyhate.trollplus.Trolls.CommandBurn; -import net.poweredbyhate.trollplus.Trolls.CommandFakeop; -import net.poweredbyhate.trollplus.Trolls.CommandFreeze; -import net.poweredbyhate.trollplus.Trolls.CommandJarcode; +import net.poweredbyhate.trollplus.listeners.PlayerListener; +import net.poweredbyhate.trollplus.managers.CommandManager; +import net.poweredbyhate.trollplus.managers.TrollPlayerManager; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.plugin.java.JavaPlugin; /** * Created by Lax on 4/18/2016. */ -public class TrollPlus extends JavaPlugin implements Listener{ +public class TrollPlus extends JavaPlugin { + private final Listener[] listeners = { + new PlayerListener(this) + }; + + private TrollPlayerManager playerManager; + private CommandManager commandManager; + + @Override // You better annotate every bloody override or I will end you. public void onEnable() { - Bukkit.getPluginManager().registerEvents(this, this); - enableCommands(); //List of commands to make: http://q.awsmpwrd.com/iVZx.png + loadManagers(); + loadListeners(); + //List of command to make: http://q.awsmpwrd.com/iVZx.png } - public void enableCommands() { - getCommand("burn").setExecutor(new CommandBurn(this)); - getCommand("freeze").setExecutor(new CommandFreeze(this)); - getCommand("bolt").setExecutor(new CommandBolt(this)); - //getCommand("special").setExecutor(new CommandSpecial(this)); I have yet to check what a fucking AK-47 is. - getCommand("fakeop").setExecutor(new CommandFakeop(this)); //not done - getCommand("jarcode").setExecutor(new CommandJarcode(this)); + private void loadManagers() { + playerManager = new TrollPlayerManager(this); + commandManager = new CommandManager(this); } - String[] ad = { - "&d____----====[ &cSponsored by GNU/Emacs&d ]====----____", - "&aGet emacs for your linux distro now!", - "&bhttps://www.gnu.org/software/emacs/", - - "&aThis troll plugin is sponsored by Emacs!", - "&aEmacs is the one true editor that respects your software freedoms", - " " - }; + private void loadListeners() { + for (Listener listener : listeners) { + Bukkit.getPluginManager().registerEvents(listener, this); + } + } + public TrollPlayerManager getPlayerManager() { + return playerManager; + } - @EventHandler - public void onJoin(PlayerJoinEvent ev) { - for (String s : ad) { - ev.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', s)); - } + public CommandManager getCommandManager() { + return commandManager; } } diff --git a/src/main/java/net/poweredbyhate/trollplus/Trolls/CommandBolt.java b/src/main/java/net/poweredbyhate/trollplus/Trolls/CommandBolt.java deleted file mode 100644 index 60007a2..0000000 --- a/src/main/java/net/poweredbyhate/trollplus/Trolls/CommandBolt.java +++ /dev/null @@ -1,37 +0,0 @@ -package net.poweredbyhate.trollplus.Trolls; - -import net.poweredbyhate.trollplus.TrollPlus; -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; - -/** - * Created by Lax on 4/18/2016. - */ -public class CommandBolt implements CommandExecutor { - - TrollPlus plugin; - - public CommandBolt(TrollPlus trollPlus) { - this.plugin = trollPlus; - } - - - @Override - public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { - if (sender.hasPermission("trollplus.bolt")) { - if(args.length == 0 && sender instanceof Player) { - Player p = (Player) sender; - p.getLocation().getWorld().strikeLightning(p.getLocation()); - } else if (Bukkit.getPlayer(args[0]) != null && sender.hasPermission("trollplus.bolt.others")) { - Player p = Bukkit.getPlayer(args[0]); - p.getLocation().getWorld().strikeLightning(p.getLocation()); - } - } - sender.sendMessage(ChatColor.RED+ "No Permz"); - return false; - } -} diff --git a/src/main/java/net/poweredbyhate/trollplus/Trolls/CommandBurn.java b/src/main/java/net/poweredbyhate/trollplus/Trolls/CommandBurn.java deleted file mode 100644 index bc8fb32..0000000 --- a/src/main/java/net/poweredbyhate/trollplus/Trolls/CommandBurn.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.poweredbyhate.trollplus.Trolls; - -import net.poweredbyhate.trollplus.TrollPlus; -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; - -/** - * Created by Lax on 4/18/2016. - */ -public class CommandBurn implements CommandExecutor { - - TrollPlus plugin; - - public CommandBurn(TrollPlus trollPlus) { - this.plugin = trollPlus; - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { - if (sender.hasPermission("trollplus.burn")) { - if(args.length == 0 && sender instanceof Player) { - ((Player) sender).setFireTicks(200); - } else if (Bukkit.getPlayer(args[0]) != null && sender.hasPermission("trollplus.burn.others")) { - Bukkit.getPlayer(args[0]).setFireTicks(200); - } - } - sender.sendMessage(ChatColor.RED+ "No Permz"); - return false; - } -} diff --git a/src/main/java/net/poweredbyhate/trollplus/Trolls/CommandFakeop.java b/src/main/java/net/poweredbyhate/trollplus/Trolls/CommandFakeop.java deleted file mode 100644 index 87be094..0000000 --- a/src/main/java/net/poweredbyhate/trollplus/Trolls/CommandFakeop.java +++ /dev/null @@ -1,27 +0,0 @@ -package net.poweredbyhate.trollplus.Trolls; - -import net.poweredbyhate.trollplus.TrollPlus; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; - -import java.util.ArrayList; - -/** - * Created by Lax on 4/18/2016. - */ -public class CommandFakeop implements CommandExecutor { - - ArrayList fakeopz = new ArrayList<>(); - - TrollPlus plugin; - public CommandFakeop(TrollPlus trollPlus) { - this.plugin = trollPlus; - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { - return false; - } - -} diff --git a/src/main/java/net/poweredbyhate/trollplus/Trolls/CommandFreeze.java b/src/main/java/net/poweredbyhate/trollplus/Trolls/CommandFreeze.java deleted file mode 100644 index 4c0c76b..0000000 --- a/src/main/java/net/poweredbyhate/trollplus/Trolls/CommandFreeze.java +++ /dev/null @@ -1,50 +0,0 @@ -package net.poweredbyhate.trollplus.Trolls; - -import net.poweredbyhate.trollplus.TrollPlus; -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.scheduler.BukkitRunnable; - -/** - * Created by Lax on 4/18/2016. - */ -public class CommandFreeze implements CommandExecutor { - - TrollPlus plugin; - public CommandFreeze(TrollPlus trollPlus) { - this.plugin = trollPlus; - } - - @Override - public boolean onCommand(final CommandSender sender, Command command, String s, final String[] args) { - if (sender.hasPermission("trollplus.freeze")) { - if (args.length == 0 && sender instanceof Player) { - ((Player) sender).setWalkSpeed(0); - ((Player) sender).setFlySpeed(0); - new BukkitRunnable() { - @Override - public void run() { - ((Player) sender).setWalkSpeed(0.2F); - ((Player) sender).setFlySpeed(0.1F); - } - }.runTaskLater(plugin, 200); - } else if (Bukkit.getPlayer(args[0]) != null && sender.hasPermission("trollplus.freeze.others")) { - Bukkit.getPlayer(args[0]).setWalkSpeed(0); - Bukkit.getPlayer(args[0]).setFlySpeed(0); - new BukkitRunnable() { - @Override - public void run() { - Bukkit.getPlayer(args[0]).setWalkSpeed(0.2F); - Bukkit.getPlayer(args[0]).setFlySpeed(0.1F); - } - }.runTaskLater(plugin, 200); - } - sender.sendMessage(ChatColor.RED+ "No Permz"); - } - return false; - } -} diff --git a/src/main/java/net/poweredbyhate/trollplus/Trolls/CommandJarcode.java b/src/main/java/net/poweredbyhate/trollplus/Trolls/CommandJarcode.java deleted file mode 100644 index 2d67d00..0000000 --- a/src/main/java/net/poweredbyhate/trollplus/Trolls/CommandJarcode.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.poweredbyhate.trollplus.Trolls; - -import net.poweredbyhate.trollplus.TrollPlus; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - -import java.util.Random; - -/** - * Created by Lax on 4/18/2016. - */ -public class CommandJarcode implements CommandExecutor { - - TrollPlus plugin; - String[] jarcodes = { //oh and + jarcode - "install fucking gentoo you pleb", - "use emacs you sack of shit", - "this server doesn\'t support your software freedom", - "emacs is the one true editor, emacs is love, emacs is life", - "i secretly love laxwashere" - }; - String rant = "What the fuck did you just fucking say about me, you little bitch? I’ll have you know I graduated top of my class in the Navy Seals, and I’ve been involved in numerous secret raids on Al-Quaeda, and I have over 300 confirmed kills. I am trained in gorilla warfare and I’m the top sniper in the entire US armed forces. You are nothing to me but just another target. I will wipe you the fuck out with precision the likes of which has never been seen before on this Earth, mark my fucking words. You think you can get away with saying that shit to me over the Internet? Think again, fucker. As we speak I am contacting my secret network of spies across the USA and your IP is being traced right now so you better prepare for the storm, maggot. The storm that wipes out the pathetic little thing you call your life. You’re fucking dead, kid. I can be anywhere, anytime, and I can kill you in over seven hundred ways, and that’s just with my bare hands. Not only am I extensively trained in unarmed combat, but I have access to the entire arsenal of the United States Marine Corps and I will use it to its full extent to wipe your miserable ass off the face of the continent, you little shit. If only you could have known what unholy retribution your little “clever” comment was about to bring down upon you, maybe you would have held your fucking tongue. But you couldn’t, you didn’t, and now you’re paying the price, you goddamn idiot. I will shit fury all over you and you will drown in it. You’re fucking dead, kiddo."; - - public CommandJarcode(TrollPlus trollPlus) { - this.plugin = trollPlus; - } - - Random r = new Random(); - @Override - public boolean onCommand(final CommandSender commandSender, Command command, String s, String[] strings) { - if (commandSender.hasPermission("trollplus.jarcode") && commandSender instanceof Player) { - ((Player) commandSender).chat(rant); - new BukkitRunnable() { - @Override - public void run() { - ((Player) commandSender).chat("oh and " + jarcodes[r.nextInt(jarcodes.length)]); - } - }.runTaskLater(plugin, 40); - } - return false; - } -} diff --git a/src/main/java/net/poweredbyhate/trollplus/command/CommandConsumer.java b/src/main/java/net/poweredbyhate/trollplus/command/CommandConsumer.java new file mode 100644 index 0000000..7c4fc16 --- /dev/null +++ b/src/main/java/net/poweredbyhate/trollplus/command/CommandConsumer.java @@ -0,0 +1,41 @@ +package net.poweredbyhate.trollplus.command; + +import net.poweredbyhate.trollplus.TrollPlus; +import net.poweredbyhate.trollplus.player.TrollPlayer; +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 abstract class CommandConsumer implements CommandExecutor { + + protected final TrollPlus plugin; + + protected CommandConsumer(TrollPlus plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + // Commands can only be executed by Players because fuck the console + sender.sendMessage(ChatColor.RED + "Are ye serious mate? Too stingy to log on to the bloody server are ya?"); + sender.sendMessage(ChatColor.RED + "You can take your bloody console and piss right off mate."); + return false; + } + TrollPlayer player = plugin.getPlayerManager().getPlayer((Player) sender); + onCommand(player, label, args); + return false; + } + + // Only use label to resend the command to the player, no checks are needed + protected abstract void onCommand(TrollPlayer player, String label, String[] args); + + public abstract String getCommand(); + + protected void noPermz(TrollPlayer player) { + player.sendMessage("&cNo Permz"); + } + +} diff --git a/src/main/java/net/poweredbyhate/trollplus/command/trolls/BoltTrollCommand.java b/src/main/java/net/poweredbyhate/trollplus/command/trolls/BoltTrollCommand.java new file mode 100644 index 0000000..a2d9a13 --- /dev/null +++ b/src/main/java/net/poweredbyhate/trollplus/command/trolls/BoltTrollCommand.java @@ -0,0 +1,44 @@ +package net.poweredbyhate.trollplus.command.trolls; + +import net.poweredbyhate.trollplus.TrollPlus; +import net.poweredbyhate.trollplus.command.CommandConsumer; +import net.poweredbyhate.trollplus.player.TrollPlayer; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +/** + * Created by Lax on 4/18/2016. + */ +public class BoltTrollCommand extends CommandConsumer { + + public BoltTrollCommand(TrollPlus plugin) { + super(plugin); + } + + @Override + protected void onCommand(TrollPlayer player, String label, String[] args) { + if (!player.hasPermissionOrIsOp("trollplus.bolt")) { + noPermz(player); + return; + } + if (args.length == 0) { + player.getPlayer().getLocation().getWorld().strikeLightningEffect(player.getPlayer().getLocation()); + return; + } + if (!player.hasPermissionOrIsOp("trollplus.bolt.others")) { + noPermz(player); + return; + } + Player target = Bukkit.getPlayer(args[0]); + if (target == null) { + player.sendMessage("&cUsage: /" + label + " [player]"); + return; + } + target.getLocation().getWorld().strikeLightningEffect(target.getLocation()); + } + + @Override + public String getCommand() { + return "bolt"; + } +} diff --git a/src/main/java/net/poweredbyhate/trollplus/command/trolls/BurnTrollCommand.java b/src/main/java/net/poweredbyhate/trollplus/command/trolls/BurnTrollCommand.java new file mode 100644 index 0000000..075cf72 --- /dev/null +++ b/src/main/java/net/poweredbyhate/trollplus/command/trolls/BurnTrollCommand.java @@ -0,0 +1,40 @@ +package net.poweredbyhate.trollplus.command.trolls; + +import net.poweredbyhate.trollplus.TrollPlus; +import net.poweredbyhate.trollplus.command.CommandConsumer; +import net.poweredbyhate.trollplus.player.TrollPlayer; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +/** + * Created by Lax on 4/18/2016. + */ +public class BurnTrollCommand extends CommandConsumer { + + public BurnTrollCommand(TrollPlus plugin) { + super(plugin); + } + + @Override + protected void onCommand(TrollPlayer player, String label, String[] args) { + if (!player.hasPermissionOrIsOp("trollplus.burn")) { + noPermz(player); + return; + } + if (args.length == 0) { + player.getPlayer().setFireTicks(200); + return; + } + Player target = Bukkit.getPlayer(args[0]); + if (target == null) { + player.sendMessage("&cUsage: /" + label + " [player]"); + return; + } + target.setFireTicks(200); + } + + @Override + public String getCommand() { + return "burn"; + } +} diff --git a/src/main/java/net/poweredbyhate/trollplus/command/trolls/FakeopTrollCommand.java b/src/main/java/net/poweredbyhate/trollplus/command/trolls/FakeopTrollCommand.java new file mode 100644 index 0000000..bf94859 --- /dev/null +++ b/src/main/java/net/poweredbyhate/trollplus/command/trolls/FakeopTrollCommand.java @@ -0,0 +1,31 @@ +package net.poweredbyhate.trollplus.command.trolls; + +import net.poweredbyhate.trollplus.TrollPlus; +import net.poweredbyhate.trollplus.command.CommandConsumer; +import net.poweredbyhate.trollplus.player.TrollPlayer; + +import java.util.ArrayList; + +/** + * Created by Lax on 4/18/2016. + */ +public class FakeopTrollCommand extends CommandConsumer { + + private final ArrayList fakeopz; + + public FakeopTrollCommand(TrollPlus plugin) { + super(plugin); + fakeopz = new ArrayList<>(); + } + + @Override + protected void onCommand(TrollPlayer player, String label, String[] args) { + + } + + @Override + public String getCommand() { + return "fakeop"; + } + +} diff --git a/src/main/java/net/poweredbyhate/trollplus/command/trolls/FreezeTrollCommand.java b/src/main/java/net/poweredbyhate/trollplus/command/trolls/FreezeTrollCommand.java new file mode 100644 index 0000000..f9b3247 --- /dev/null +++ b/src/main/java/net/poweredbyhate/trollplus/command/trolls/FreezeTrollCommand.java @@ -0,0 +1,61 @@ +package net.poweredbyhate.trollplus.command.trolls; + +import net.poweredbyhate.trollplus.TrollPlus; +import net.poweredbyhate.trollplus.command.CommandConsumer; +import net.poweredbyhate.trollplus.player.TrollPlayer; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +/** + * Created by Lax on 4/18/2016. + */ +public class FreezeTrollCommand extends CommandConsumer { + + public FreezeTrollCommand(TrollPlus plugin) { + super(plugin); + } + + @Override + protected void onCommand(final TrollPlayer player, String label, String[] args) { + if (!player.hasPermissionOrIsOp("trollplus.freeze")) { + noPermz(player); + return; + } + if (args.length == 0) { + player.getPlayer().setWalkSpeed(0); + player.getPlayer().setFlySpeed(0); + new BukkitRunnable() { + @Override + public void run() { + player.getPlayer().setWalkSpeed(0.2F); + player.getPlayer().setFlySpeed(0.1F); + } + }.runTaskLater(plugin, 200); + return; + } + if (!player.hasPermissionOrIsOp("trollplus.freeze.others")) { + noPermz(player); + return; + } + final Player target = Bukkit.getPlayer(args[0]); + if (target == null) { + player.sendMessage("&cUsage: /" + label + " [player]"); + return; + } + target.setWalkSpeed(0); + target.setFlySpeed(0); + new BukkitRunnable() { + @Override + public void run() { + target.setWalkSpeed(0.2F); + target.setFlySpeed(0.1F); + } + }.runTaskLater(plugin, 200); + } + + @Override + public String getCommand() { + return "freeze"; + } +} diff --git a/src/main/java/net/poweredbyhate/trollplus/command/trolls/JarcodeTrollCommand.java b/src/main/java/net/poweredbyhate/trollplus/command/trolls/JarcodeTrollCommand.java new file mode 100644 index 0000000..9a76d7b --- /dev/null +++ b/src/main/java/net/poweredbyhate/trollplus/command/trolls/JarcodeTrollCommand.java @@ -0,0 +1,50 @@ +package net.poweredbyhate.trollplus.command.trolls; + +import net.poweredbyhate.trollplus.TrollPlus; +import net.poweredbyhate.trollplus.command.CommandConsumer; +import net.poweredbyhate.trollplus.player.TrollPlayer; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.Random; + +/** + * Created by Lax on 4/18/2016. + */ +public class JarcodeTrollCommand extends CommandConsumer { + + private final String[] jarcodes = { // oh and + jarcode + "install fucking gentoo you pleb", + "use emacs you sack of shit", + "this server doesn\'t support your software freedom", + "emacs is the one true editor, emacs is love, emacs is life", + "i secretly love laxwashere" + }; + private final String rant = "What the fuck did you just fucking say about me, you little bitch? I’ll have you know I graduated top of my class in the Navy Seals, and I’ve been involved in numerous secret raids on Al-Quaeda, and I have over 300 confirmed kills. I am trained in gorilla warfare and I’m the top sniper in the entire US armed forces. You are nothing to me but just another target. I will wipe you the fuck out with precision the likes of which has never been seen before on this Earth, mark my fucking words. You think you can get away with saying that shit to me over the Internet? Think again, fucker. As we speak I am contacting my secret network of spies across the USA and your IP is being traced right now so you better prepare for the storm, maggot. The storm that wipes out the pathetic little thing you call your life. You’re fucking dead, kid. I can be anywhere, anytime, and I can kill you in over seven hundred ways, and that’s just with my bare hands. Not only am I extensively trained in unarmed combat, but I have access to the entire arsenal of the United States Marine Corps and I will use it to its full extent to wipe your miserable ass off the face of the continent, you little shit. If only you could have known what unholy retribution your little “clever” comment was about to bring down upon you, maybe you would have held your fucking tongue. But you couldn’t, you didn’t, and now you’re paying the price, you goddamn idiot. I will shit fury all over you and you will drown in it. You’re fucking dead, kiddo."; + + private final Random random; + + public JarcodeTrollCommand(TrollPlus plugin) { + super(plugin); + random = new Random(); + } + + @Override + protected void onCommand(final TrollPlayer player, String label, String[] args) { + if (!player.hasPermissionOrIsOp("trollplus.jarcode")) { + noPermz(player); + return; + } + player.sendMessage(rant); + new BukkitRunnable() { + @Override + public void run() { + player.sendMessage("oh and " + jarcodes[random.nextInt(jarcodes.length)]); + } + }.runTaskLater(plugin, 40); + } + + @Override + public String getCommand() { + return "jarcode"; + } +} diff --git a/src/main/java/net/poweredbyhate/trollplus/listeners/PlayerListener.java b/src/main/java/net/poweredbyhate/trollplus/listeners/PlayerListener.java new file mode 100644 index 0000000..1f50129 --- /dev/null +++ b/src/main/java/net/poweredbyhate/trollplus/listeners/PlayerListener.java @@ -0,0 +1,41 @@ +package net.poweredbyhate.trollplus.listeners; + +import net.poweredbyhate.trollplus.TrollPlus; +import net.poweredbyhate.trollplus.player.TrollPlayer; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener { + + private final TrollPlus plugin; + + public PlayerListener(TrollPlus plugin) { + this.plugin = plugin; + } + + @EventHandler + public void on(PlayerJoinEvent event) { + TrollPlayer player = plugin.getPlayerManager().register(event.getPlayer()); + advertise(player); + } + + @EventHandler + public void on(PlayerQuitEvent event) { + plugin.getPlayerManager().deregister(event.getPlayer()); + } + + private void advertise(TrollPlayer player) { + player.sendMessage( + "&d____----====[ &cSponsored by GNU/Emacs&d ]====----____", + "&aGet emacs for your linux distro now!", + "&bhttps://www.gnu.org/software/emacs/", + + "&aThis troll plugin is sponsored by Emacs!", + "&aEmacs is the one true editor that respects your software freedoms", + " " + ); + } + +} diff --git a/src/main/java/net/poweredbyhate/trollplus/managers/CommandManager.java b/src/main/java/net/poweredbyhate/trollplus/managers/CommandManager.java new file mode 100644 index 0000000..fffeb25 --- /dev/null +++ b/src/main/java/net/poweredbyhate/trollplus/managers/CommandManager.java @@ -0,0 +1,30 @@ +package net.poweredbyhate.trollplus.managers; + +import net.poweredbyhate.trollplus.TrollPlus; +import net.poweredbyhate.trollplus.command.CommandConsumer; +import net.poweredbyhate.trollplus.command.trolls.*; + +public class CommandManager extends Manager { + + private final CommandConsumer[] commandConsumers = new CommandConsumer[] { + new BoltTrollCommand(plugin), new BurnTrollCommand(plugin), new FakeopTrollCommand(plugin), + new FreezeTrollCommand(plugin), new JarcodeTrollCommand(plugin) + }; + + public CommandManager(TrollPlus plugin) { + super(plugin); + loadCommands(); + } + + private void loadCommands() { + for (CommandConsumer commandConsumer : commandConsumers) { + register(commandConsumer); + } + } + + private void register(CommandConsumer commandConsumer) { + plugin.getCommand(commandConsumer.getCommand()).setExecutor(commandConsumer); + } + + +} diff --git a/src/main/java/net/poweredbyhate/trollplus/managers/Manager.java b/src/main/java/net/poweredbyhate/trollplus/managers/Manager.java new file mode 100644 index 0000000..a07d1d5 --- /dev/null +++ b/src/main/java/net/poweredbyhate/trollplus/managers/Manager.java @@ -0,0 +1,13 @@ +package net.poweredbyhate.trollplus.managers; + +import net.poweredbyhate.trollplus.TrollPlus; + +public abstract class Manager { + + protected final TrollPlus plugin; + + public Manager(TrollPlus plugin) { + this.plugin = plugin; + } + +} diff --git a/src/main/java/net/poweredbyhate/trollplus/managers/TrollPlayerManager.java b/src/main/java/net/poweredbyhate/trollplus/managers/TrollPlayerManager.java new file mode 100644 index 0000000..de63ad2 --- /dev/null +++ b/src/main/java/net/poweredbyhate/trollplus/managers/TrollPlayerManager.java @@ -0,0 +1,45 @@ +package net.poweredbyhate.trollplus.managers; + +import net.poweredbyhate.trollplus.TrollPlus; +import net.poweredbyhate.trollplus.player.TrollPlayer; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class TrollPlayerManager { + + private final TrollPlus plugin; + private final Map players; + + public TrollPlayerManager(TrollPlus plugin) { + this.plugin = plugin; + players = new HashMap<>(); + } + + public TrollPlayer register(Player player) { + return players.put(player.getUniqueId(), new TrollPlayer(plugin, player.getUniqueId())); + } + + public void deregister(Player player) { + players.remove(player.getUniqueId()); + } + + public TrollPlayer getPlayer(Player player) { + TrollPlayer tPlayer = players.get(player.getUniqueId()); + if (tPlayer == null) { + // This will never happen. I hope. + tPlayer = players.put(player.getUniqueId(), register(player)); + } + return tPlayer; + } + + private void registerPlayers() { + for (Player player : Bukkit.getOnlinePlayers()) { + register(player); + } + } + +} diff --git a/src/main/java/net/poweredbyhate/trollplus/player/TrollPlayer.java b/src/main/java/net/poweredbyhate/trollplus/player/TrollPlayer.java new file mode 100644 index 0000000..fb35c6c --- /dev/null +++ b/src/main/java/net/poweredbyhate/trollplus/player/TrollPlayer.java @@ -0,0 +1,39 @@ +package net.poweredbyhate.trollplus.player; + +import net.poweredbyhate.trollplus.TrollPlus; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import java.util.UUID; + +public class TrollPlayer { + + private final TrollPlus plugin; + private final UUID uuid; + + public TrollPlayer(TrollPlus plugin, UUID uuid) { + this.plugin = plugin; + this.uuid = uuid; + } + + public void sendMessage(String... messages) { + if (messages == null) { + return; + } + for (String message : messages) { + if (message != null) { + getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', message)); + } + } + } + + public boolean hasPermissionOrIsOp(String permission) { + return getPlayer().isOp() || getPlayer().hasPermission(permission); + } + + public Player getPlayer() { + return Bukkit.getPlayer(uuid); + } + +}