From 324a9730903e9fc4c929b02b029bb7250f05ff26 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Fri, 2 Dec 2016 21:26:03 -0500 Subject: [PATCH] Implemented Letter Dyes for testing --- src/alisolarflare/AliPresents.java | 4 +-- .../FlairColouringAPI.java | 7 ++-- .../FlairColouringComponent.java | 32 +++++++++++++++++++ .../letterdyes/GetLetterDye.java | 14 ++++++++ .../flaircolouring/letterdyes/LetterDye.java | 23 +++++++++++++ .../letterdyes/LetterDyeListener.java | 29 +++++++++++++++++ .../portals}/FlairMe.java | 8 ++--- .../portals}/PlayerProximityLoop.java | 8 ++--- .../portals}/PortalListener.java | 10 +++--- .../portals}/SetProximityLocation.java | 2 +- .../flairdoor/FlairDoorComponent.java | 24 -------------- 11 files changed, 119 insertions(+), 42 deletions(-) rename src/alisolarflare/components/{flairdoor => flaircolouring}/FlairColouringAPI.java (90%) create mode 100644 src/alisolarflare/components/flaircolouring/FlairColouringComponent.java create mode 100644 src/alisolarflare/components/flaircolouring/letterdyes/GetLetterDye.java create mode 100644 src/alisolarflare/components/flaircolouring/letterdyes/LetterDye.java create mode 100644 src/alisolarflare/components/flaircolouring/letterdyes/LetterDyeListener.java rename src/alisolarflare/components/{flairdoor/flairme => flaircolouring/portals}/FlairMe.java (69%) rename src/alisolarflare/components/{flairdoor/proximitydetector => flaircolouring/portals}/PlayerProximityLoop.java (88%) rename src/alisolarflare/components/{flairdoor/listeners => flaircolouring/portals}/PortalListener.java (84%) rename src/alisolarflare/components/{flairdoor/proximitydetector => flaircolouring/portals}/SetProximityLocation.java (94%) delete mode 100644 src/alisolarflare/components/flairdoor/FlairDoorComponent.java diff --git a/src/alisolarflare/AliPresents.java b/src/alisolarflare/AliPresents.java index dcc97a9..6b0d4de 100644 --- a/src/alisolarflare/AliPresents.java +++ b/src/alisolarflare/AliPresents.java @@ -9,7 +9,7 @@ import org.bukkit.plugin.java.JavaPlugin; import alisolarflare.components.alilinks.AliLinkComponent; import alisolarflare.components.bankchest.BankChestComponent; import alisolarflare.components.creativeboundaries.CreativeBoundariesComponent; -import alisolarflare.components.flairdoor.FlairDoorComponent; +import alisolarflare.components.flaircolouring.FlairColouringComponent; import alisolarflare.components.gpowers.GPowerComponent; import alisolarflare.components.insurance.InsuranceComponent; import alisolarflare.components.magic.MagicComponent; @@ -26,7 +26,7 @@ public class AliPresents extends JavaPlugin{ new AliLinkComponent().register(this); new BankChestComponent().register(this); new CreativeBoundariesComponent().register(this); - new FlairDoorComponent().register(this); + new FlairColouringComponent().register(this); new GPowerComponent().register(this); new InsuranceComponent().register(this); new MagicComponent().register(this); diff --git a/src/alisolarflare/components/flairdoor/FlairColouringAPI.java b/src/alisolarflare/components/flaircolouring/FlairColouringAPI.java similarity index 90% rename from src/alisolarflare/components/flairdoor/FlairColouringAPI.java rename to src/alisolarflare/components/flaircolouring/FlairColouringAPI.java index 9dce73d..759f761 100644 --- a/src/alisolarflare/components/flairdoor/FlairColouringAPI.java +++ b/src/alisolarflare/components/flaircolouring/FlairColouringAPI.java @@ -1,4 +1,4 @@ -package alisolarflare.components.flairdoor; +package alisolarflare.components.flaircolouring; import org.bukkit.DyeColor; @@ -23,7 +23,10 @@ public class FlairColouringAPI { user.sendMessage("Adding the colour " + colourCode + dyecolour.name() + "§f!"); user.sendMessage("Your name is now: " + user.getNickname() +"!"); } - public static String shiftColoursRight(String input){ + public static String colourShiftRight(String input, DyeColor newDye){ + return dyeToColourCode(newDye) + shiftColoursRight(input); + } + private static String shiftColoursRight(String input){ String output = ""; if (input.length() <= 2){ return input; diff --git a/src/alisolarflare/components/flaircolouring/FlairColouringComponent.java b/src/alisolarflare/components/flaircolouring/FlairColouringComponent.java new file mode 100644 index 0000000..d9c28fa --- /dev/null +++ b/src/alisolarflare/components/flaircolouring/FlairColouringComponent.java @@ -0,0 +1,32 @@ +package alisolarflare.components.flaircolouring; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import com.earth2me.essentials.Essentials; + +import alisolarflare.architecture.Component; +import alisolarflare.components.flaircolouring.letterdyes.GetLetterDye; +import alisolarflare.components.flaircolouring.letterdyes.LetterDyeListener; +import alisolarflare.components.flaircolouring.portals.FlairMe; +import alisolarflare.components.flaircolouring.portals.PlayerProximityLoop; +import alisolarflare.components.flaircolouring.portals.PortalListener; +import alisolarflare.components.flaircolouring.portals.SetProximityLocation; + +public class FlairColouringComponent extends Component { + public List playersToBeFlaired = new ArrayList(); + @Override + public void register(JavaPlugin plugin) { + registerCommand(plugin, new FlairMe(this)); + registerCommand(plugin, new SetProximityLocation()); + registerCommand(plugin, new GetLetterDye()); + + registerListener(plugin, new PortalListener(plugin, this)); + registerListener(plugin, new PlayerProximityLoop(plugin, this)); + registerListener(plugin, new LetterDyeListener((Essentials) Bukkit.getPluginManager().getPlugin("Essentials"))); + } +} diff --git a/src/alisolarflare/components/flaircolouring/letterdyes/GetLetterDye.java b/src/alisolarflare/components/flaircolouring/letterdyes/GetLetterDye.java new file mode 100644 index 0000000..438306b --- /dev/null +++ b/src/alisolarflare/components/flaircolouring/letterdyes/GetLetterDye.java @@ -0,0 +1,14 @@ +package alisolarflare.components.flaircolouring.letterdyes; + +import org.bukkit.entity.Player; + +import alisolarflare.architecture.commands.PlayerCommand; + +public class GetLetterDye extends PlayerCommand{ + @Override + public boolean OnCommand(Player player, String alias, String[] args) { + player.getInventory().addItem(LetterDye.getLetterDye()); + return false; + } + +} diff --git a/src/alisolarflare/components/flaircolouring/letterdyes/LetterDye.java b/src/alisolarflare/components/flaircolouring/letterdyes/LetterDye.java new file mode 100644 index 0000000..506f53c --- /dev/null +++ b/src/alisolarflare/components/flaircolouring/letterdyes/LetterDye.java @@ -0,0 +1,23 @@ +package alisolarflare.components.flaircolouring.letterdyes; + +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +public class LetterDye { + public static boolean isLetterDye(ItemStack item){ + if(item.getType() != Material.INK_SACK) return false; + if(item.getItemMeta().hasEnchant(Enchantment.LUCK) && (item.getItemMeta().getEnchantLevel(Enchantment.LUCK) == 10)) return false; + if(item.getItemMeta().getDisplayName() == "LetterDye") return false; + return true; + } + public static ItemStack getLetterDye(){ + ItemStack item = new ItemStack(Material.INK_SACK); + item.addEnchantment(Enchantment.LUCK, 10); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName("LetterDye"); + item.setItemMeta(meta); + return item; + } +} diff --git a/src/alisolarflare/components/flaircolouring/letterdyes/LetterDyeListener.java b/src/alisolarflare/components/flaircolouring/letterdyes/LetterDyeListener.java new file mode 100644 index 0000000..3befee2 --- /dev/null +++ b/src/alisolarflare/components/flaircolouring/letterdyes/LetterDyeListener.java @@ -0,0 +1,29 @@ +package alisolarflare.components.flaircolouring.letterdyes; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.material.Dye; + +import com.earth2me.essentials.Essentials; +import com.earth2me.essentials.User; + +import alisolarflare.components.flaircolouring.FlairColouringAPI; + +public class LetterDyeListener implements Listener{ + private Essentials essentials; + public LetterDyeListener(Essentials essentials) { + this.essentials = essentials; + } + @EventHandler + public void onLetterDye(PlayerInteractEvent event){ + if((event.getAction() == Action.PHYSICAL)) return; + if (LetterDye.isLetterDye(event.getItem())) return; + + Dye dye = (Dye) event.getItem().getData(); + User user = essentials.getUser(event.getPlayer()); + user.setNickname(FlairColouringAPI.colourShiftRight(user._getNickname(), dye.getColor())); + + } +} diff --git a/src/alisolarflare/components/flairdoor/flairme/FlairMe.java b/src/alisolarflare/components/flaircolouring/portals/FlairMe.java similarity index 69% rename from src/alisolarflare/components/flairdoor/flairme/FlairMe.java rename to src/alisolarflare/components/flaircolouring/portals/FlairMe.java index d41fb1f..5d428cc 100644 --- a/src/alisolarflare/components/flairdoor/flairme/FlairMe.java +++ b/src/alisolarflare/components/flaircolouring/portals/FlairMe.java @@ -1,14 +1,14 @@ -package alisolarflare.components.flairdoor.flairme; +package alisolarflare.components.flaircolouring.portals; import org.bukkit.entity.Player; import alisolarflare.architecture.commands.PlayerCommand; -import alisolarflare.components.flairdoor.FlairDoorComponent; +import alisolarflare.components.flaircolouring.FlairColouringComponent; public class FlairMe extends PlayerCommand { - private FlairDoorComponent component; - public FlairMe(FlairDoorComponent flairDoorComponent) { + private FlairColouringComponent component; + public FlairMe(FlairColouringComponent flairDoorComponent) { this.component = flairDoorComponent; } @Override diff --git a/src/alisolarflare/components/flairdoor/proximitydetector/PlayerProximityLoop.java b/src/alisolarflare/components/flaircolouring/portals/PlayerProximityLoop.java similarity index 88% rename from src/alisolarflare/components/flairdoor/proximitydetector/PlayerProximityLoop.java rename to src/alisolarflare/components/flaircolouring/portals/PlayerProximityLoop.java index e65eff7..fbbe1f8 100644 --- a/src/alisolarflare/components/flairdoor/proximitydetector/PlayerProximityLoop.java +++ b/src/alisolarflare/components/flaircolouring/portals/PlayerProximityLoop.java @@ -1,4 +1,4 @@ -package alisolarflare.components.flairdoor.proximitydetector; +package alisolarflare.components.flaircolouring.portals; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -6,11 +6,11 @@ import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; -import alisolarflare.components.flairdoor.FlairDoorComponent; +import alisolarflare.components.flaircolouring.FlairColouringComponent; public class PlayerProximityLoop extends BukkitRunnable implements Listener{ private static JavaPlugin plugin; - private static FlairDoorComponent component; + private static FlairColouringComponent component; private static Location startLocation; private static Location endLocation; @@ -21,7 +21,7 @@ public class PlayerProximityLoop extends BukkitRunnable implements Listener{ private static int eY; private static int eZ; - public PlayerProximityLoop(JavaPlugin plugin, FlairDoorComponent component) { + public PlayerProximityLoop(JavaPlugin plugin, FlairColouringComponent component) { PlayerProximityLoop.plugin = plugin; PlayerProximityLoop.component = component; this.runTaskTimer(plugin, 0, 20); diff --git a/src/alisolarflare/components/flairdoor/listeners/PortalListener.java b/src/alisolarflare/components/flaircolouring/portals/PortalListener.java similarity index 84% rename from src/alisolarflare/components/flairdoor/listeners/PortalListener.java rename to src/alisolarflare/components/flaircolouring/portals/PortalListener.java index 82f8ba5..8286e47 100644 --- a/src/alisolarflare/components/flairdoor/listeners/PortalListener.java +++ b/src/alisolarflare/components/flaircolouring/portals/PortalListener.java @@ -1,4 +1,4 @@ -package alisolarflare.components.flairdoor.listeners; +package alisolarflare.components.flaircolouring.portals; import org.bukkit.Bukkit; import org.bukkit.DyeColor; @@ -13,17 +13,17 @@ import org.bukkit.plugin.java.JavaPlugin; import com.earth2me.essentials.Essentials; -import alisolarflare.components.flairdoor.FlairColouringAPI; -import alisolarflare.components.flairdoor.FlairDoorComponent; +import alisolarflare.components.flaircolouring.FlairColouringAPI; +import alisolarflare.components.flaircolouring.FlairColouringComponent; public class PortalListener implements Listener{ public JavaPlugin plugin; Essentials essentials; - private FlairDoorComponent component; + private FlairColouringComponent component; - public PortalListener(JavaPlugin plugin, FlairDoorComponent component) { + public PortalListener(JavaPlugin plugin, FlairColouringComponent component) { this.plugin = plugin; this.component = component; this.essentials = ((Essentials) Bukkit.getPluginManager().getPlugin("Essentials")); diff --git a/src/alisolarflare/components/flairdoor/proximitydetector/SetProximityLocation.java b/src/alisolarflare/components/flaircolouring/portals/SetProximityLocation.java similarity index 94% rename from src/alisolarflare/components/flairdoor/proximitydetector/SetProximityLocation.java rename to src/alisolarflare/components/flaircolouring/portals/SetProximityLocation.java index 372d158..f60b8e9 100644 --- a/src/alisolarflare/components/flairdoor/proximitydetector/SetProximityLocation.java +++ b/src/alisolarflare/components/flaircolouring/portals/SetProximityLocation.java @@ -1,4 +1,4 @@ -package alisolarflare.components.flairdoor.proximitydetector; +package alisolarflare.components.flaircolouring.portals; import org.bukkit.entity.Player; diff --git a/src/alisolarflare/components/flairdoor/FlairDoorComponent.java b/src/alisolarflare/components/flairdoor/FlairDoorComponent.java deleted file mode 100644 index e43389d..0000000 --- a/src/alisolarflare/components/flairdoor/FlairDoorComponent.java +++ /dev/null @@ -1,24 +0,0 @@ -package alisolarflare.components.flairdoor; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import alisolarflare.architecture.Component; -import alisolarflare.components.flairdoor.flairme.FlairMe; -import alisolarflare.components.flairdoor.listeners.PortalListener; -import alisolarflare.components.flairdoor.proximitydetector.PlayerProximityLoop; -import alisolarflare.components.flairdoor.proximitydetector.SetProximityLocation; - -public class FlairDoorComponent extends Component { - public List playersToBeFlaired = new ArrayList(); - @Override - public void register(JavaPlugin plugin) { - registerCommand(plugin, new FlairMe(this)); - registerCommand(plugin, new SetProximityLocation()); - registerListener(plugin, new PortalListener(plugin, this)); - registerListener(plugin, new PlayerProximityLoop(plugin, this)); - } -}