Merge pull request #466 from OmniCypher-/master

Adds BendingPlayerCreationEvent and moves login
This commit is contained in:
OmniCypher 2016-03-31 23:26:51 -07:00
commit 392ea3c152
5 changed files with 89 additions and 69 deletions

Binary file not shown.

View file

@ -86,7 +86,7 @@ public class BendingPlayer {
}
PLAYERS.put(uuid, this);
PKListener.login(this);
GeneralMethods.loadBendingPlayer(this);
}
public void addCooldown(Ability ability, long cooldown) {

View file

@ -47,6 +47,7 @@ import com.projectkorra.projectkorra.airbending.AirSwipe;
import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.earthbending.EarthBlast;
import com.projectkorra.projectkorra.earthbending.EarthPassive;
import com.projectkorra.projectkorra.event.BendingPlayerCreationEvent;
import com.projectkorra.projectkorra.event.BendingReloadEvent;
import com.projectkorra.projectkorra.event.BindChangeEvent;
import com.projectkorra.projectkorra.firebending.Combustion;
@ -1275,6 +1276,58 @@ public class GeneralMethods {
return mat != null && (mat == Material.WOOD_AXE || mat == Material.WOOD_PICKAXE || mat == Material.WOOD_SPADE || mat == Material.WOOD_SWORD || mat == Material.STONE_AXE || mat == Material.STONE_PICKAXE || mat == Material.STONE_SPADE || mat == Material.STONE_SWORD || mat == Material.IRON_AXE || mat == Material.IRON_PICKAXE || mat == Material.IRON_SWORD || mat == Material.IRON_SPADE || mat == Material.DIAMOND_AXE || mat == Material.DIAMOND_PICKAXE || mat == Material.DIAMOND_SWORD || mat == Material.DIAMOND_SPADE);
}
public static void loadBendingPlayer(BendingPlayer pl) {
Player player = Bukkit.getPlayer(pl.getUUID());
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
if (bPlayer == null) {
return;
}
if (PKListener.getToggledOut().contains(player.getUniqueId())) {
bPlayer.toggleBending();
player.sendMessage(ChatColor.YELLOW + "Reminder, you toggled your bending before signing off. Enable it again with /bending toggle.");
}
Preset.loadPresets(player);
Element element = null;
String prefix = "";
boolean chatEnabled = ConfigManager.languageConfig.get().getBoolean("Chat.Enable");
if (bPlayer.getElements().size() > 1) {
prefix = Element.AVATAR.getPrefix();
} else if (bPlayer.getElements().size() == 1){
element = bPlayer.getElements().get(0);
prefix = element.getPrefix();
} else {
prefix = ChatColor.WHITE + "[Nonbender] ";
}
if (chatEnabled) {
player.setDisplayName(player.getName());
player.setDisplayName(prefix + ChatColor.RESET + player.getDisplayName());
}
// Handle the AirSpout/WaterSpout login glitches
if (player.getGameMode() != GameMode.CREATIVE) {
HashMap<Integer, String> bound = bPlayer.getAbilities();
for (String str : bound.values()) {
if (str.equalsIgnoreCase("AirSpout") || str.equalsIgnoreCase("WaterSpout") || str.equalsIgnoreCase("SandSpout")) {
final Player fplayer = player;
new BukkitRunnable() {
@Override
public void run() {
fplayer.setFlying(false);
fplayer.setAllowFlight(false);
}
}.runTaskLater(ProjectKorra.plugin, 2);
break;
}
}
}
Bukkit.getServer().getPluginManager().callEvent(new BendingPlayerCreationEvent(bPlayer));
}
public static void reloadPlugin(CommandSender sender) {
ProjectKorra.log.info("Reloading ProjectKorra and configuration");
BendingReloadEvent event = new BendingReloadEvent(sender);

View file

@ -97,7 +97,6 @@ import com.projectkorra.projectkorra.waterbending.WaterPassive;
import com.projectkorra.projectkorra.waterbending.WaterSpout;
import com.projectkorra.projectkorra.waterbending.WaterSpoutWave;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -172,73 +171,6 @@ public class PKListener implements Listener {
this.plugin = plugin;
}
public static void login(BendingPlayer pl) {
ProjectKorra plugin = ProjectKorra.plugin;
Player player = Bukkit.getPlayer(pl.getUUID());
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
if (bPlayer == null) {
return;
}
if (TOGGLED_OUT.contains(player.getUniqueId())) {
bPlayer.toggleBending();
player.sendMessage(ChatColor.YELLOW + "Reminder, you toggled your bending before signing off. Enable it again with /bending toggle.");
}
Preset.loadPresets(player);
String append = "";
ChatColor color = null;
boolean chatEnabled = ProjectKorra.plugin.getConfig().getBoolean("Properties.Chat.Enable");
if (bPlayer.getElements().size() > 1 && chatEnabled) {
append = plugin.getConfig().getString("Properties.Chat.Prefixes.Avatar");
color = ChatColor.valueOf(plugin.getConfig().getString("Properties.Chat.Colors.Avatar"));
} else if (bPlayer.hasElement(Element.AIR) && chatEnabled) {
append = plugin.getConfig().getString("Properties.Chat.Prefixes.Air");
color = Element.AIR.getColor();
} else if (bPlayer.hasElement(Element.WATER) && chatEnabled) {
append = plugin.getConfig().getString("Properties.Chat.Prefixes.Water");
color = Element.WATER.getColor();
} else if (bPlayer.hasElement(Element.EARTH) && chatEnabled) {
append = plugin.getConfig().getString("Properties.Chat.Prefixes.Earth");
color = Element.EARTH.getColor();
} else if (bPlayer.hasElement(Element.FIRE) && chatEnabled) {
append = plugin.getConfig().getString("Properties.Chat.Prefixes.Fire");
color = Element.FIRE.getColor();
} else if (bPlayer.hasElement(Element.CHI) && chatEnabled) {
append = plugin.getConfig().getString("Properties.Chat.Prefixes.Chi");
color = Element.CHI.getColor();
} else {
append = "[Nonbender]";
color = ChatColor.WHITE;
}
if (chatEnabled) {
player.setDisplayName(player.getName());
if(color != null) {
player.setDisplayName(color + append + ChatColor.RESET + player.getDisplayName());
}
}
// Handle the AirSpout/WaterSpout login glitches
if (player.getGameMode() != GameMode.CREATIVE) {
HashMap<Integer, String> bound = bPlayer.getAbilities();
for (String str : bound.values()) {
if (str.equalsIgnoreCase("AirSpout") || str.equalsIgnoreCase("WaterSpout") || str.equalsIgnoreCase("SandSpout")) {
final Player fplayer = player;
new BukkitRunnable() {
@Override
public void run() {
fplayer.setFlying(false);
fplayer.setAllowFlight(false);
}
}.runTaskLater(ProjectKorra.plugin, 2);
break;
}
}
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled()) {

View file

@ -0,0 +1,35 @@
package com.projectkorra.projectkorra.event;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.projectkorra.projectkorra.BendingPlayer;
/**
* Called when a new BendingPlayer is created
*/
public class BendingPlayerCreationEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private BendingPlayer bPlayer;
public BendingPlayerCreationEvent(BendingPlayer bPlayer) {
this.bPlayer = bPlayer;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
/**
* @return BendingPlayer created
*/
public BendingPlayer getBendingPlayer() {
return bPlayer;
}
}