Fixes and preparing to move things

This commit is contained in:
Norbi Peti 2016-07-01 23:32:41 +02:00
parent f168931496
commit ccdb53023e
4 changed files with 219 additions and 400 deletions

View file

@ -24,23 +24,20 @@ public class ChatProcessing {
// Returns e.setCancelled // Returns e.setCancelled
public static boolean ProcessChat(CommandSender sender, String message) { public static boolean ProcessChat(CommandSender sender, String message) {
if (PlayerListener.essentials == null) if (PlayerListener.essentials == null)
PlayerListener.essentials = (Essentials) (Bukkit.getPluginManager() PlayerListener.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
.getPlugin("Essentials"));
Player player = (sender instanceof Player ? (Player) sender : null); Player player = (sender instanceof Player ? (Player) sender : null);
if (player != null if (player != null && PlayerListener.essentials.getUser(player).isMuted())
&& PlayerListener.essentials.getUser(player).isMuted())
return true; return true;
MaybeOfflinePlayer mp = null; TBMCPlayer mp = null;
if (player != null) { if (player != null) {
mp = MaybeOfflinePlayer.AllPlayers.get(player.getUniqueId()); mp = TBMCPlayer.AllPlayers.get(player.getUniqueId());
if (message.equalsIgnoreCase("F")) { if (message.equalsIgnoreCase("F")) {
if (!mp.PressedF && PlayerListener.ActiveF) { if (!mp.PressedF && PlayerListener.ActiveF) {
PlayerListener.FCount++; PlayerListener.FCount++;
mp.PressedF = true; mp.PressedF = true;
if (PlayerListener.FPlayer != null if (PlayerListener.FPlayer != null && PlayerListener.FPlayer.FCount < Integer.MAX_VALUE - 1)
&& PlayerListener.FPlayer.FCount < Integer.MAX_VALUE - 1)
PlayerListener.FPlayer.FCount++; PlayerListener.FPlayer.FCount++;
} }
} }
@ -59,8 +56,7 @@ public class ChatProcessing {
} }
} }
} }
Channel currentchannel = (mp == null ? PlayerListener.ConsoleChannel Channel currentchannel = (mp == null ? PlayerListener.ConsoleChannel : mp.CurrentChannel);
: mp.CurrentChannel);
ArrayList<ChatFormatter> formatters = new ArrayList<ChatFormatter>(); ArrayList<ChatFormatter> formatters = new ArrayList<ChatFormatter>();
@ -73,8 +69,7 @@ public class ChatProcessing {
colormode = ChatFormatter.Color.Green; colormode = ChatFormatter.Color.Green;
// If greentext, ignore channel or player colors // If greentext, ignore channel or player colors
formatters.add(new ChatFormatter(Pattern.compile(".+"), colormode, "", formatters.add(new ChatFormatter(Pattern.compile(".+"), colormode, "", Priority.Low));
Priority.Low));
String formattedmessage = message; String formattedmessage = message;
formattedmessage = formattedmessage.replace("\\", "\\\\"); formattedmessage = formattedmessage.replace("\\", "\\\\");
@ -83,20 +78,15 @@ public class ChatProcessing {
String suggestmsg = formattedmessage; String suggestmsg = formattedmessage;
formatters formatters.add(new ChatFormatter(Pattern.compile("(?<!\\\\)\\*\\*((?:\\\\\\*|[^\\*])+[^\\*\\\\])\\*\\*"),
.add(new ChatFormatter( ChatFormatter.Format.Bold, "$1"));
Pattern.compile("(?<!\\\\)\\*\\*((?:\\\\\\*|[^\\*])+[^\\*\\\\])\\*\\*"), formatters.add(new ChatFormatter(Pattern.compile("(?<!\\\\)\\*((?:\\\\\\*|[^\\*])+[^\\*\\\\])\\*"),
ChatFormatter.Format.Bold, "$1"));
formatters.add(new ChatFormatter(Pattern
.compile("(?<!\\\\)\\*((?:\\\\\\*|[^\\*])+[^\\*\\\\])\\*"),
ChatFormatter.Format.Italic, "$1")); ChatFormatter.Format.Italic, "$1"));
formatters.add(new ChatFormatter(Pattern formatters.add(new ChatFormatter(Pattern.compile("(?<!\\\\)\\_((?:\\\\\\_|[^\\_])+[^\\_\\\\])\\_"),
.compile("(?<!\\\\)\\_((?:\\\\\\_|[^\\_])+[^\\_\\\\])\\_"),
ChatFormatter.Format.Underlined, "$1")); ChatFormatter.Format.Underlined, "$1"));
// URLs + Rainbow text // URLs + Rainbow text
formatters.add(new ChatFormatter(Pattern formatters.add(new ChatFormatter(Pattern.compile("(http[\\w:/?=$\\-_.+!*'(),]+)"),
.compile("(http[\\w:/?=$\\-_.+!*'(),]+)"),
ChatFormatter.Format.Underlined, "$1")); ChatFormatter.Format.Underlined, "$1"));
/* /*
* formattedmessage = formattedmessage .replace( item, String.format( * formattedmessage = formattedmessage .replace( item, String.format(
@ -113,112 +103,72 @@ public class ChatProcessing {
sb.append(")"); sb.append(")");
formatters formatters
.add(new ChatFormatter( .add(new ChatFormatter(Pattern.compile(sb.toString()), ChatFormatter.Color.Aqua, (String match) -> {
Pattern.compile(sb.toString()), Player p = Bukkit.getPlayer(match);
ChatFormatter.Color.Aqua, if (p == null) {
(String match) -> { System.out.println("Error: Can't find player " + match + " but it was reported as online.");
Player p = Bukkit.getPlayer(match); return false;
if (p == null) { }
System.out TBMCPlayer mpp = TBMCPlayer.AddPlayerIfNeeded(p.getUniqueId());
.println("Error: Can't find player " if (PlayerListener.NotificationSound == null)
+ match p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO:
+ " but it was reported as online."); // Airhorn
return false; else
} p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
MaybeOfflinePlayer mpp = MaybeOfflinePlayer (float) PlayerListener.NotificationPitch);
.AddPlayerIfNeeded(p.getUniqueId()); String color = String.format("§%x", (mpp.GetFlairColor() == 0x00 ? 0xb : mpp.GetFlairColor()));
if (PlayerListener.NotificationSound == null) return true; // TODO
p.playSound(p.getLocation(), }, Priority.High));
Sound.ENTITY_ARROW_HIT_PLAYER,
1.0f, 0.5f); // TODO:
// Airhorn
else
p.playSound(
p.getLocation(),
PlayerListener.NotificationSound,
1.0f,
(float) PlayerListener.NotificationPitch);
String color = String.format("§%x",
(mpp.GetFlairColor() == 0x00 ? 0xb
: mpp.GetFlairColor()));
return true; // TODO
}, Priority.High));
formatters formatters
.add(new ChatFormatter( .add(new ChatFormatter(Pattern.compile(sb.toString()), ChatFormatter.Color.Aqua, (String match) -> {
Pattern.compile(sb.toString()), for (String n : PlayerListener.nicknames.keySet()) {
ChatFormatter.Color.Aqua, String nwithoutformatting = new String(n);
(String match) -> { int index;
for (String n : PlayerListener.nicknames while ((index = nwithoutformatting.indexOf("§k")) != -1)
.keySet()) { nwithoutformatting = nwithoutformatting
String nwithoutformatting = new String(n); .replace("§k" + nwithoutformatting.charAt(index + 2), ""); // Support
int index; // for
while ((index = nwithoutformatting // one
.indexOf("§k")) != -1) // random
nwithoutformatting = nwithoutformatting.replace( // char
"§k" while ((index = nwithoutformatting.indexOf('§')) != -1)
+ nwithoutformatting nwithoutformatting = nwithoutformatting
.charAt(index + 2), .replace("§" + nwithoutformatting.charAt(index + 1), "");
""); // Support if (!match.equalsIgnoreCase(nwithoutformatting))
// for return false; // TODO
// one Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(n));
// random if (p == null) {
// char System.out.println(
while ((index = nwithoutformatting "Error: Can't find player " + match + " but it was reported as online.");
.indexOf('§')) != -1) return false;
nwithoutformatting = nwithoutformatting.replace( }
"§" TBMCPlayer mpp = TBMCPlayer.AddPlayerIfNeeded(p.getUniqueId());
+ nwithoutformatting if (PlayerListener.NotificationSound == null)
.charAt(index + 1), p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO:
""); // Airhorn
if (!match else
.equalsIgnoreCase(nwithoutformatting)) p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
return false; // TODO (float) PlayerListener.NotificationPitch);
Player p = Bukkit String color = String.format("§%x",
.getPlayer(PlayerListener.nicknames (mpp.GetFlairColor() == 0x00 ? 0xb : mpp.GetFlairColor()));
.get(n)); }
if (p == null) { return true; // TODO
System.out }, Priority.High));
.println("Error: Can't find player "
+ match
+ " but it was reported as online.");
return false;
}
MaybeOfflinePlayer mpp = MaybeOfflinePlayer
.AddPlayerIfNeeded(p.getUniqueId());
if (PlayerListener.NotificationSound == null)
p.playSound(p.getLocation(),
Sound.ENTITY_ARROW_HIT_PLAYER,
1.0f, 0.5f); // TODO:
// Airhorn
else
p.playSound(
p.getLocation(),
PlayerListener.NotificationSound,
1.0f,
(float) PlayerListener.NotificationPitch);
String color = String.format("§%x", (mpp
.GetFlairColor() == 0x00 ? 0xb
: mpp.GetFlairColor()));
}
return true; // TODO
}, Priority.High));
} }
pingedconsole = false; pingedconsole = false;
formatters.add(new ChatFormatter(Pattern.compile("(?i)" formatters.add(new ChatFormatter(Pattern.compile("(?i)" + Pattern.quote("@console")), ChatFormatter.Color.Aqua,
+ Pattern.quote("@console")), ChatFormatter.Color.Aqua, ( (String match) -> {
String match) -> { if (!pingedconsole) {
if (!pingedconsole) { System.out.print("\007");
System.out.print("\007"); pingedconsole = true;
pingedconsole = true; }
} return true;
return true; }, Priority.High));
}, Priority.High));
formatters.add(new ChatFormatter(Pattern.compile("#(\\w+)"), formatters.add(new ChatFormatter(Pattern.compile("#(\\w+)"), ChatFormatter.Color.Blue,
ChatFormatter.Color.Blue, "https://twitter.com/hashtag/$1", "https://twitter.com/hashtag/$1", Priority.High));
Priority.High));
/* /*
* if (!hadurls) { * if (!hadurls) {
@ -234,34 +184,27 @@ public class ChatProcessing {
StringBuilder json = new StringBuilder(); StringBuilder json = new StringBuilder();
json.append("[\"\","); json.append("[\"\",");
json.append(String json.append(String.format(
.format("%s{\"text\":\"[%s]%s\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"Copy message\",\"color\":\"blue\"}},\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"%s\"}},", "%s{\"text\":\"[%s]%s\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"Copy message\",\"color\":\"blue\"}},\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"%s\"}},",
(mp != null && mp.ChatOnly ? "{\"text\":\"[C]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Chat only\",\"color\":\"blue\"}]}}}," (mp != null && mp.ChatOnly
// (mp != null && mp.ChatOnly ? ? "{\"text\":\"[C]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Chat only\",\"color\":\"blue\"}]}}},"
// "{\"text:\":\"\"}," - I have been staring at // (mp != null && mp.ChatOnly ?
// this one line for hours... Hours... // "{\"text:\":\"\"}," - I have been staring at
: ""), currentchannel.DisplayName, (mp != null // this one line for hours... Hours...
&& !mp.RPMode ? "[OOC]" : ""), suggestmsg)); : ""),
currentchannel.DisplayName, (mp != null && !mp.RPMode ? "[OOC]" : ""), suggestmsg));
json.append("{\"text\":\" <\"},"); json.append("{\"text\":\" <\"},");
json.append(String.format("{\"text\":\"%s%s\",", json.append(String.format("{\"text\":\"%s%s\",", (player != null ? player.getDisplayName() : sender.getName()),
(player != null ? player.getDisplayName() : sender.getName()),
(mp != null ? mp.GetFormattedFlair() : ""))); (mp != null ? mp.GetFormattedFlair() : "")));
json.append("\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":["); json.append("\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[");
json.append(String.format("{\"text\":\"%s\n\",", json.append(String.format("{\"text\":\"%s\n\",", (player != null ? player.getName() : sender.getName())));
(player != null ? player.getName() : sender.getName()))); json.append(String.format("\"color\":\"aqua\"},{\"text\":\"World: %s\n\",\"color\":\"white\"},",
json.append(String (player != null ? player.getWorld().getName() : "-")));
.format("\"color\":\"aqua\"},{\"text\":\"World: %s\n\",\"color\":\"white\"},", json.append(String.format("{\"text\":\"Respect: %s%s%s\",\"color\":\"white\"}]}}},",
(player != null ? player.getWorld().getName() : "-"))); (mp != null ? (mp.FCount / (double) mp.FDeaths) : "Infinite"),
json.append(String (mp != null && mp.UserName != null && !mp.UserName.isEmpty() ? "\nUserName: " + mp.UserName : ""),
.format("{\"text\":\"Respect: %s%s%s\",\"color\":\"white\"}]}}},", (mp != null && mp.PlayerName.equals("\nAlpha_Bacca44") ? "\nDeaths: " + PlayerListener.AlphaDeaths
(mp != null ? (mp.FCount / (double) mp.FDeaths) : "")));
: "Infinite"),
(mp != null && mp.UserName != null
&& !mp.UserName.isEmpty() ? "\nUserName: "
+ mp.UserName : ""),
(mp != null && mp.PlayerName.equals("\nAlpha_Bacca44") ? "\nDeaths: "
+ PlayerListener.AlphaDeaths
: "")));
json.append("{\"text\":\"> \",\"color\":\"white\"}"); json.append("{\"text\":\"> \",\"color\":\"white\"}");
/* /*
@ -288,25 +231,21 @@ public class ChatProcessing {
json.append("]"); json.append("]");
String jsonstr = json.toString(); String jsonstr = json.toString();
if (jsonstr.length() >= 32767) { if (jsonstr.length() >= 32767) {
sender.sendMessage("§cError: Message too large. Try shortening it, or remove hashtags and other formatting."); sender.sendMessage(
"§cError: Message too large. Try shortening it, or remove hashtags and other formatting.");
return true; return true;
} }
if (currentchannel.equals(Channel.TownChat) if (currentchannel.equals(Channel.TownChat) || currentchannel.equals(Channel.NationChat)) {
|| currentchannel.equals(Channel.NationChat)) {
if (player == null) { if (player == null) {
sender.sendMessage("§cYou are not a player!"); sender.sendMessage("§cYou are not a player!");
return true; return true;
} }
for (Player p : PluginMain.GetPlayers()) { for (Player p : PluginMain.GetPlayers()) {
try { try {
Resident resident = PluginMain.Instance.TU.getResidentMap() Resident resident = PluginMain.Instance.TU.getResidentMap().get(p.getName().toLowerCase());
.get(p.getName().toLowerCase()); if (!resident.getName().equals(player.getName()) && resident.getModes().contains("spy"))
if (!resident.getName().equals(player.getName()) Bukkit.getPlayer(resident.getName()).sendMessage(String.format("[SPY-%s] - %s: %s",
&& resident.getModes().contains("spy")) currentchannel.DisplayName, player.getDisplayName(), message));
Bukkit.getPlayer(resident.getName()).sendMessage(
String.format("[SPY-%s] - %s: %s",
currentchannel.DisplayName,
player.getDisplayName(), message));
} catch (Exception e) { } catch (Exception e) {
} }
} }
@ -315,8 +254,7 @@ public class ChatProcessing {
try { try {
Town town = null; Town town = null;
try { try {
town = PluginMain.Instance.TU.getResidentMap() town = PluginMain.Instance.TU.getResidentMap().get(player.getName().toLowerCase()).getTown();
.get(player.getName().toLowerCase()).getTown();
} catch (NotRegisteredException e) { } catch (NotRegisteredException e) {
} }
if (town == null) { if (town == null) {
@ -331,9 +269,8 @@ public class ChatProcessing {
Objective obj = PluginMain.SB.getObjective("town"); Objective obj = PluginMain.SB.getObjective("town");
for (Player p : PluginMain.GetPlayers()) { for (Player p : PluginMain.GetPlayers()) {
try { try {
if (PluginMain.Instance.TU.getResidentMap() if (PluginMain.Instance.TU.getResidentMap().get(p.getName().toLowerCase()).getTown().getName()
.get(p.getName().toLowerCase()).getTown() .equals(town.getName()))
.getName().equals(town.getName()))
obj.getScore(p.getName()).setScore(index); obj.getScore(p.getName()).setScore(index);
else else
obj.getScore(p.getName()).setScore(-1); obj.getScore(p.getName()).setScore(-1);
@ -341,13 +278,8 @@ public class ChatProcessing {
obj.getScore(p.getName()).setScore(-1); obj.getScore(p.getName()).setScore(-1);
} }
} }
PluginMain.Instance PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
.getServer() String.format("tellraw @a[score_town=%d,score_town_min=%d] %s", index, index, json.toString()));
.dispatchCommand(
PluginMain.Console,
String.format(
"tellraw @a[score_town=%d,score_town_min=%d] %s",
index, index, json.toString()));
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
e.printStackTrace(); e.printStackTrace();
player.sendMessage("§cAn error occured while sending the message. (IllegalStateException)"); player.sendMessage("§cAn error occured while sending the message. (IllegalStateException)");
@ -361,8 +293,7 @@ public class ChatProcessing {
try { try {
Town town = null; Town town = null;
try { try {
town = PluginMain.Instance.TU.getResidentMap() town = PluginMain.Instance.TU.getResidentMap().get(player.getName().toLowerCase()).getTown();
.get(player.getName().toLowerCase()).getTown();
} catch (NotRegisteredException e) { } catch (NotRegisteredException e) {
} }
if (town == null) { if (town == null) {
@ -386,22 +317,16 @@ public class ChatProcessing {
Objective obj = PluginMain.SB.getObjective("nation"); Objective obj = PluginMain.SB.getObjective("nation");
for (Player p : PluginMain.GetPlayers()) { for (Player p : PluginMain.GetPlayers()) {
try { try {
if (PluginMain.Instance.TU.getResidentMap() if (PluginMain.Instance.TU.getResidentMap().get(p.getName().toLowerCase()).getTown().getNation()
.get(p.getName().toLowerCase()).getTown() .getName().equals(nation.getName()))
.getNation().getName().equals(nation.getName()))
obj.getScore(p.getName()).setScore(index); obj.getScore(p.getName()).setScore(index);
else else
obj.getScore(p.getName()).setScore(-1); obj.getScore(p.getName()).setScore(-1);
} catch (Exception e) { } catch (Exception e) {
} }
} }
PluginMain.Instance PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, String
.getServer() .format("tellraw @a[score_nation=%d,score_nation_min=%d] %s", index, index, json.toString()));
.dispatchCommand(
PluginMain.Console,
String.format(
"tellraw @a[score_nation=%d,score_nation_min=%d] %s",
index, index, json.toString()));
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
e.printStackTrace(); e.printStackTrace();
player.sendMessage("§cAn error occured while sending the message. (IllegalStateException)"); player.sendMessage("§cAn error occured while sending the message. (IllegalStateException)");
@ -424,13 +349,8 @@ public class ChatProcessing {
else else
obj.getScore(p.getName()).setScore(0); obj.getScore(p.getName()).setScore(0);
} }
PluginMain.Instance PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
.getServer() String.format("tellraw @a[score_admin=%d,score_admin_min=%d] %s", 1, 1, json.toString()));
.dispatchCommand(
PluginMain.Console,
String.format(
"tellraw @a[score_admin=%d,score_admin_min=%d] %s",
1, 1, json.toString()));
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
e.printStackTrace(); e.printStackTrace();
player.sendMessage("§cAn error occured while sending the message. (IllegalStateException)"); player.sendMessage("§cAn error occured while sending the message. (IllegalStateException)");
@ -442,8 +362,7 @@ public class ChatProcessing {
} }
} else if (currentchannel.equals(Channel.ModChat)) { } else if (currentchannel.equals(Channel.ModChat)) {
try { try {
if (player != null if (player != null && !PluginMain.permission.playerInGroup(player, "mod")) {
&& !PluginMain.permission.playerInGroup(player, "mod")) {
player.sendMessage("§cYou need to be a mod to use this channel."); player.sendMessage("§cYou need to be a mod to use this channel.");
return true; return true;
} }
@ -454,11 +373,8 @@ public class ChatProcessing {
else else
obj.getScore(p.getName()).setScore(0); obj.getScore(p.getName()).setScore(0);
} }
PluginMain.Instance.getServer().dispatchCommand( PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
PluginMain.Console, String.format("tellraw @a[score_mod=%d,score_mod_min=%d] %s", 1, 1, json.toString()));
String.format(
"tellraw @a[score_mod=%d,score_mod_min=%d] %s",
1, 1, json.toString()));
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
e.printStackTrace(); e.printStackTrace();
player.sendMessage("§cAn error occured while sending the message. (IllegalStateException)"); player.sendMessage("§cAn error occured while sending the message. (IllegalStateException)");
@ -471,16 +387,10 @@ public class ChatProcessing {
} else } else
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
String.format("tellraw @a %s", json.toString())); String.format("tellraw @a %s", json.toString()));
PluginMain.Instance PluginMain.Instance.getServer().getConsoleSender()
.getServer() .sendMessage(String.format("[%s] <%s%s> %s", currentchannel.DisplayName,
.getConsoleSender() (player != null ? player.getDisplayName() : sender.getName()),
.sendMessage( (mp != null ? mp.GetFormattedFlair() : ""), message));
String.format("[%s] <%s%s> %s",
currentchannel.DisplayName,
(player != null ? player.getDisplayName()
: sender.getName()),
(mp != null ? mp.GetFormattedFlair() : ""),
message));
return true; return true;
} }
} }

View file

@ -65,11 +65,9 @@ public class PlayerListener implements Listener {
@EventHandler @EventHandler
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
if (essentials == null) if (essentials == null)
essentials = ((Essentials) Bukkit.getPluginManager().getPlugin( essentials = ((Essentials) Bukkit.getPluginManager().getPlugin("Essentials"));
"Essentials"));
final Player p = event.getPlayer(); final Player p = event.getPlayer();
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p TBMCPlayer mp = TBMCPlayer.AddPlayerIfNeeded(p.getUniqueId());
.getUniqueId());
if (!mp.FlairState.equals(FlairStates.NoComment)) { if (!mp.FlairState.equals(FlairStates.NoComment)) {
PluginMain.ConfirmUserMessage(mp); PluginMain.ConfirmUserMessage(mp);
Timer timer = new Timer(); Timer timer = new Timer();
@ -83,7 +81,7 @@ public class PlayerListener implements Listener {
timer.schedule(tt, 1000); timer.schedule(tt, 1000);
} else { } else {
if (mp.GetFlairTime() == 0x00) if (mp.GetFlairTime() == 0x00)
mp.SetFlair(MaybeOfflinePlayer.FlairTimeNone); mp.SetFlair(TBMCPlayer.FlairTimeNone);
Timer timer = new Timer(); Timer timer = new Timer();
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() { PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
@Override @Override
@ -103,15 +101,13 @@ public class PlayerListener implements Listener {
* ispremium && * ispremium &&
*/// Login stuff */// Login stuff
mp.FlairState.equals(FlairStates.NoComment)) { mp.FlairState.equals(FlairStates.NoComment)) {
String json = String String json = String.format(
.format("[\"\",{\"text\":\"If you're from Reddit and you'd like your /r/TheButton flair displayed ingame, write your Minecraft name to \",\"color\":\"aqua\"},{\"text\":\"[this thread].\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread\",\"color\":\"aqua\"}]}}}]", "[\"\",{\"text\":\"If you're from Reddit and you'd like your /r/TheButton flair displayed ingame, write your Minecraft name to \",\"color\":\"aqua\"},{\"text\":\"[this thread].\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread\",\"color\":\"aqua\"}]}}}]",
PluginMain.FlairThreadURL); PluginMain.FlairThreadURL);
PluginMain.Instance.getServer().dispatchCommand( PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
PluginMain.Console,
"tellraw " + mp.PlayerName + " " + json); "tellraw " + mp.PlayerName + " " + json);
json = "[\"\",{\"text\":\"If you aren't from Reddit or don't want the flair, type /u ignore to prevent this message after next login.\",\"color\":\"aqua\"}]"; json = "[\"\",{\"text\":\"If you aren't from Reddit or don't want the flair, type /u ignore to prevent this message after next login.\",\"color\":\"aqua\"}]";
PluginMain.Instance.getServer().dispatchCommand( PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
PluginMain.Console,
"tellraw " + mp.PlayerName + " " + json); "tellraw " + mp.PlayerName + " " + json);
} }
} }
@ -218,15 +214,13 @@ public class PlayerListener implements Listener {
public static boolean ShowRPTag = false; public static boolean ShowRPTag = false;
public static Essentials essentials = null; public static Essentials essentials = null;
final static String[] LaughStrings = new String[] { "xd", "lel", "lawl", final static String[] LaughStrings = new String[] { "xd", "lel", "lawl", "kek", "lmao", "hue", "hah" };
"kek", "lmao", "hue", "hah" };
@EventHandler @EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event) { public void onPlayerChat(AsyncPlayerChatEvent event) {
if (event.isCancelled()) if (event.isCancelled())
return; return;
event.setCancelled(ChatProcessing.ProcessChat(event.getPlayer(), event.setCancelled(ChatProcessing.ProcessChat(event.getPlayer(), event.getMessage()));
event.getMessage()));
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
@ -234,53 +228,42 @@ public class PlayerListener implements Listener {
if (event.getMessage().length() < 2) if (event.getMessage().length() < 2)
return; return;
int index = event.getMessage().indexOf(" "); int index = event.getMessage().indexOf(" ");
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(event TBMCPlayer mp = TBMCPlayer.AllPlayers.get(event.getPlayer().getUniqueId());
.getPlayer().getUniqueId());
String cmd = ""; String cmd = "";
if (index == -1) { if (index == -1) {
cmd = event.getMessage().substring(1); cmd = event.getMessage().substring(1);
// System.out.println("cmd: " + cmd); // System.out.println("cmd: " + cmd);
if (cmd.equalsIgnoreCase(Channel.GlobalChat.Command)) { if (cmd.equalsIgnoreCase(Channel.GlobalChat.Command)) {
mp.CurrentChannel = Channel.GlobalChat; mp.CurrentChannel = Channel.GlobalChat;
event.getPlayer().sendMessage( event.getPlayer().sendMessage("§6You are now talking in: §b" + mp.CurrentChannel.DisplayName);
"§6You are now talking in: §b"
+ mp.CurrentChannel.DisplayName);
event.setCancelled(true); event.setCancelled(true);
} else if (cmd.equalsIgnoreCase(Channel.TownChat.Command)) { } else if (cmd.equalsIgnoreCase(Channel.TownChat.Command)) {
if (mp.CurrentChannel.equals(Channel.TownChat)) if (mp.CurrentChannel.equals(Channel.TownChat))
mp.CurrentChannel = Channel.GlobalChat; mp.CurrentChannel = Channel.GlobalChat;
else else
mp.CurrentChannel = Channel.TownChat; mp.CurrentChannel = Channel.TownChat;
event.getPlayer().sendMessage( event.getPlayer().sendMessage("§6You are now talking in: §b" + mp.CurrentChannel.DisplayName);
"§6You are now talking in: §b"
+ mp.CurrentChannel.DisplayName);
event.setCancelled(true); event.setCancelled(true);
} else if (cmd.equalsIgnoreCase(Channel.NationChat.Command)) { } else if (cmd.equalsIgnoreCase(Channel.NationChat.Command)) {
if (mp.CurrentChannel.equals(Channel.NationChat)) if (mp.CurrentChannel.equals(Channel.NationChat))
mp.CurrentChannel = Channel.GlobalChat; mp.CurrentChannel = Channel.GlobalChat;
else else
mp.CurrentChannel = Channel.NationChat; mp.CurrentChannel = Channel.NationChat;
event.getPlayer().sendMessage( event.getPlayer().sendMessage("§6You are now talking in: §b" + mp.CurrentChannel.DisplayName);
"§6You are now talking in: §b"
+ mp.CurrentChannel.DisplayName);
event.setCancelled(true); event.setCancelled(true);
} else if (cmd.equalsIgnoreCase(Channel.AdminChat.Command)) { } else if (cmd.equalsIgnoreCase(Channel.AdminChat.Command)) {
if (mp.CurrentChannel.equals(Channel.AdminChat)) if (mp.CurrentChannel.equals(Channel.AdminChat))
mp.CurrentChannel = Channel.GlobalChat; mp.CurrentChannel = Channel.GlobalChat;
else else
mp.CurrentChannel = Channel.AdminChat; mp.CurrentChannel = Channel.AdminChat;
event.getPlayer().sendMessage( event.getPlayer().sendMessage("§6You are now talking in: §b" + mp.CurrentChannel.DisplayName);
"§6You are now talking in: §b"
+ mp.CurrentChannel.DisplayName);
event.setCancelled(true); event.setCancelled(true);
} else if (cmd.equalsIgnoreCase(Channel.ModChat.Command)) { } else if (cmd.equalsIgnoreCase(Channel.ModChat.Command)) {
if (mp.CurrentChannel.equals(Channel.ModChat)) if (mp.CurrentChannel.equals(Channel.ModChat))
mp.CurrentChannel = Channel.GlobalChat; mp.CurrentChannel = Channel.GlobalChat;
else else
mp.CurrentChannel = Channel.ModChat; mp.CurrentChannel = Channel.ModChat;
event.getPlayer().sendMessage( event.getPlayer().sendMessage("§6You are now talking in: §b" + mp.CurrentChannel.DisplayName);
"§6You are now talking in: §b"
+ mp.CurrentChannel.DisplayName);
event.setCancelled(true); event.setCancelled(true);
} }
} else { } else {
@ -317,20 +300,16 @@ public class PlayerListener implements Listener {
event.getPlayer().chat(event.getMessage().substring(index + 1)); event.getPlayer().chat(event.getMessage().substring(index + 1));
mp.CurrentChannel = c; mp.CurrentChannel = c;
} else if (cmd.equalsIgnoreCase("tpahere")) { } else if (cmd.equalsIgnoreCase("tpahere")) {
Player player = Bukkit.getPlayer(event.getMessage().substring( Player player = Bukkit.getPlayer(event.getMessage().substring(index + 1));
index + 1));
if (player != null) if (player != null)
player.sendMessage("§b" player.sendMessage("§b" + event.getPlayer().getDisplayName() + " §bis in this world: "
+ event.getPlayer().getDisplayName()
+ " §bis in this world: "
+ event.getPlayer().getWorld().getName()); + event.getPlayer().getWorld().getName());
} else if (cmd.equalsIgnoreCase("minecraft:me")) { } else if (cmd.equalsIgnoreCase("minecraft:me")) {
if (!essentials.getUser(event.getPlayer()).isMuted()) { if (!essentials.getUser(event.getPlayer()).isMuted()) {
event.setCancelled(true); event.setCancelled(true);
String message = event.getMessage().substring(index + 1); String message = event.getMessage().substring(index + 1);
for (Player p : PluginMain.GetPlayers()) for (Player p : PluginMain.GetPlayers())
p.sendMessage(String.format("* %s %s", event p.sendMessage(String.format("* %s %s", event.getPlayer().getDisplayName(), message));
.getPlayer().getDisplayName(), message));
} }
} }
/* /*
@ -384,21 +363,16 @@ public class PlayerListener implements Listener {
if (cmd.equalsIgnoreCase("sethome")) { if (cmd.equalsIgnoreCase("sethome")) {
TownyUniverse tu = PluginMain.Instance.TU; TownyUniverse tu = PluginMain.Instance.TU;
try { try {
TownBlock tb = WorldCoord.parseWorldCoord(event.getPlayer()) TownBlock tb = WorldCoord.parseWorldCoord(event.getPlayer()).getTownBlock();
.getTownBlock();
if (tb.hasTown()) { if (tb.hasTown()) {
Town town = tb.getTown(); Town town = tb.getTown();
if (town.hasNation()) { if (town.hasNation()) {
Resident res = tu.getResidentMap().get( Resident res = tu.getResidentMap().get(event.getPlayer().getName());
event.getPlayer().getName());
if (res != null && res.hasTown()) { if (res != null && res.hasTown()) {
Town town2 = res.getTown(); Town town2 = res.getTown();
if (town2.hasNation()) { if (town2.hasNation()) {
if (town.getNation().getEnemies() if (town.getNation().getEnemies().contains(town2.getNation())) {
.contains(town2.getNation())) { event.getPlayer().sendMessage("§cYou cannot set homes in enemy territory.");
event.getPlayer()
.sendMessage(
"§cYou cannot set homes in enemy territory.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -409,31 +383,23 @@ public class PlayerListener implements Listener {
} catch (NotRegisteredException e) { } catch (NotRegisteredException e) {
return; return;
} }
} else if (cmd.equalsIgnoreCase("home") || cmd.equalsIgnoreCase("tpa") } else if (cmd.equalsIgnoreCase("home") || cmd.equalsIgnoreCase("tpa") || cmd.equalsIgnoreCase("tp")) {
|| cmd.equalsIgnoreCase("tp")) { MinigamePlayer mgp = Minigames.plugin.pdata.getMinigamePlayer(event.getPlayer());
MinigamePlayer mgp = Minigames.plugin.pdata.getMinigamePlayer(event String currentWorld = event.getPlayer().getLocation().getWorld().getName();
.getPlayer());
String currentWorld = event.getPlayer().getLocation().getWorld()
.getName();
Location currentLocation = event.getPlayer().getLocation(); Location currentLocation = event.getPlayer().getLocation();
TownyUniverse universe = Towny.getPlugin(Towny.class) TownyUniverse universe = Towny.getPlugin(Towny.class).getTownyUniverse();
.getTownyUniverse(); if (mgp.isInMinigame() && mgp.getMinigame().getMechanic().getMechanic().equals("creativeglobal")) {
if (mgp.isInMinigame()
&& mgp.getMinigame().getMechanic().getMechanic()
.equals("creativeglobal")) {
mgp.setAllowTeleport(true); mgp.setAllowTeleport(true);
} else if (TownyUniverse.isWarTime()) { } else if (TownyUniverse.isWarTime()) {
War war = universe.getWarEvent(); War war = universe.getWarEvent();
if (war.isWarZone(new WorldCoord(currentWorld, currentLocation if (war.isWarZone(
.getBlockX(), currentLocation.getBlockZ()))) { new WorldCoord(currentWorld, currentLocation.getBlockX(), currentLocation.getBlockZ()))) {
event.getPlayer().sendMessage( event.getPlayer().sendMessage("§cError: You can't teleport out of a war zone!");
"§cError: You can't teleport out of a war zone!");
event.setCancelled(true); event.setCancelled(true);
} }
} }
} else if (cmd.toLowerCase().startsWith("un")) { } else if (cmd.toLowerCase().startsWith("un")) {
for (HelpTopic ht : PluginMain.Instance.getServer().getHelpMap() for (HelpTopic ht : PluginMain.Instance.getServer().getHelpMap().getHelpTopics()) {
.getHelpTopics()) {
// event.getPlayer().sendMessage("HT: " + ht.getName()); // event.getPlayer().sendMessage("HT: " + ht.getName());
if (ht.getName().equalsIgnoreCase("/" + cmd)) if (ht.getName().equalsIgnoreCase("/" + cmd))
return; return;
@ -441,27 +407,18 @@ public class PlayerListener implements Listener {
if (PluginMain.permission.has(event.getPlayer(), "tbmc.admin")) { if (PluginMain.permission.has(event.getPlayer(), "tbmc.admin")) {
String s = cmd.substring(2); String s = cmd.substring(2);
Player target = null; Player target = null;
target = Bukkit.getPlayer(event.getMessage().substring( target = Bukkit.getPlayer(event.getMessage().substring(index + 1));
index + 1));
if (target == null) { if (target == null) {
event.getPlayer().sendMessage( event.getPlayer().sendMessage("§cError: Player not found. (/un" + s + " <player>)");
"§cError: Player not found. (/un" + s
+ " <player>)");
event.setCancelled(true); event.setCancelled(true);
} }
if (target != null) { if (target != null) {
target.addPotionEffect(new PotionEffect( target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
PotionEffectType.BLINDNESS, 10 * 20, 5, false,
false));
for (Player pl : PluginMain.GetPlayers()) for (Player pl : PluginMain.GetPlayers())
pl.sendMessage(event.getPlayer().getDisplayName() pl.sendMessage(
+ " un" + s + "'d " + target.getDisplayName()); event.getPlayer().getDisplayName() + " un" + s + "'d " + target.getDisplayName());
Bukkit.getServer() Bukkit.getServer().getConsoleSender().sendMessage(
.getConsoleSender() event.getPlayer().getDisplayName() + " un" + s + "'d " + target.getDisplayName());
.sendMessage(
event.getPlayer().getDisplayName() + " un"
+ s + "'d "
+ target.getDisplayName());
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -469,12 +426,9 @@ public class PlayerListener implements Listener {
if (cmd.equalsIgnoreCase("f")) { if (cmd.equalsIgnoreCase("f")) {
String[] args = event.getMessage().substring(index + 1).split(" "); String[] args = event.getMessage().substring(index + 1).split(" ");
if (args.length > 1) { if (args.length > 1) {
if (args[0].toLowerCase().equals("enemy") if (args[0].toLowerCase().equals("enemy") && args[1].equalsIgnoreCase("newhaven")) {
&& args[1].equalsIgnoreCase("newhaven")) {
event.setCancelled(true); event.setCancelled(true);
event.getPlayer() event.getPlayer().sendMessage("§cYou are not allowed to set New Haven as your enemy faction.");
.sendMessage(
"§cYou are not allowed to set New Haven as your enemy faction.");
} }
} }
} }
@ -487,18 +441,15 @@ public class PlayerListener implements Listener {
String nwithoutformatting = nickname; String nwithoutformatting = nickname;
int index; int index;
while ((index = nwithoutformatting.indexOf("§k")) != -1) while ((index = nwithoutformatting.indexOf("§k")) != -1)
nwithoutformatting = nwithoutformatting.replace("§k" nwithoutformatting = nwithoutformatting.replace("§k" + nwithoutformatting.charAt(index + 2), ""); // Support
+ nwithoutformatting.charAt(index + 2), ""); // Support // for
// for // one
// one // random
// random // char
// char
while ((index = nwithoutformatting.indexOf('§')) != -1) while ((index = nwithoutformatting.indexOf('§')) != -1)
nwithoutformatting = nwithoutformatting.replace("§" nwithoutformatting = nwithoutformatting.replace("§" + nwithoutformatting.charAt(index + 1), "");
+ nwithoutformatting.charAt(index + 1), "");
if (nwithoutformatting.startsWith(name) if (nwithoutformatting.startsWith(name)
&& !nwithoutformatting.equals(Bukkit.getPlayer( && !nwithoutformatting.equals(Bukkit.getPlayer(nicknames.get(nickname)).getName()))
nicknames.get(nickname)).getName()))
e.getTabCompletions().add(nwithoutformatting); e.getTabCompletions().add(nwithoutformatting);
} }
} }
@ -518,7 +469,7 @@ public class PlayerListener implements Listener {
static boolean ActiveF = false; static boolean ActiveF = false;
static int FCount = 0; static int FCount = 0;
static MaybeOfflinePlayer FPlayer = null; static TBMCPlayer FPlayer = null;
private Timer Ftimer; private Timer Ftimer;
public static int AlphaDeaths; public static int AlphaDeaths;
@ -526,8 +477,7 @@ public class PlayerListener implements Listener {
public void onPlayerDeath(PlayerDeathEvent e) { public void onPlayerDeath(PlayerDeathEvent e) {
if (e.getEntity().getName().equals("Alpha_Bacca44")) if (e.getEntity().getName().equals("Alpha_Bacca44"))
AlphaDeaths++; AlphaDeaths++;
MinigamePlayer mgp = Minigames.plugin.pdata.getMinigamePlayer(e MinigamePlayer mgp = Minigames.plugin.pdata.getMinigamePlayer(e.getEntity());
.getEntity());
if ((mgp != null && !mgp.isInMinigame()) && new Random().nextBoolean()) { // Don't if ((mgp != null && !mgp.isInMinigame()) && new Random().nextBoolean()) { // Don't
// store // store
// Fs // Fs
@ -537,12 +487,10 @@ public class PlayerListener implements Listener {
Ftimer.cancel(); Ftimer.cancel();
ActiveF = true; ActiveF = true;
FCount = 0; FCount = 0;
FPlayer = MaybeOfflinePlayer.AllPlayers.get(e.getEntity() FPlayer = TBMCPlayer.AllPlayers.get(e.getEntity().getUniqueId());
.getUniqueId());
FPlayer.FDeaths++; FPlayer.FDeaths++;
for (Player p : PluginMain.GetPlayers()) { for (Player p : PluginMain.GetPlayers()) {
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p TBMCPlayer mp = TBMCPlayer.AllPlayers.get(p.getUniqueId());
.getUniqueId());
mp.PressedF = false; mp.PressedF = false;
p.sendMessage("§bPress F to pay respects.§r"); p.sendMessage("§bPress F to pay respects.§r");
} }
@ -553,8 +501,7 @@ public class PlayerListener implements Listener {
if (ActiveF) { if (ActiveF) {
ActiveF = false; ActiveF = false;
for (Player p : PluginMain.GetPlayers()) { for (Player p : PluginMain.GetPlayers()) {
p.sendMessage("§b" + FCount + " " p.sendMessage("§b" + FCount + " " + (FCount == 1 ? "person" : "people")
+ (FCount == 1 ? "person" : "people")
+ " paid their respects.§r"); + " paid their respects.§r");
} }
} }
@ -567,8 +514,7 @@ public class PlayerListener implements Listener {
@EventHandler @EventHandler
public void onPlayerItemPickup(PlayerPickupItemEvent e) { public void onPlayerItemPickup(PlayerPickupItemEvent e) {
// System.out.println("A"); // System.out.println("A");
MinigamePlayer mp = Minigames.plugin.pdata.getMinigamePlayer(e MinigamePlayer mp = Minigames.plugin.pdata.getMinigamePlayer(e.getPlayer());
.getPlayer());
// System.out.println("B"); // System.out.println("B");
/* /*
@ -576,30 +522,25 @@ public class PlayerListener implements Listener {
* mp.getMinigame().getName(false) * mp.getMinigame().getName(false)
* .equalsIgnoreCase(Commands.KittyCannonMinigame))) return; * .equalsIgnoreCase(Commands.KittyCannonMinigame))) return;
*/ */
if (!(mp.isInMinigame() && mp.getMinigame().getName(false) if (!(mp.isInMinigame()
.equalsIgnoreCase(KittycannonCommand.KittyCannonMinigame))) && mp.getMinigame().getName(false).equalsIgnoreCase(KittycannonCommand.KittyCannonMinigame)))
return; return;
// System.out.println("C"); // System.out.println("C");
ItemStack item = e.getItem().getItemStack(); ItemStack item = e.getItem().getItemStack();
if (!item.getType().equals(Material.SKULL_ITEM) if (!item.getType().equals(Material.SKULL_ITEM) && !item.getType().equals(Material.SKULL))
&& !item.getType().equals(Material.SKULL))
return; return;
// System.out.println("D"); // System.out.println("D");
SkullMeta meta = (SkullMeta) item.getItemMeta(); SkullMeta meta = (SkullMeta) item.getItemMeta();
if (!meta.getDisplayName().equals("§rOcelot Head") if (!meta.getDisplayName().equals("§rOcelot Head") || !meta.getOwner().equals("MHF_Ocelot"))
|| !meta.getOwner().equals("MHF_Ocelot"))
return; return;
// System.out.println("E"); // System.out.println("E");
if (meta.getLore() == null || meta.getLore().size() == 0) if (meta.getLore() == null || meta.getLore().size() == 0)
return; return;
// System.out.println("F"); // System.out.println("F");
ItemStack hat = e.getPlayer().getInventory().getHelmet(); ItemStack hat = e.getPlayer().getInventory().getHelmet();
if (!(hat != null if (!(hat != null && (hat.getType().equals(Material.SKULL) || hat.getType().equals(Material.SKULL_ITEM))
&& (hat.getType().equals(Material.SKULL) || hat.getType() && ((SkullMeta) hat.getItemMeta()).getDisplayName().equals("§rWolf Head")))
.equals(Material.SKULL_ITEM)) && ((SkullMeta) hat e.getPlayer().damage(1f * item.getAmount(), Bukkit.getPlayer(meta.getLore().get(0)));
.getItemMeta()).getDisplayName().equals("§rWolf Head")))
e.getPlayer().damage(1f * item.getAmount(),
Bukkit.getPlayer(meta.getLore().get(0)));
e.getItem().remove(); e.getItem().remove();
e.setCancelled(true); e.setCancelled(true);
} }
@ -609,8 +550,7 @@ public class PlayerListener implements Listener {
public void onVotifierEvent(VotifierEvent event) { public void onVotifierEvent(VotifierEvent event) {
Vote vote = event.getVote(); Vote vote = event.getVote();
System.out.println("Vote: " + vote); System.out.println("Vote: " + vote);
org.bukkit.OfflinePlayer op = Bukkit.getOfflinePlayer(vote org.bukkit.OfflinePlayer op = Bukkit.getOfflinePlayer(vote.getUsername());
.getUsername());
Player p = Bukkit.getPlayer(vote.getUsername()); Player p = Bukkit.getPlayer(vote.getUsername());
if (op != null) { if (op != null) {
PluginMain.economy.depositPlayer(op, 50.0); PluginMain.economy.depositPlayer(op, 50.0);
@ -623,29 +563,24 @@ public class PlayerListener implements Listener {
@EventHandler @EventHandler
public void onPlayerMove(PlayerMoveEvent e) { public void onPlayerMove(PlayerMoveEvent e) {
// minecraft:tp @a[x=190,y=-80,z=45,dx=5,dy=50,dz=5] 190 1 45 // minecraft:tp @a[x=190,y=-80,z=45,dx=5,dy=50,dz=5] 190 1 45
if (e.getPlayer().getWorld().getName().equals("wilds") if (e.getPlayer().getWorld().getName().equals("wilds") && e.getTo().getBlockX() > 100
&& e.getTo().getBlockX() > 100 && e.getTo().getBlockX() < 250 && e.getTo().getBlockX() < 250 && e.getTo().getBlockZ() > 0 && e.getTo().getBlockZ() < 200
&& e.getTo().getBlockZ() > 0 && e.getTo().getBlockZ() < 200
&& e.getTo().getBlockY() < -64) { && e.getTo().getBlockY() < -64) {
final Player p = e.getPlayer(); final Player p = e.getPlayer();
p.setVelocity(new Vector(0, 0, 0)); p.setVelocity(new Vector(0, 0, 0));
p.setFallDistance(0); p.setFallDistance(0);
Bukkit.getServer() Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(PluginMain.Instance, new Runnable() {
.getScheduler() public void run() {
.scheduleSyncDelayedTask(PluginMain.Instance, p.setVelocity(new Vector(0, 0, 0));
new Runnable() { p.setFallDistance(0);
public void run() { p.teleport(new Location(Bukkit.getWorld("wilds"), 190, 1, 50));
p.setVelocity(new Vector(0, 0, 0)); p.setVelocity(new Vector(0, 0, 0));
p.setFallDistance(0); p.setFallDistance(0);
p.teleport(new Location(Bukkit }
.getWorld("wilds"), 190, 1, 50)); });
p.setVelocity(new Vector(0, 0, 0));
p.setFallDistance(0);
}
});
} }
MaybeOfflinePlayer mp = MaybeOfflinePlayer.GetFromPlayer(e.getPlayer()); TBMCPlayer mp = TBMCPlayer.GetFromPlayer(e.getPlayer());
if (mp.ChatOnly) if (mp.ChatOnly)
e.setCancelled(true); e.setCancelled(true);
} }
@ -669,32 +604,25 @@ public class PlayerListener implements Listener {
* "§cYou are not allowed to teleport to/from No Mans Land."); } * "§cYou are not allowed to teleport to/from No Mans Land."); }
*/ */
if (MaybeOfflinePlayer.GetFromPlayer(e.getPlayer()).ChatOnly) { if (TBMCPlayer.GetFromPlayer(e.getPlayer()).ChatOnly) {
e.setCancelled(true); e.setCancelled(true);
e.getPlayer() e.getPlayer().sendMessage("§cYou are not allowed to teleport while in chat-only mode.");
.sendMessage(
"§cYou are not allowed to teleport while in chat-only mode.");
} }
} }
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent e) { public void onPlayerInteract(PlayerInteractEvent e) {
MinigamePlayer mp = Minigames.plugin.pdata.getMinigamePlayer(e MinigamePlayer mp = Minigames.plugin.pdata.getMinigamePlayer(e.getPlayer());
.getPlayer());
if (mp == null) if (mp == null)
return; return;
if (mp.isInMinigame() if (mp.isInMinigame() && mp.getMinigame().getName(false).equalsIgnoreCase("twohundred")) {
&& mp.getMinigame().getName(false)
.equalsIgnoreCase("twohundred")) {
Block block = e.getClickedBlock(); Block block = e.getClickedBlock();
if (block == null) if (block == null)
return; return;
if (block.getType() == Material.ENDER_CHEST) { if (block.getType() == Material.ENDER_CHEST) {
e.setCancelled(true); e.setCancelled(true);
e.getPlayer().sendMessage( e.getPlayer().sendMessage("§You are not allowed to use enderchests here.");
"§You are not allowed to use enderchests here."); System.out.println(e.getPlayer().getName() + " tried to use an enderchest in twohundred.");
System.out.println(e.getPlayer().getName()
+ " tried to use an enderchest in twohundred.");
} }
} }
} }
@ -711,27 +639,21 @@ public class PlayerListener implements Listener {
cmd = event.getCommand(); cmd = event.getCommand();
if (cmd.equalsIgnoreCase(Channel.GlobalChat.Command)) { if (cmd.equalsIgnoreCase(Channel.GlobalChat.Command)) {
ConsoleChannel = Channel.GlobalChat; ConsoleChannel = Channel.GlobalChat;
event.getSender().sendMessage( event.getSender().sendMessage("§6You are now talking in: §b" + ConsoleChannel.DisplayName);
"§6You are now talking in: §b"
+ ConsoleChannel.DisplayName);
event.setCommand("dontrunthiscmd"); event.setCommand("dontrunthiscmd");
} else if (cmd.equalsIgnoreCase(Channel.AdminChat.Command)) { } else if (cmd.equalsIgnoreCase(Channel.AdminChat.Command)) {
if (ConsoleChannel.equals(Channel.AdminChat)) if (ConsoleChannel.equals(Channel.AdminChat))
ConsoleChannel = Channel.GlobalChat; ConsoleChannel = Channel.GlobalChat;
else else
ConsoleChannel = Channel.AdminChat; ConsoleChannel = Channel.AdminChat;
event.getSender().sendMessage( event.getSender().sendMessage("§6You are now talking in: §b" + ConsoleChannel.DisplayName);
"§6You are now talking in: §b"
+ ConsoleChannel.DisplayName);
event.setCommand("dontrunthiscmd"); event.setCommand("dontrunthiscmd");
} else if (cmd.equalsIgnoreCase(Channel.ModChat.Command)) { } else if (cmd.equalsIgnoreCase(Channel.ModChat.Command)) {
if (ConsoleChannel.equals(Channel.ModChat)) if (ConsoleChannel.equals(Channel.ModChat))
ConsoleChannel = Channel.GlobalChat; ConsoleChannel = Channel.GlobalChat;
else else
ConsoleChannel = Channel.ModChat; ConsoleChannel = Channel.ModChat;
event.getSender().sendMessage( event.getSender().sendMessage("§6You are now talking in: §b" + ConsoleChannel.DisplayName);
"§6You are now talking in: §b"
+ ConsoleChannel.DisplayName);
event.setCommand("dontrunthiscmd"); event.setCommand("dontrunthiscmd");
} }
} else { } else {
@ -739,48 +661,42 @@ public class PlayerListener implements Listener {
if (cmd.equalsIgnoreCase(Channel.GlobalChat.Command)) { if (cmd.equalsIgnoreCase(Channel.GlobalChat.Command)) {
Channel c = ConsoleChannel; Channel c = ConsoleChannel;
ConsoleChannel = Channel.GlobalChat; ConsoleChannel = Channel.GlobalChat;
ChatProcessing.ProcessChat(Bukkit.getServer() ChatProcessing.ProcessChat(Bukkit.getServer().getConsoleSender(),
.getConsoleSender(),
event.getCommand().substring(index + 1)); event.getCommand().substring(index + 1));
ConsoleChannel = c; ConsoleChannel = c;
event.setCommand("dontrunthiscmd"); event.setCommand("dontrunthiscmd");
} else if (cmd.equalsIgnoreCase(Channel.TownChat.Command)) { } else if (cmd.equalsIgnoreCase(Channel.TownChat.Command)) {
Channel c = ConsoleChannel; Channel c = ConsoleChannel;
ConsoleChannel = Channel.TownChat; ConsoleChannel = Channel.TownChat;
ChatProcessing.ProcessChat(Bukkit.getServer() ChatProcessing.ProcessChat(Bukkit.getServer().getConsoleSender(),
.getConsoleSender(),
event.getCommand().substring(index + 1)); event.getCommand().substring(index + 1));
ConsoleChannel = c; ConsoleChannel = c;
event.setCommand("dontrunthiscmd"); event.setCommand("dontrunthiscmd");
} else if (cmd.equalsIgnoreCase(Channel.NationChat.Command)) { } else if (cmd.equalsIgnoreCase(Channel.NationChat.Command)) {
Channel c = ConsoleChannel; Channel c = ConsoleChannel;
ConsoleChannel = Channel.NationChat; ConsoleChannel = Channel.NationChat;
ChatProcessing.ProcessChat(Bukkit.getServer() ChatProcessing.ProcessChat(Bukkit.getServer().getConsoleSender(),
.getConsoleSender(),
event.getCommand().substring(index + 1)); event.getCommand().substring(index + 1));
ConsoleChannel = c; ConsoleChannel = c;
event.setCommand("dontrunthiscmd"); event.setCommand("dontrunthiscmd");
} else if (cmd.equalsIgnoreCase(Channel.AdminChat.Command)) { } else if (cmd.equalsIgnoreCase(Channel.AdminChat.Command)) {
Channel c = ConsoleChannel; Channel c = ConsoleChannel;
ConsoleChannel = Channel.AdminChat; ConsoleChannel = Channel.AdminChat;
ChatProcessing.ProcessChat(Bukkit.getServer() ChatProcessing.ProcessChat(Bukkit.getServer().getConsoleSender(),
.getConsoleSender(),
event.getCommand().substring(index + 1)); event.getCommand().substring(index + 1));
ConsoleChannel = c; ConsoleChannel = c;
event.setCommand("dontrunthiscmd"); event.setCommand("dontrunthiscmd");
} else if (cmd.equalsIgnoreCase(Channel.ModChat.Command)) { } else if (cmd.equalsIgnoreCase(Channel.ModChat.Command)) {
Channel c = ConsoleChannel; Channel c = ConsoleChannel;
ConsoleChannel = Channel.ModChat; ConsoleChannel = Channel.ModChat;
ChatProcessing.ProcessChat(Bukkit.getServer() ChatProcessing.ProcessChat(Bukkit.getServer().getConsoleSender(),
.getConsoleSender(),
event.getCommand().substring(index + 1)); event.getCommand().substring(index + 1));
ConsoleChannel = c; ConsoleChannel = c;
event.setCommand("dontrunthiscmd"); event.setCommand("dontrunthiscmd");
} }
} }
if (cmd.toLowerCase().startsWith("un")) { if (cmd.toLowerCase().startsWith("un")) {
for (HelpTopic ht : PluginMain.Instance.getServer().getHelpMap() for (HelpTopic ht : PluginMain.Instance.getServer().getHelpMap().getHelpTopics()) {
.getHelpTopics()) {
// event.getSender().sendMessage("HT: " + ht.getName()); // event.getSender().sendMessage("HT: " + ht.getName());
if (ht.getName().equalsIgnoreCase("/" + cmd)) if (ht.getName().equalsIgnoreCase("/" + cmd))
return; return;
@ -789,21 +705,15 @@ public class PlayerListener implements Listener {
Player target = null; Player target = null;
target = Bukkit.getPlayer(event.getCommand().substring(index + 1)); target = Bukkit.getPlayer(event.getCommand().substring(index + 1));
if (target == null) { if (target == null) {
event.getSender().sendMessage( event.getSender().sendMessage("§cError: Player not found. (/un" + s + " <player>)");
"§cError: Player not found. (/un" + s + " <player>)");
event.setCommand("dontrunthiscmd"); event.setCommand("dontrunthiscmd");
} }
if (target != null) { if (target != null) {
target.addPotionEffect(new PotionEffect( target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
for (Player pl : PluginMain.GetPlayers()) for (Player pl : PluginMain.GetPlayers())
pl.sendMessage(event.getSender().getName() + " un" + s pl.sendMessage(event.getSender().getName() + " un" + s + "'d " + target.getDisplayName());
+ "'d " + target.getDisplayName()); Bukkit.getServer().getConsoleSender()
Bukkit.getServer() .sendMessage(event.getSender().getName() + " un" + s + "'d " + target.getDisplayName());
.getConsoleSender()
.sendMessage(
event.getSender().getName() + " un" + s + "'d "
+ target.getDisplayName());
event.setCommand("dontrunthiscmd"); event.setCommand("dontrunthiscmd");
} }
} }

View file

@ -1,5 +1,7 @@
package io.github.norbipeti.thebuttonmcchat; package io.github.norbipeti.thebuttonmcchat;
import org.bukkit.plugin.java.JavaPlugin;
import io.github.norbipeti.thebuttonmcchat.commands.CommandCaller; import io.github.norbipeti.thebuttonmcchat.commands.CommandCaller;
import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase; import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase;
import io.github.norbipeti.thebuttonmcchat.commands.ucmds.admin.PlayerInfoCommand; import io.github.norbipeti.thebuttonmcchat.commands.ucmds.admin.PlayerInfoCommand;
@ -20,7 +22,7 @@ public class TBMCChatAPI {
* @param cmd * @param cmd
* The command to add * The command to add
*/ */
public void AddCommand(Plugin plugin, TBMCCommandBase cmd) { public void AddCommand(JavaPlugin plugin, TBMCCommandBase cmd) {
CommandCaller.AddCommand(plugin, cmd); CommandCaller.AddCommand(plugin, cmd);
} }
@ -49,9 +51,4 @@ public class TBMCChatAPI {
public void AddPlayerInfoForHover(TBMCPlayer player, String infoline) { public void AddPlayerInfoForHover(TBMCPlayer player, String infoline) {
// TODO // TODO
} }
public TBMCPlayer GetPlayer(Player player) //TODO: Move to the bucket
{ //TODO: Enable offline playerinfo
}
} }

View file

@ -13,6 +13,8 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.reflections.Reflections; import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner; import org.reflections.scanners.SubTypesScanner;
import org.reflections.util.ClasspathHelper; import org.reflections.util.ClasspathHelper;
@ -57,7 +59,7 @@ public class CommandCaller implements CommandExecutor {
if (pc == null) if (pc == null)
new Exception("Can't find top-level command: " + c.GetCommandPath()).printStackTrace(); new Exception("Can't find top-level command: " + c.GetCommandPath()).printStackTrace();
else else
pc.setExecutor(cc); pc.setExecutor(instance);
} }
} catch (InstantiationException e) { } catch (InstantiationException e) {
e.printStackTrace(); e.printStackTrace();
@ -67,15 +69,15 @@ public class CommandCaller implements CommandExecutor {
} }
} }
public static void AddCommand(Plugin plugin, TBMCCommandBase cmd) { public static void AddCommand(JavaPlugin plugin, TBMCCommandBase cmd) {
if (instance == null) if (instance == null)
instance = new CommandCaller(); instance = new CommandCaller();
commands.put(cmd.GetCommandPath(), cmd); commands.put(cmd.GetCommandPath(), cmd);
if (!c.GetCommandPath().contains("/")) // Top-level command if (!cmd.GetCommandPath().contains("/")) // Top-level command
{ {
PluginCommand pc = plugin.getCommand(cmd.GetCommandPath()); PluginCommand pc = plugin.getCommand(cmd.GetCommandPath());
if (pc == null) if (pc == null)
new Exception("Can't find top-level command: " + c.GetCommandPath()).printStackTrace(); new Exception("Can't find top-level command: " + cmd.GetCommandPath()).printStackTrace();
else else
pc.setExecutor(instance); pc.setExecutor(instance);
} }