Invited @console to the party
This commit is contained in:
parent
aaf19190e4
commit
0e55cf89da
17 changed files with 629 additions and 504 deletions
Binary file not shown.
|
@ -18,8 +18,6 @@ commands:
|
||||||
mwiki:
|
mwiki:
|
||||||
description: Search the wiki.
|
description: Search the wiki.
|
||||||
usage: "&vUsage: /mwiki [query]&r"
|
usage: "&vUsage: /mwiki [query]&r"
|
||||||
chat:
|
|
||||||
description: Chats from console.
|
|
||||||
author: NorbiPeti
|
author: NorbiPeti
|
||||||
depend: [Essentials, Towny, Minigames, Votifier, Factions]
|
depend: [Essentials, Towny, Minigames, Votifier, Factions]
|
||||||
permissions:
|
permissions:
|
||||||
|
|
|
@ -0,0 +1,467 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scoreboard.Objective;
|
||||||
|
|
||||||
|
import ru.tehkode.permissions.bukkit.PermissionsEx;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.Essentials;
|
||||||
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
|
||||||
|
public class ChatProcessing {
|
||||||
|
// Returns e.setCancelled
|
||||||
|
public static boolean ProcessChat(CommandSender sender, String message) {
|
||||||
|
if (PlayerListener.essentials == null)
|
||||||
|
PlayerListener.essentials = (Essentials) (Bukkit.getPluginManager()
|
||||||
|
.getPlugin("Essentials"));
|
||||||
|
Player player = (sender instanceof Player ? (Player) sender : null);
|
||||||
|
if (player != null && message.equalsIgnoreCase("F")) {
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(player
|
||||||
|
.getUniqueId());
|
||||||
|
if (!mp.PressedF && PlayerListener.ActiveF) {
|
||||||
|
PlayerListener.FCount++;
|
||||||
|
mp.PressedF = true;
|
||||||
|
if (PlayerListener.FPlayer != null
|
||||||
|
&& PlayerListener.FPlayer.FCount < Integer.MAX_VALUE - 1)
|
||||||
|
PlayerListener.FPlayer.FCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean greentext = message.startsWith(">");
|
||||||
|
String msg = message.toLowerCase();
|
||||||
|
if (player != null && msg.contains("lol")) {
|
||||||
|
Commands.Lastlol = MaybeOfflinePlayer.AllPlayers.get(player
|
||||||
|
.getUniqueId());
|
||||||
|
Commands.Lastlolornot = true;
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < PlayerListener.LaughStrings.length; i++) {
|
||||||
|
if (msg.contains(PlayerListener.LaughStrings[i])) {
|
||||||
|
Commands.Lastlol = MaybeOfflinePlayer.AllPlayers.get(player
|
||||||
|
.getUniqueId());
|
||||||
|
Commands.Lastlolornot = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MaybeOfflinePlayer mplayer = null;
|
||||||
|
if (player != null) {
|
||||||
|
mplayer = MaybeOfflinePlayer.AllPlayers.get(player.getUniqueId());
|
||||||
|
}
|
||||||
|
Channel currentchannel = (mplayer == null ? PlayerListener.ConsoleChannel
|
||||||
|
: mplayer.CurrentChannel);
|
||||||
|
String formattedmessage = message;
|
||||||
|
formattedmessage = formattedmessage.replace("\\", "\\\\"); // It's
|
||||||
|
// really
|
||||||
|
// important
|
||||||
|
// to escape
|
||||||
|
// the
|
||||||
|
// slashes
|
||||||
|
// first
|
||||||
|
formattedmessage = formattedmessage.replace("\"", "\\\"");
|
||||||
|
formattedmessage = formattedmessage.replace("&", "§");
|
||||||
|
formattedmessage = formattedmessage.replace("§r", "§"
|
||||||
|
+ currentchannel.DisplayName.charAt(1));
|
||||||
|
String suggestmsg = formattedmessage;
|
||||||
|
|
||||||
|
// URLs + Rainbow text
|
||||||
|
String[] parts = formattedmessage.split("\\s+");
|
||||||
|
boolean hadurls = false;
|
||||||
|
final String[] RainbowPresserColors = new String[] { "c", "6", "e",
|
||||||
|
"a", "9", "5" };
|
||||||
|
int rpc = 0;
|
||||||
|
int currentindex = 0;
|
||||||
|
for (String item : parts) {
|
||||||
|
try {
|
||||||
|
URL url = new URL(item);
|
||||||
|
formattedmessage = formattedmessage
|
||||||
|
.replace(
|
||||||
|
item,
|
||||||
|
String.format(
|
||||||
|
"\",\"color\":\"%s\"},{\"text\":\"%s\",\"color\":\"%s\",\"underlined\":\"true\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open URL\",\"color\":\"blue\"}]}}},{\"text\":\"",
|
||||||
|
(greentext ? "green"
|
||||||
|
: currentchannel.Color), url,
|
||||||
|
(greentext ? "green"
|
||||||
|
: currentchannel.Color), url));
|
||||||
|
hadurls = true;
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
}
|
||||||
|
if (mplayer != null && mplayer.RainbowPresserColorMode) { // TODO:
|
||||||
|
// Rainbow
|
||||||
|
// mode
|
||||||
|
// for
|
||||||
|
// console
|
||||||
|
if (item.startsWith(RainbowPresserColors[rpc])) { // Prevent
|
||||||
|
// words
|
||||||
|
// being
|
||||||
|
// equal/starting
|
||||||
|
// with a
|
||||||
|
// color
|
||||||
|
// code
|
||||||
|
// letter to
|
||||||
|
// be messed
|
||||||
|
// up
|
||||||
|
if (rpc + 1 < RainbowPresserColors.length)
|
||||||
|
rpc++;
|
||||||
|
else
|
||||||
|
rpc = 0;
|
||||||
|
}
|
||||||
|
StringBuffer buf = new StringBuffer(formattedmessage);
|
||||||
|
buf.replace(currentindex, currentindex + item.length(),
|
||||||
|
String.format("§%s%s", RainbowPresserColors[rpc], item));
|
||||||
|
formattedmessage = buf.toString();
|
||||||
|
if (rpc + 1 < RainbowPresserColors.length)
|
||||||
|
rpc++;
|
||||||
|
else
|
||||||
|
rpc = 0;
|
||||||
|
}
|
||||||
|
currentindex += item.length() + 3;
|
||||||
|
}
|
||||||
|
if (mplayer != null && mplayer.OtherColorMode != 0xFF) {
|
||||||
|
formattedmessage = String.format("§%x%s", mplayer.OtherColorMode,
|
||||||
|
formattedmessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hadurls) {
|
||||||
|
for (Player p : PluginMain.GetPlayers()) {
|
||||||
|
String color = "";
|
||||||
|
if (formattedmessage.matches("(?i).*"
|
||||||
|
+ Pattern.quote(p.getName()) + ".*")) {
|
||||||
|
if (PlayerListener.NotificationSound == null)
|
||||||
|
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f,
|
||||||
|
0.5f);
|
||||||
|
else
|
||||||
|
p.playSound(p.getLocation(),
|
||||||
|
PlayerListener.NotificationSound, 1.0f,
|
||||||
|
(float) PlayerListener.NotificationPitch);
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer
|
||||||
|
.AddPlayerIfNeeded(p.getUniqueId());
|
||||||
|
color = String.format(
|
||||||
|
"§%x",
|
||||||
|
(mp.GetFlairColor() == 0x00 ? 0xb : mp
|
||||||
|
.GetFlairColor()));
|
||||||
|
}
|
||||||
|
|
||||||
|
formattedmessage = formattedmessage.replaceAll(
|
||||||
|
"(?i)" + Pattern.quote(p.getName()),
|
||||||
|
color
|
||||||
|
+ p.getName()
|
||||||
|
+ (greentext ? "§a"
|
||||||
|
: currentchannel.DisplayName.substring(
|
||||||
|
0, 2)));
|
||||||
|
}
|
||||||
|
for (String n : PlayerListener.nicknames.keySet()) {
|
||||||
|
Player p = null;
|
||||||
|
String nwithoutformatting = new String(n);
|
||||||
|
int index;
|
||||||
|
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
||||||
|
nwithoutformatting = nwithoutformatting.replace("§k"
|
||||||
|
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
||||||
|
// for
|
||||||
|
// one
|
||||||
|
// random
|
||||||
|
// char
|
||||||
|
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
||||||
|
nwithoutformatting = nwithoutformatting.replace("§"
|
||||||
|
+ nwithoutformatting.charAt(index + 1), "");
|
||||||
|
if (formattedmessage.matches("(?i).*"
|
||||||
|
+ Pattern.quote(nwithoutformatting) + ".*")) {
|
||||||
|
p = Bukkit.getPlayer(PlayerListener.nicknames.get(n));
|
||||||
|
if (PlayerListener.NotificationSound == null)
|
||||||
|
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f,
|
||||||
|
0.5f); // 2015.08.12.
|
||||||
|
else
|
||||||
|
p.playSound(p.getLocation(),
|
||||||
|
PlayerListener.NotificationSound, 1.0f,
|
||||||
|
(float) PlayerListener.NotificationPitch);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId());
|
||||||
|
}
|
||||||
|
if (p != null) {
|
||||||
|
formattedmessage = formattedmessage.replaceAll(
|
||||||
|
"(?i)" + Pattern.quote(nwithoutformatting),
|
||||||
|
n
|
||||||
|
+ (greentext ? "§a"
|
||||||
|
: currentchannel.DisplayName
|
||||||
|
.substring(0, 2)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (formattedmessage.matches("(?i).*" + Pattern.quote("@console")
|
||||||
|
+ ".*")) {
|
||||||
|
formattedmessage = formattedmessage.replaceAll(
|
||||||
|
"(?i)" + Pattern.quote("@console"), "§b@console§r");
|
||||||
|
System.out.println("\007");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player != null
|
||||||
|
&& PlayerListener.essentials.getUser(player).isMuted())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
StringBuilder json = new StringBuilder();
|
||||||
|
json.append("[\"\",");
|
||||||
|
json.append(String
|
||||||
|
.format("{\"text\":\"[%s]%s\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"Copy message\",\"color\":\"blue\"}},clickEvent:{\"action\":\"suggest_command\",\"value\":\"%s\"}},",
|
||||||
|
currentchannel.DisplayName,
|
||||||
|
(mplayer != null && !mplayer.RPMode ? "[OOC]" : ""),
|
||||||
|
suggestmsg));
|
||||||
|
json.append("{\"text\":\" <\"},");
|
||||||
|
json.append(String.format("{\"text\":\"%s%s\",",
|
||||||
|
(player != null ? player.getDisplayName() : sender.getName()),
|
||||||
|
(mplayer != null ? mplayer.GetFormattedFlair() : "")));
|
||||||
|
json.append("\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[");
|
||||||
|
json.append(String.format("{\"text\":\"%s\n\",",
|
||||||
|
(player != null ? player.getName() : sender.getName())));
|
||||||
|
json.append(String
|
||||||
|
.format("\"color\":\"aqua\"},{\"text\":\"World: %s\n\",\"color\":\"white\"},",
|
||||||
|
(player != null ? player.getWorld().getName() : "-")));
|
||||||
|
json.append(String.format(
|
||||||
|
"{\"text\":\"Respect: %s%s%s\",\"color\":\"white\"}]}}},",
|
||||||
|
(mplayer != null ? (mplayer.FCount / (double) mplayer.FDeaths)
|
||||||
|
: "Infinite"),
|
||||||
|
(mplayer != null && mplayer.UserName != null
|
||||||
|
&& !mplayer.UserName.isEmpty() ? "\nUserName: "
|
||||||
|
+ mplayer.UserName : ""),
|
||||||
|
(mplayer != null
|
||||||
|
&& mplayer.PlayerName.equals("\nAlpha_Bacca44") ? "\nDeaths: "
|
||||||
|
+ PlayerListener.AlphaDeaths
|
||||||
|
: "")));
|
||||||
|
json.append("{\"text\":\"> \",\"color\":\"white\"},");
|
||||||
|
|
||||||
|
int index = -1;
|
||||||
|
ArrayList<String> list = new ArrayList<String>();
|
||||||
|
while ((index = message.indexOf("#", index + 1)) != -1) {
|
||||||
|
int index2 = message.indexOf(" ", index + 1);
|
||||||
|
if (index2 == -1)
|
||||||
|
index2 = message.length();
|
||||||
|
int index3 = message.indexOf("#", index + 1);
|
||||||
|
if (index3 != -1 && index3 < index2) // A # occurs before a
|
||||||
|
// space
|
||||||
|
index2 = index3;
|
||||||
|
String original = message.substring(index + 1, index2);
|
||||||
|
list.add(original);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hadurls) {
|
||||||
|
for (String original : list)
|
||||||
|
// Hashtags
|
||||||
|
formattedmessage = formattedmessage
|
||||||
|
.replace(
|
||||||
|
"#" + original,
|
||||||
|
String.format(
|
||||||
|
"\",\"color\":\"%s\"},{\"text\":\"#%s\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}},{\"text\":\"",
|
||||||
|
(greentext ? "green"
|
||||||
|
: currentchannel.Color),
|
||||||
|
original, original));
|
||||||
|
}
|
||||||
|
|
||||||
|
json.append(String.format("{\"text\":\"%s\",\"color\":\"%s\"}]",
|
||||||
|
formattedmessage, (greentext ? "green" : currentchannel.Color)));
|
||||||
|
String jsonstr = json.toString();
|
||||||
|
if (jsonstr.length() >= 32767) {
|
||||||
|
sender.sendMessage("§cError: Message too large. Try shortening it, or remove hashtags and other formatting.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (currentchannel.equals(Channel.TownChat)
|
||||||
|
|| currentchannel.equals(Channel.NationChat)) {
|
||||||
|
if (player == null) {
|
||||||
|
sender.sendMessage("§cYou are not a player!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (Player p : PluginMain.GetPlayers()) {
|
||||||
|
try {
|
||||||
|
Resident resident = PluginMain.Instance.TU.getResidentMap()
|
||||||
|
.get(p.getName().toLowerCase());
|
||||||
|
if (!resident.getName().equals(player.getName())
|
||||||
|
&& resident.getModes().contains("spy"))
|
||||||
|
Bukkit.getPlayer(resident.getName()).sendMessage(
|
||||||
|
String.format("[SPY-%s] - %s: %s",
|
||||||
|
currentchannel.DisplayName,
|
||||||
|
player.getDisplayName(), message));
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (currentchannel.equals(Channel.TownChat)) {
|
||||||
|
try {
|
||||||
|
Town town = null;
|
||||||
|
try {
|
||||||
|
town = PluginMain.Instance.TU.getResidentMap()
|
||||||
|
.get(player.getName().toLowerCase()).getTown();
|
||||||
|
} catch (NotRegisteredException e) {
|
||||||
|
}
|
||||||
|
if (town == null) {
|
||||||
|
player.sendMessage("§cYou aren't in a town or an error occured.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
index = PluginMain.Instance.Towns.indexOf(town);
|
||||||
|
if (index < 0) {
|
||||||
|
PluginMain.Instance.Towns.add(town);
|
||||||
|
index = PluginMain.Instance.Towns.size() - 1;
|
||||||
|
}
|
||||||
|
Objective obj = PluginMain.SB.getObjective("town");
|
||||||
|
for (Player p : PluginMain.GetPlayers()) {
|
||||||
|
try {
|
||||||
|
if (PluginMain.Instance.TU.getResidentMap()
|
||||||
|
.get(p.getName().toLowerCase()).getTown()
|
||||||
|
.getName().equals(town.getName()))
|
||||||
|
obj.getScore(p.getName()).setScore(index);
|
||||||
|
else
|
||||||
|
obj.getScore(p.getName()).setScore(-1);
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PluginMain.Instance
|
||||||
|
.getServer()
|
||||||
|
.dispatchCommand(
|
||||||
|
PluginMain.Console,
|
||||||
|
String.format(
|
||||||
|
"tellraw @a[score_town=%d,score_town_min=%d] %s",
|
||||||
|
index, index, json.toString()));
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
player.sendMessage("§cAn error occured while sending the message. (IllegalStateException)");
|
||||||
|
return true;
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
player.sendMessage("§cAn error occured while sending the message. (IllegalArgumentException)");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (currentchannel.equals(Channel.NationChat)) {
|
||||||
|
try {
|
||||||
|
Town town = null;
|
||||||
|
try {
|
||||||
|
town = PluginMain.Instance.TU.getResidentMap()
|
||||||
|
.get(player.getName().toLowerCase()).getTown();
|
||||||
|
} catch (NotRegisteredException e) {
|
||||||
|
}
|
||||||
|
if (town == null) {
|
||||||
|
player.sendMessage("§cYou aren't in a town or an error occured.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Nation nation = null;
|
||||||
|
try {
|
||||||
|
nation = town.getNation();
|
||||||
|
} catch (NotRegisteredException e) {
|
||||||
|
}
|
||||||
|
if (nation == null) {
|
||||||
|
player.sendMessage("§cYour town isn't in a nation or an error occured.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
index = PluginMain.Instance.Nations.indexOf(nation);
|
||||||
|
if (index < 0) {
|
||||||
|
PluginMain.Instance.Nations.add(nation);
|
||||||
|
index = PluginMain.Instance.Nations.size() - 1;
|
||||||
|
}
|
||||||
|
Objective obj = PluginMain.SB.getObjective("nation");
|
||||||
|
for (Player p : PluginMain.GetPlayers()) {
|
||||||
|
try {
|
||||||
|
if (PluginMain.Instance.TU.getResidentMap()
|
||||||
|
.get(p.getName().toLowerCase()).getTown()
|
||||||
|
.getNation().getName().equals(nation.getName()))
|
||||||
|
obj.getScore(p.getName()).setScore(index);
|
||||||
|
else
|
||||||
|
obj.getScore(p.getName()).setScore(-1);
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PluginMain.Instance
|
||||||
|
.getServer()
|
||||||
|
.dispatchCommand(
|
||||||
|
PluginMain.Console,
|
||||||
|
String.format(
|
||||||
|
"tellraw @a[score_nation=%d,score_nation_min=%d] %s",
|
||||||
|
index, index, json.toString()));
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
player.sendMessage("§cAn error occured while sending the message. (IllegalStateException)");
|
||||||
|
return true;
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
player.sendMessage("§cAn error occured while sending the message. (IllegalArgumentException)");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (currentchannel.equals(Channel.AdminChat)) {
|
||||||
|
try { // TODO: Put message JSON into it's structure
|
||||||
|
if (player != null && !player.isOp()) {
|
||||||
|
player.sendMessage("§cYou need to be an OP to use this channel.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Objective obj = PluginMain.SB.getObjective("admin");
|
||||||
|
for (Player p : PluginMain.GetPlayers()) {
|
||||||
|
if (p.isOp())
|
||||||
|
obj.getScore(p.getName()).setScore(1);
|
||||||
|
else
|
||||||
|
obj.getScore(p.getName()).setScore(0);
|
||||||
|
}
|
||||||
|
PluginMain.Instance
|
||||||
|
.getServer()
|
||||||
|
.dispatchCommand(
|
||||||
|
PluginMain.Console,
|
||||||
|
String.format(
|
||||||
|
"tellraw @a[score_admin=%d,score_admin_min=%d] %s",
|
||||||
|
1, 1, json.toString()));
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
player.sendMessage("§cAn error occured while sending the message. (IllegalStateException)");
|
||||||
|
return true;
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
player.sendMessage("§cAn error occured while sending the message. (IllegalArgumentException)");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (currentchannel.equals(Channel.ModChat)) {
|
||||||
|
try {
|
||||||
|
if (player != null
|
||||||
|
&& !PermissionsEx.getUser(player).inGroup("mod")) {
|
||||||
|
player.sendMessage("§cYou need to be a mod to use this channel.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Objective obj = PluginMain.SB.getObjective("mod");
|
||||||
|
for (Player p : PluginMain.GetPlayers()) {
|
||||||
|
if (PermissionsEx.getUser(p).inGroup("mod"))
|
||||||
|
obj.getScore(p.getName()).setScore(1);
|
||||||
|
else
|
||||||
|
obj.getScore(p.getName()).setScore(0);
|
||||||
|
}
|
||||||
|
PluginMain.Instance.getServer().dispatchCommand(
|
||||||
|
PluginMain.Console,
|
||||||
|
String.format(
|
||||||
|
"tellraw @a[score_mod=%d,score_mod_min=%d] %s",
|
||||||
|
1, 1, json.toString()));
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
player.sendMessage("§cAn error occured while sending the message. (IllegalStateException)");
|
||||||
|
return true;
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
player.sendMessage("§cAn error occured while sending the message. (IllegalArgumentException)");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
||||||
|
String.format("tellraw @a %s", json.toString()));
|
||||||
|
PluginMain.Instance
|
||||||
|
.getServer()
|
||||||
|
.getConsoleSender()
|
||||||
|
.sendMessage(
|
||||||
|
String.format("[%s] <%s%s> %s",
|
||||||
|
currentchannel.DisplayName,
|
||||||
|
(player != null ? player.getDisplayName()
|
||||||
|
: sender.getName()),
|
||||||
|
(mplayer != null ? mplayer.GetFormattedFlair()
|
||||||
|
: ""), message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -233,6 +233,13 @@ public class Commands implements CommandExecutor {
|
||||||
pl.sendMessage(player.getDisplayName()
|
pl.sendMessage(player.getDisplayName()
|
||||||
+ (Lastlolornot ? " unlolled " : " unlaughed ")
|
+ (Lastlolornot ? " unlolled " : " unlaughed ")
|
||||||
+ p.getDisplayName());
|
+ p.getDisplayName());
|
||||||
|
Bukkit.getServer()
|
||||||
|
.getConsoleSender()
|
||||||
|
.sendMessage(
|
||||||
|
player.getDisplayName()
|
||||||
|
+ (Lastlolornot ? " unlolled "
|
||||||
|
: " unlaughed ")
|
||||||
|
+ p.getDisplayName());
|
||||||
Lastlol = null;
|
Lastlol = null;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -248,12 +255,6 @@ public class Commands implements CommandExecutor {
|
||||||
DoMWiki(player, args);
|
DoMWiki(player, args);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "chat": {
|
|
||||||
/*ConsolePlayer cp = new ConsolePlayer();
|
|
||||||
cp.chat("Test!");
|
|
||||||
System.out.println("Sent msg");*/
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
player.sendMessage("Unknown command: " + cmd.getName());
|
player.sendMessage("Unknown command: " + cmd.getName());
|
||||||
break;
|
break;
|
||||||
|
@ -268,11 +269,39 @@ public class Commands implements CommandExecutor {
|
||||||
else
|
else
|
||||||
DoAnnounce(null, args, null);
|
DoAnnounce(null, args, null);
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
switch (cmd.getName()) {
|
||||||
|
case "unlaugh":
|
||||||
|
case "unlol": {
|
||||||
|
Player p = null;
|
||||||
|
if (Lastlol != null
|
||||||
|
&& (p = Bukkit.getPlayer(Lastlol.UUID)) != null) {
|
||||||
|
p.addPotionEffect(new PotionEffect(
|
||||||
|
PotionEffectType.BLINDNESS, 10 * 20, 5, false,
|
||||||
|
false));
|
||||||
|
for (Player pl : PluginMain.GetPlayers())
|
||||||
|
pl.sendMessage(Bukkit.getServer().getConsoleSender()
|
||||||
|
.getName()
|
||||||
|
+ (Lastlolornot ? " unlolled " : " unlaughed ")
|
||||||
|
+ p.getDisplayName());
|
||||||
|
Bukkit.getServer()
|
||||||
|
.getConsoleSender()
|
||||||
|
.sendMessage(
|
||||||
|
Bukkit.getServer().getConsoleSender()
|
||||||
|
.getName()
|
||||||
|
+ (Lastlolornot ? " unlolled "
|
||||||
|
: " unlaughed ")
|
||||||
|
+ p.getDisplayName());
|
||||||
|
Lastlol = null;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DoReload(Player player) { // 2015.07.20.
|
private static void DoReload(Player player) {
|
||||||
try {
|
try {
|
||||||
PluginMain.Console
|
PluginMain.Console
|
||||||
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
.sendMessage("§6-- Reloading The Button Minecraft plugin...§r");
|
||||||
|
|
|
@ -2,20 +2,15 @@ package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
@ -33,15 +28,14 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
import org.bukkit.event.server.ServerCommandEvent;
|
||||||
import org.bukkit.help.HelpTopic;
|
import org.bukkit.help.HelpTopic;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.SkullMeta;
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
import org.bukkit.scoreboard.Objective;
|
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import ru.tehkode.permissions.bukkit.PermissionsEx;
|
|
||||||
import au.com.mineauz.minigames.MinigamePlayer;
|
import au.com.mineauz.minigames.MinigamePlayer;
|
||||||
import au.com.mineauz.minigames.Minigames;
|
import au.com.mineauz.minigames.Minigames;
|
||||||
|
|
||||||
|
@ -49,7 +43,6 @@ import com.earth2me.essentials.Essentials;
|
||||||
import com.massivecraft.factions.entity.BoardColl;
|
import com.massivecraft.factions.entity.BoardColl;
|
||||||
import com.massivecraft.massivecore.ps.PS;
|
import com.massivecraft.massivecore.ps.PS;
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
import com.palmergames.bukkit.towny.object.Nation;
|
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
import com.palmergames.bukkit.towny.object.TownBlock;
|
import com.palmergames.bukkit.towny.object.TownBlock;
|
||||||
|
@ -58,10 +51,10 @@ import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
import com.vexsoftware.votifier.model.Vote;
|
import com.vexsoftware.votifier.model.Vote;
|
||||||
import com.vexsoftware.votifier.model.VotifierEvent;
|
import com.vexsoftware.votifier.model.VotifierEvent;
|
||||||
|
|
||||||
public class PlayerListener implements Listener { // 2015.07.16.
|
public class PlayerListener implements Listener {
|
||||||
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
public static HashMap<String, UUID> nicknames = new HashMap<>();
|
||||||
|
|
||||||
public static boolean Enable = false; // 2015.08.29.
|
public static boolean Enable = false;
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
@ -161,493 +154,16 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
|
|
||||||
public static boolean ShowRPTag = false;
|
public static boolean ShowRPTag = false;
|
||||||
|
|
||||||
private Essentials essentials = null;
|
public static Essentials essentials = null;
|
||||||
private final 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 (essentials == null)
|
|
||||||
essentials = ((Essentials) Bukkit.getPluginManager().getPlugin(
|
|
||||||
"Essentials"));
|
|
||||||
if (event.isCancelled()) // TODO: Change FactionChat to /tellraw
|
if (event.isCancelled()) // TODO: Change FactionChat to /tellraw
|
||||||
return;
|
return;
|
||||||
if (event.getMessage().equalsIgnoreCase("F")) {
|
event.setCancelled(ChatProcessing.ProcessChat(event.getPlayer(),
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(event
|
|
||||||
.getPlayer().getUniqueId());
|
|
||||||
if (!mp.PressedF && ActiveF) {
|
|
||||||
FCount++;
|
|
||||||
mp.PressedF = true;
|
|
||||||
if (FPlayer != null && FPlayer.FCount < Integer.MAX_VALUE - 1)
|
|
||||||
FPlayer.FCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean greentext = event.getMessage().startsWith(">");
|
|
||||||
String msg = event.getMessage().toLowerCase();
|
|
||||||
if (msg.contains("lol")) {
|
|
||||||
Commands.Lastlol = MaybeOfflinePlayer.AllPlayers.get(event
|
|
||||||
.getPlayer().getUniqueId());
|
|
||||||
Commands.Lastlolornot = true;
|
|
||||||
} else {
|
|
||||||
for (int i = 0; i < LaughStrings.length; i++) {
|
|
||||||
if (msg.contains(LaughStrings[i])) {
|
|
||||||
Commands.Lastlol = MaybeOfflinePlayer.AllPlayers.get(event
|
|
||||||
.getPlayer().getUniqueId());
|
|
||||||
Commands.Lastlolornot = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event
|
|
||||||
.getPlayer().getUniqueId());
|
|
||||||
String formattedmessage = event.getMessage();
|
|
||||||
formattedmessage = formattedmessage.replace("\\", "\\\\"); // It's
|
|
||||||
// really
|
|
||||||
// important
|
|
||||||
// to escape
|
|
||||||
// the
|
|
||||||
// slashes
|
|
||||||
// first
|
|
||||||
formattedmessage = formattedmessage.replace("\"", "\\\"");
|
|
||||||
if (PluginMain.permission.has(event.getPlayer(), "tbmc.admin")) {
|
|
||||||
formattedmessage = formattedmessage.replace("&", "§");
|
|
||||||
formattedmessage = formattedmessage.replace("§r", "§"
|
|
||||||
+ player.CurrentChannel.DisplayName.charAt(1));
|
|
||||||
}
|
|
||||||
String suggestmsg = formattedmessage;
|
|
||||||
|
|
||||||
// URLs + Rainbow text
|
|
||||||
String[] parts = formattedmessage.split("\\s+");
|
|
||||||
boolean hadurls = false;
|
|
||||||
final String[] RainbowPresserColors = new String[] { "c", "6", "e",
|
|
||||||
"a", "9", "5" };
|
|
||||||
int rpc = 0;
|
|
||||||
int currentindex = 0;
|
|
||||||
for (String item : parts) {
|
|
||||||
try {
|
|
||||||
URL url = new URL(item);
|
|
||||||
formattedmessage = formattedmessage
|
|
||||||
.replace(
|
|
||||||
item,
|
|
||||||
String.format(
|
|
||||||
"\",\"color\":\"%s\"},{\"text\":\"%s\",\"color\":\"%s\",\"underlined\":\"true\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open URL\",\"color\":\"blue\"}]}}},{\"text\":\"",
|
|
||||||
(greentext ? "green"
|
|
||||||
: player.CurrentChannel.Color),
|
|
||||||
url, (greentext ? "green"
|
|
||||||
: player.CurrentChannel.Color),
|
|
||||||
url));
|
|
||||||
hadurls = true;
|
|
||||||
// System.out.println("URL: " + url);
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
}
|
|
||||||
if (player.RainbowPresserColorMode) {
|
|
||||||
if (item.startsWith(RainbowPresserColors[rpc])) { // Prevent
|
|
||||||
// words
|
|
||||||
// being
|
|
||||||
// equal/starting
|
|
||||||
// with a
|
|
||||||
// color
|
|
||||||
// code
|
|
||||||
// letter to
|
|
||||||
// be messed
|
|
||||||
// up
|
|
||||||
if (rpc + 1 < RainbowPresserColors.length)
|
|
||||||
rpc++;
|
|
||||||
else
|
|
||||||
rpc = 0;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* System.out.println("item: " + item); // TO!DO: TMP
|
|
||||||
* System.out.println("currentindex: " + currentindex);
|
|
||||||
* System.out.println("format: " + String.format("§%s%s",
|
|
||||||
* RainbowPresserColors[rpc], item));
|
|
||||||
* System.out.println("formattedmessage: " + formattedmessage);
|
|
||||||
*/
|
|
||||||
StringBuffer buf = new StringBuffer(formattedmessage);
|
|
||||||
buf.replace(currentindex, currentindex + item.length(),
|
|
||||||
String.format("§%s%s", RainbowPresserColors[rpc], item));
|
|
||||||
formattedmessage = buf.toString();
|
|
||||||
/*
|
|
||||||
* "§" + RainbowPresserColors[rpc] + item));
|
|
||||||
*/
|
|
||||||
if (rpc + 1 < RainbowPresserColors.length)
|
|
||||||
rpc++;
|
|
||||||
else
|
|
||||||
rpc = 0;
|
|
||||||
}
|
|
||||||
currentindex += item.length() + 3;
|
|
||||||
}
|
|
||||||
if (player.OtherColorMode != 0xFF) {
|
|
||||||
formattedmessage = String.format("§%x%s", player.OtherColorMode,
|
|
||||||
formattedmessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hadurls) {
|
|
||||||
for (Player p : PluginMain.GetPlayers()) { // 2015.08.12.
|
|
||||||
String color = ""; // 2015.08.17.
|
|
||||||
if (formattedmessage.matches("(?i).*"
|
|
||||||
+ Pattern.quote(p.getName()) + ".*")) {
|
|
||||||
if (NotificationSound == null)
|
|
||||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f,
|
|
||||||
0.5f); // 2015.08.12.
|
|
||||||
else
|
|
||||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
|
||||||
(float) NotificationPitch); // 2015.08.14.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer
|
|
||||||
.AddPlayerIfNeeded(p.getUniqueId());
|
|
||||||
color = String.format(
|
|
||||||
"§%x",
|
|
||||||
(mp.GetFlairColor() == 0x00 ? 0xb : mp
|
|
||||||
.GetFlairColor()));
|
|
||||||
}
|
|
||||||
|
|
||||||
formattedmessage = formattedmessage.replaceAll(
|
|
||||||
"(?i)" + Pattern.quote(p.getName()),
|
|
||||||
color
|
|
||||||
+ p.getName()
|
|
||||||
+ (greentext ? "§a"
|
|
||||||
: player.CurrentChannel.DisplayName
|
|
||||||
.substring(0, 2)));
|
|
||||||
}
|
|
||||||
for (String n : nicknames.keySet()) {
|
|
||||||
Player p = null;
|
|
||||||
String nwithoutformatting = new String(n);
|
|
||||||
int index;
|
|
||||||
while ((index = nwithoutformatting.indexOf("§k")) != -1)
|
|
||||||
nwithoutformatting = nwithoutformatting.replace("§k"
|
|
||||||
+ nwithoutformatting.charAt(index + 2), ""); // Support
|
|
||||||
// for
|
|
||||||
// one
|
|
||||||
// random
|
|
||||||
// char
|
|
||||||
while ((index = nwithoutformatting.indexOf('§')) != -1)
|
|
||||||
nwithoutformatting = nwithoutformatting.replace("§"
|
|
||||||
+ nwithoutformatting.charAt(index + 1), "");
|
|
||||||
if (formattedmessage.matches("(?i).*"
|
|
||||||
+ Pattern.quote(nwithoutformatting) + ".*")) {
|
|
||||||
p = Bukkit.getPlayer(nicknames.get(n));
|
|
||||||
if (NotificationSound == null)
|
|
||||||
p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1.0f,
|
|
||||||
0.5f); // 2015.08.12.
|
|
||||||
else
|
|
||||||
p.playSound(p.getLocation(), NotificationSound, 1.0f,
|
|
||||||
(float) NotificationPitch); // 2015.08.14.
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getUniqueId()); // 2015.08.17.
|
|
||||||
}
|
|
||||||
if (p != null) {
|
|
||||||
formattedmessage = formattedmessage.replaceAll(
|
|
||||||
"(?i)" + Pattern.quote(nwithoutformatting),
|
|
||||||
n
|
|
||||||
+ (greentext ? "§a"
|
|
||||||
: player.CurrentChannel.DisplayName
|
|
||||||
.substring(0, 2)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (formattedmessage.matches("(?i).*" + Pattern.quote("@console")
|
|
||||||
+ ".*")) {
|
|
||||||
formattedmessage = formattedmessage.replaceAll(
|
|
||||||
"(?i)" + Pattern.quote("@console"), "§b@console§r");
|
|
||||||
System.out.println("\007");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* event.setFormat(event .getFormat() .replace( "{rptag}",
|
|
||||||
* (player.RPMode ? (ShowRPTag ? "§2[RP]§r" : "") : "§8[OOC]§r"))
|
|
||||||
* .replace("{buttonflair}", flair) .replace( "{isitwilds}",
|
|
||||||
* (event.getPlayer().getWorld().getName() .equalsIgnoreCase("wilds") ?
|
|
||||||
* "[PVP]" : ""))); // 2015.09.04.
|
|
||||||
*/
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
if (essentials.getUser(event.getPlayer()).isMuted())
|
|
||||||
return;
|
|
||||||
|
|
||||||
StringBuilder json = new StringBuilder();
|
|
||||||
json.append("[\"\",");
|
|
||||||
json.append(String
|
|
||||||
.format("{\"text\":\"[%s]%s\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"Copy message\",\"color\":\"blue\"}},clickEvent:{\"action\":\"suggest_command\",\"value\":\"%s\"}},",
|
|
||||||
player.CurrentChannel.DisplayName,
|
|
||||||
(!player.RPMode ? "[OOC]" : ""), suggestmsg));
|
|
||||||
json.append("{\"text\":\" <\"},");
|
|
||||||
json.append(String.format("{\"text\":\"%s%s\",", event.getPlayer()
|
|
||||||
.getDisplayName(), player.GetFormattedFlair()));
|
|
||||||
json.append("\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[");
|
|
||||||
json.append(String.format("{\"text\":\"%s\n\",", event.getPlayer()
|
|
||||||
.getName()));
|
|
||||||
json.append(String
|
|
||||||
.format("\"color\":\"aqua\"},{\"text\":\"World: %s\n\",\"color\":\"white\"},",
|
|
||||||
event.getPlayer().getWorld().getName()));
|
|
||||||
json.append(String
|
|
||||||
.format("{\"text\":\"Respect: %s%s%s\",\"color\":\"white\"}]}}},",
|
|
||||||
player.FCount / (double) player.FDeaths,
|
|
||||||
(player.UserName != null && !player.UserName.isEmpty() ? "\nUserName: "
|
|
||||||
+ player.UserName
|
|
||||||
: ""), (player.PlayerName
|
|
||||||
.equals("\nAlpha_Bacca44") ? "\nDeaths: "
|
|
||||||
+ AlphaDeaths : "")));
|
|
||||||
json.append("{\"text\":\"> \",\"color\":\"white\"},");
|
|
||||||
|
|
||||||
int index = -1;
|
|
||||||
ArrayList<String> list = new ArrayList<String>();
|
|
||||||
while ((index = event.getMessage().indexOf("#", index + 1)) != -1) {
|
|
||||||
int index2 = event.getMessage().indexOf(" ", index + 1);
|
|
||||||
if (index2 == -1)
|
|
||||||
index2 = event.getMessage().length();
|
|
||||||
int index3 = event.getMessage().indexOf("#", index + 1);
|
|
||||||
if (index3 != -1 && index3 < index2) // A # occurs before a
|
|
||||||
// space
|
|
||||||
index2 = index3;
|
|
||||||
String original = event.getMessage().substring(index + 1, index2);
|
|
||||||
list.add(original);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hadurls) {
|
|
||||||
for (String original : list)
|
|
||||||
// Hashtags
|
|
||||||
formattedmessage = formattedmessage
|
|
||||||
.replace(
|
|
||||||
"#" + original,
|
|
||||||
String.format(
|
|
||||||
"\",\"color\":\"%s\"},{\"text\":\"#%s\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://twitter.com/hashtag/%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open on Twitter\",\"color\":\"blue\"}]}}},{\"text\":\"",
|
|
||||||
(greentext ? "green"
|
|
||||||
: player.CurrentChannel.Color),
|
|
||||||
original, original));
|
|
||||||
}
|
|
||||||
|
|
||||||
json.append(String.format("{\"text\":\"%s\",\"color\":\"%s\"}]",
|
|
||||||
formattedmessage, (greentext ? "green"
|
|
||||||
: player.CurrentChannel.Color)));
|
|
||||||
// System.out.println(formattedmessage); // TO!DO: TMP
|
|
||||||
String jsonstr = json.toString();
|
|
||||||
if (jsonstr.length() >= 32767) {
|
|
||||||
event.getPlayer()
|
|
||||||
.sendMessage(
|
|
||||||
"§cError: Message too large. Try shortening it, or remove hashtags and other formatting.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (player.CurrentChannel.equals(Channel.TownChat)
|
|
||||||
|| player.CurrentChannel.equals(Channel.NationChat))
|
|
||||||
// for (Resident resident :
|
|
||||||
// PluginMain.Instance.TU.getResidentMap().values()) {
|
|
||||||
for (Player p : PluginMain.GetPlayers()) {
|
|
||||||
try {
|
|
||||||
Resident resident = PluginMain.Instance.TU.getResidentMap()
|
|
||||||
.get(p.getName().toLowerCase());
|
|
||||||
if (!resident.getName().equals(event.getPlayer().getName())
|
|
||||||
&& resident.getModes().contains("spy"))
|
|
||||||
Bukkit.getPlayer(resident.getName()).sendMessage(
|
|
||||||
String.format("[SPY-%s] - %s: %s",
|
|
||||||
player.CurrentChannel.DisplayName,
|
|
||||||
event.getPlayer().getDisplayName(),
|
|
||||||
event.getMessage()));
|
event.getMessage()));
|
||||||
} catch (Exception e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (player.CurrentChannel.equals(Channel.TownChat)) {
|
|
||||||
try {
|
|
||||||
// System.out.println(PluginMain.Instance.TU.getResidentMap().keys().nextElement());
|
|
||||||
Town town = null;
|
|
||||||
try {
|
|
||||||
town = PluginMain.Instance.TU.getResidentMap()
|
|
||||||
.get(event.getPlayer().getName().toLowerCase())
|
|
||||||
.getTown();
|
|
||||||
} catch (NotRegisteredException e) {
|
|
||||||
}
|
|
||||||
if (town == null) {
|
|
||||||
event.getPlayer().sendMessage(
|
|
||||||
"§cYou aren't in a town or an error occured.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
index = PluginMain.Instance.Towns.indexOf(town);
|
|
||||||
if (index < 0) {
|
|
||||||
PluginMain.Instance.Towns.add(town);
|
|
||||||
index = PluginMain.Instance.Towns.size() - 1;
|
|
||||||
}
|
|
||||||
// PluginMain.SB.getObjective("town").getScore(event.getPlayer().getName()).setScore(index);
|
|
||||||
// System.out.println("index: " + index);
|
|
||||||
Objective obj = PluginMain.SB.getObjective("town");
|
|
||||||
// System.out.println("obj: " + obj);
|
|
||||||
for (Player p : PluginMain.GetPlayers()) {
|
|
||||||
// System.out.println(town.getName()); //Mute fixed,
|
|
||||||
// re-enabled /minecraft:me except when muted, admin and mod
|
|
||||||
// channel added, links implemented
|
|
||||||
try {
|
|
||||||
if (PluginMain.Instance.TU.getResidentMap()
|
|
||||||
.get(p.getName().toLowerCase()).getTown()
|
|
||||||
.getName().equals(town.getName()))
|
|
||||||
obj.getScore(p.getName()).setScore(index);
|
|
||||||
else
|
|
||||||
obj.getScore(p.getName()).setScore(-1);
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PluginMain.Instance
|
|
||||||
.getServer()
|
|
||||||
.dispatchCommand(
|
|
||||||
PluginMain.Console,
|
|
||||||
String.format(
|
|
||||||
"tellraw @a[score_town=%d,score_town_min=%d] %s",
|
|
||||||
index, index, json.toString()));
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
event.getPlayer()
|
|
||||||
.sendMessage(
|
|
||||||
"§cAn error occured while sending the message. (IllegalStateException)");
|
|
||||||
return;
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
event.getPlayer()
|
|
||||||
.sendMessage(
|
|
||||||
"§cAn error occured while sending the message. (IllegalArgumentException)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (player.CurrentChannel.equals(Channel.NationChat)) {
|
|
||||||
try {
|
|
||||||
Town town = null;
|
|
||||||
try {
|
|
||||||
town = PluginMain.Instance.TU.getResidentMap()
|
|
||||||
.get(event.getPlayer().getName().toLowerCase())
|
|
||||||
.getTown();
|
|
||||||
} catch (NotRegisteredException e) {
|
|
||||||
}
|
|
||||||
if (town == null) {
|
|
||||||
event.getPlayer().sendMessage(
|
|
||||||
"§cYou aren't in a town or an error occured.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Nation nation = null;
|
|
||||||
try {
|
|
||||||
nation = town.getNation();
|
|
||||||
} catch (NotRegisteredException e) {
|
|
||||||
}
|
|
||||||
if (nation == null) {
|
|
||||||
event.getPlayer()
|
|
||||||
.sendMessage(
|
|
||||||
"§cYour town isn't in a nation or an error occured.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
index = PluginMain.Instance.Nations.indexOf(nation);
|
|
||||||
if (index < 0) {
|
|
||||||
PluginMain.Instance.Nations.add(nation);
|
|
||||||
index = PluginMain.Instance.Nations.size() - 1;
|
|
||||||
}
|
|
||||||
// PluginMain.SB.getObjective("nation").getScore(event.getPlayer().getName()).setScore(index);
|
|
||||||
Objective obj = PluginMain.SB.getObjective("nation");
|
|
||||||
for (Player p : PluginMain.GetPlayers()) {
|
|
||||||
try {
|
|
||||||
if (PluginMain.Instance.TU.getResidentMap()
|
|
||||||
.get(p.getName().toLowerCase()).getTown()
|
|
||||||
.getNation().getName().equals(nation.getName()))
|
|
||||||
obj.getScore(p.getName()).setScore(index);
|
|
||||||
else
|
|
||||||
obj.getScore(p.getName()).setScore(-1);
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PluginMain.Instance
|
|
||||||
.getServer()
|
|
||||||
.dispatchCommand(
|
|
||||||
PluginMain.Console,
|
|
||||||
String.format(
|
|
||||||
"tellraw @a[score_nation=%d,score_nation_min=%d] %s",
|
|
||||||
index, index, json.toString()));
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
event.getPlayer()
|
|
||||||
.sendMessage(
|
|
||||||
"§cAn error occured while sending the message. (IllegalStateException)");
|
|
||||||
return;
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
event.getPlayer()
|
|
||||||
.sendMessage(
|
|
||||||
"§cAn error occured while sending the message. (IllegalArgumentException)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (player.CurrentChannel.equals(Channel.AdminChat)) {
|
|
||||||
try { // TODO: Put message JSON into it's structure
|
|
||||||
if (!event.getPlayer().isOp()) {
|
|
||||||
event.getPlayer().sendMessage(
|
|
||||||
"§cYou need to be an OP to use this channel.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Objective obj = PluginMain.SB.getObjective("admin");
|
|
||||||
for (Player p : PluginMain.GetPlayers()) {
|
|
||||||
if (p.isOp())
|
|
||||||
obj.getScore(p.getName()).setScore(1);
|
|
||||||
else
|
|
||||||
obj.getScore(p.getName()).setScore(0);
|
|
||||||
}
|
|
||||||
PluginMain.Instance
|
|
||||||
.getServer()
|
|
||||||
.dispatchCommand(
|
|
||||||
PluginMain.Console,
|
|
||||||
String.format(
|
|
||||||
"tellraw @a[score_admin=%d,score_admin_min=%d] %s",
|
|
||||||
1, 1, json.toString()));
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
event.getPlayer()
|
|
||||||
.sendMessage(
|
|
||||||
"§cAn error occured while sending the message. (IllegalStateException)");
|
|
||||||
return;
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
event.getPlayer()
|
|
||||||
.sendMessage(
|
|
||||||
"§cAn error occured while sending the message. (IllegalArgumentException)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (player.CurrentChannel.equals(Channel.ModChat)) {
|
|
||||||
try {
|
|
||||||
if (!PermissionsEx.getUser(event.getPlayer()).inGroup("mod")) {
|
|
||||||
event.getPlayer().sendMessage(
|
|
||||||
"§cYou need to be a mod to use this channel.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Objective obj = PluginMain.SB.getObjective("mod");
|
|
||||||
for (Player p : PluginMain.GetPlayers()) {
|
|
||||||
if (PermissionsEx.getUser(p).inGroup("mod"))
|
|
||||||
obj.getScore(p.getName()).setScore(1);
|
|
||||||
else
|
|
||||||
obj.getScore(p.getName()).setScore(0);
|
|
||||||
}
|
|
||||||
PluginMain.Instance.getServer().dispatchCommand(
|
|
||||||
PluginMain.Console,
|
|
||||||
String.format(
|
|
||||||
"tellraw @a[score_mod=%d,score_mod_min=%d] %s",
|
|
||||||
1, 1, json.toString()));
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
event.getPlayer()
|
|
||||||
.sendMessage(
|
|
||||||
"§cAn error occured while sending the message. (IllegalStateException)");
|
|
||||||
return;
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
event.getPlayer()
|
|
||||||
.sendMessage(
|
|
||||||
"§cAn error occured while sending the message. (IllegalArgumentException)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
|
||||||
String.format("tellraw @a %s", json.toString()));
|
|
||||||
// System.out.println("JSON: " + json); // TO!DO: TMP
|
|
||||||
PluginMain.Instance
|
|
||||||
.getServer()
|
|
||||||
.getConsoleSender()
|
|
||||||
.sendMessage(
|
|
||||||
String.format("[%s] <%s%s> %s",
|
|
||||||
player.CurrentChannel.DisplayName, event
|
|
||||||
.getPlayer().getDisplayName(), player
|
|
||||||
.GetFormattedFlair(), event
|
|
||||||
.getMessage()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
@ -874,6 +390,12 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
for (Player pl : PluginMain.GetPlayers())
|
for (Player pl : PluginMain.GetPlayers())
|
||||||
pl.sendMessage(event.getPlayer().getDisplayName()
|
pl.sendMessage(event.getPlayer().getDisplayName()
|
||||||
+ " un" + s + "'d " + target.getDisplayName());
|
+ " un" + s + "'d " + target.getDisplayName());
|
||||||
|
Bukkit.getServer()
|
||||||
|
.getConsoleSender()
|
||||||
|
.sendMessage(
|
||||||
|
event.getPlayer().getDisplayName() + " un"
|
||||||
|
+ s + "'d "
|
||||||
|
+ target.getDisplayName());
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -928,9 +450,9 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean ActiveF = false;
|
static boolean ActiveF = false;
|
||||||
private int FCount = 0;
|
static int FCount = 0;
|
||||||
private MaybeOfflinePlayer FPlayer = null;
|
static MaybeOfflinePlayer FPlayer = null;
|
||||||
private Timer Ftimer;
|
private Timer Ftimer;
|
||||||
public static int AlphaDeaths;
|
public static int AlphaDeaths;
|
||||||
|
|
||||||
|
@ -1107,4 +629,114 @@ public class PlayerListener implements Listener { // 2015.07.16.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Channel ConsoleChannel = Channel.GlobalChat;
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onConsoleCommand(ServerCommandEvent event) {
|
||||||
|
if (event.getCommand().length() < 2)
|
||||||
|
return;
|
||||||
|
int index = event.getCommand().indexOf(" ");
|
||||||
|
String cmd = "";
|
||||||
|
if (index == -1) {
|
||||||
|
cmd = event.getCommand();
|
||||||
|
if (cmd.equalsIgnoreCase(Channel.GlobalChat.Command)) {
|
||||||
|
ConsoleChannel = Channel.GlobalChat;
|
||||||
|
event.getSender().sendMessage(
|
||||||
|
"§6You are now talking in: §b"
|
||||||
|
+ ConsoleChannel.DisplayName);
|
||||||
|
event.setCancelled(true);
|
||||||
|
} else if (cmd.equalsIgnoreCase(Channel.AdminChat.Command)) {
|
||||||
|
if (ConsoleChannel.equals(Channel.AdminChat))
|
||||||
|
ConsoleChannel = Channel.GlobalChat;
|
||||||
|
else
|
||||||
|
ConsoleChannel = Channel.AdminChat;
|
||||||
|
event.getSender().sendMessage(
|
||||||
|
"§6You are now talking in: §b"
|
||||||
|
+ ConsoleChannel.DisplayName);
|
||||||
|
event.setCancelled(true);
|
||||||
|
} else if (cmd.equalsIgnoreCase(Channel.ModChat.Command)) {
|
||||||
|
if (ConsoleChannel.equals(Channel.ModChat))
|
||||||
|
ConsoleChannel = Channel.GlobalChat;
|
||||||
|
else
|
||||||
|
ConsoleChannel = Channel.ModChat;
|
||||||
|
event.getSender().sendMessage(
|
||||||
|
"§6You are now talking in: §b"
|
||||||
|
+ ConsoleChannel.DisplayName);
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cmd = event.getCommand().substring(0, index);
|
||||||
|
if (cmd.equalsIgnoreCase(Channel.GlobalChat.Command)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
Channel c = ConsoleChannel;
|
||||||
|
ConsoleChannel = Channel.GlobalChat;
|
||||||
|
ChatProcessing.ProcessChat(Bukkit.getServer()
|
||||||
|
.getConsoleSender(),
|
||||||
|
event.getCommand().substring(index + 1));
|
||||||
|
ConsoleChannel = c;
|
||||||
|
} else if (cmd.equalsIgnoreCase(Channel.TownChat.Command)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
Channel c = ConsoleChannel;
|
||||||
|
ConsoleChannel = Channel.TownChat;
|
||||||
|
ChatProcessing.ProcessChat(Bukkit.getServer()
|
||||||
|
.getConsoleSender(),
|
||||||
|
event.getCommand().substring(index + 1));
|
||||||
|
ConsoleChannel = c;
|
||||||
|
} else if (cmd.equalsIgnoreCase(Channel.NationChat.Command)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
Channel c = ConsoleChannel;
|
||||||
|
ConsoleChannel = Channel.NationChat;
|
||||||
|
ChatProcessing.ProcessChat(Bukkit.getServer()
|
||||||
|
.getConsoleSender(),
|
||||||
|
event.getCommand().substring(index + 1));
|
||||||
|
ConsoleChannel = c;
|
||||||
|
} else if (cmd.equalsIgnoreCase(Channel.AdminChat.Command)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
Channel c = ConsoleChannel;
|
||||||
|
ConsoleChannel = Channel.AdminChat;
|
||||||
|
ChatProcessing.ProcessChat(Bukkit.getServer()
|
||||||
|
.getConsoleSender(),
|
||||||
|
event.getCommand().substring(index + 1));
|
||||||
|
ConsoleChannel = c;
|
||||||
|
} else if (cmd.equalsIgnoreCase(Channel.ModChat.Command)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
Channel c = ConsoleChannel;
|
||||||
|
ConsoleChannel = Channel.ModChat;
|
||||||
|
ChatProcessing.ProcessChat(Bukkit.getServer()
|
||||||
|
.getConsoleSender(),
|
||||||
|
event.getCommand().substring(index + 1));
|
||||||
|
ConsoleChannel = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cmd.toLowerCase().startsWith("un")) {
|
||||||
|
for (HelpTopic ht : PluginMain.Instance.getServer().getHelpMap()
|
||||||
|
.getHelpTopics()) {
|
||||||
|
// event.getSender().sendMessage("HT: " + ht.getName());
|
||||||
|
if (ht.getName().equalsIgnoreCase("/" + cmd))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String s = cmd.substring(2);
|
||||||
|
Player target = null;
|
||||||
|
target = Bukkit.getPlayer(event.getCommand().substring(index + 1));
|
||||||
|
if (target == null) {
|
||||||
|
event.getSender().sendMessage(
|
||||||
|
"§cError: Player not found. (/un" + s + " <player>)");
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
if (target != null) {
|
||||||
|
target.addPotionEffect(new PotionEffect(
|
||||||
|
PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
|
||||||
|
for (Player pl : PluginMain.GetPlayers())
|
||||||
|
pl.sendMessage(event.getSender().getName() + " un" + s
|
||||||
|
+ "'d " + target.getDisplayName());
|
||||||
|
Bukkit.getServer()
|
||||||
|
.getConsoleSender()
|
||||||
|
.sendMessage(
|
||||||
|
event.getSender().getName() + " un" + s + "'d "
|
||||||
|
+ target.getDisplayName());
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,6 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
this.getCommand("mwiki").setExecutor(comm);
|
this.getCommand("mwiki").setExecutor(comm);
|
||||||
this.getCommand("mwiki").setUsage(
|
this.getCommand("mwiki").setUsage(
|
||||||
this.getCommand("mwiki").getUsage().replace('&', '§'));
|
this.getCommand("mwiki").getUsage().replace('&', '§'));
|
||||||
this.getCommand("chat").setExecutor(comm);
|
|
||||||
Instance = this; // 2015.08.08.
|
Instance = this; // 2015.08.08.
|
||||||
Console = this.getServer().getConsoleSender(); // 2015.08.12.
|
Console = this.getServer().getConsoleSender(); // 2015.08.12.
|
||||||
LoadFiles(false); // 2015.08.09.
|
LoadFiles(false); // 2015.08.09.
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue