Implemented Letter Dyes for testing

This commit is contained in:
alisolarflare 2016-12-02 21:26:03 -05:00
parent 34f66f78ff
commit 324a973090
11 changed files with 119 additions and 42 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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<Player> playersToBeFlaired = new ArrayList<Player>();
@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")));
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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()));
}
}

View file

@ -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

View file

@ -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);

View file

@ -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"));

View file

@ -1,4 +1,4 @@
package alisolarflare.components.flairdoor.proximitydetector;
package alisolarflare.components.flaircolouring.portals;
import org.bukkit.entity.Player;

View file

@ -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<Player> playersToBeFlaired = new ArrayList<Player>();
@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));
}
}