Less error messages, channel and command changes applied #66

Merged
NorbiPeti merged 6 commits from dev into master 2017-05-15 00:38:33 +00:00
33 changed files with 178 additions and 513 deletions

View file

@ -2,10 +2,11 @@ package buttondevteam.chat;
import org.bukkit.Bukkit;
public class AnnouncerThread {
public class AnnouncerThread implements Runnable {
private static int AnnounceMessageIndex = 0;
public static void Run() {
@Override
public void run() {
while (!PluginMain.Instance.stop) {
try {
Thread.sleep(PluginMain.AnnounceTime);

View file

@ -13,14 +13,10 @@ import org.bukkit.scoreboard.Objective;
import com.earth2me.essentials.Essentials;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
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;
import buttondevteam.chat.commands.UnlolCommand;
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
import buttondevteam.chat.formatting.*;
import buttondevteam.lib.TBMCChatEvent;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.TellrawSerializableEnum;
@ -82,8 +78,10 @@ public class ChatProcessing {
.registerTypeAdapter(boolean.class, new TellrawSerializer.TwBool()).disableHtmlEscaping().create();
}
// Returns e.setCancelled for custom event
public static boolean ProcessChat(Channel channel, CommandSender sender, String message) {
public static boolean ProcessChat(TBMCChatEvent e) {
Channel channel = e.getChannel();
CommandSender sender = e.getSender();
String message = e.getMessage();
long processstart = System.nanoTime();
if (PluginMain.essentials == null)
PluginMain.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
@ -122,127 +120,22 @@ public class ChatProcessing {
return true;
}
DebugCommand.SendDebugMessage(jsonstr);
if (channel.equals(Channel.TownChat) || channel.equals(Channel.NationChat)) {
if (player == null) {
sender.sendMessage("§cYou are not a player!");
return true;
}
for (Player p : Bukkit.getOnlinePlayers()) {
try {
Resident resident = PluginMain.Instance.TU.getResidentMap().get(p.getName().toLowerCase());
if (resident != null && !resident.getName().equals(player.getName())
&& resident.getModes().contains("spy"))
Bukkit.getPlayer(resident.getName()).sendMessage(String.format("[SPY-%s] - %s: %s",
channel.DisplayName, player.getDisplayName(), message));
} catch (Exception e) {
}
}
}
try {
if (channel.equals(Channel.TownChat)) {
Town town = null;
try {
final Resident resident = PluginMain.Instance.TU.getResidentMap()
.get(player.getName().toLowerCase());
if (resident != null && resident.hasTown())
town = resident.getTown();
} catch (NotRegisteredException e) {
}
if (town == null) {
player.sendMessage("§cYou aren't in a town or an error occured.");
return true;
}
int 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");
if (channel.filteranderrormsg != null) {
Objective obj = PluginMain.SB.getObjective(channel.ID);
int score = -1;
for (Player p : Bukkit.getOnlinePlayers()) {
try {
if (town.getResidents().stream().anyMatch(r -> r.getName().equalsIgnoreCase(p.getName())))
obj.getScore(p.getName()).setScore(index);
else
obj.getScore(p.getName()).setScore(-1);
} catch (Exception e) {
obj.getScore(p.getName()).setScore(-1);
}
obj.getScore(p.getUniqueId().toString()).setScore(score = e.getMCScore(p));
}
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
String.format("tellraw @a[score_town=%d,score_town_min=%d] %s", index, index, jsonstr));
} else if (channel.equals(Channel.NationChat)) {
Town town = null;
try {
final Resident resident = PluginMain.Instance.TU.getResidentMap()
.get(player.getName().toLowerCase());
if (resident != null && resident.hasTown())
town = resident.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;
}
int 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 : Bukkit.getOnlinePlayers()) {
try {
if (nation.getResidents().stream().anyMatch(r -> r.getName().equalsIgnoreCase(p.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, jsonstr));
} else if (channel.equals(Channel.AdminChat)) {
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 : Bukkit.getOnlinePlayers()) {
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, jsonstr));
} else if (channel.equals(Channel.ModChat)) {
if (player != null && !PluginMain.permission.playerInGroup(player, "mod")) {
player.sendMessage("§cYou need to be a mod to use this channel.");
return true;
}
Objective obj = PluginMain.SB.getObjective("mod");
for (Player p : Bukkit.getOnlinePlayers()) {
if (PluginMain.permission.playerInGroup(p, "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, jsonstr));
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, String.format(
"tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID, score, jsonstr));
} else
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
String.format("tellraw @a %s", jsonstr));
} catch (Exception e) {
TBMCCoreAPI.SendException("An error occured while sending a chat message!", e);
player.sendMessage("§cAn error occured while sending the message.");
} catch (Exception ex) {
TBMCCoreAPI.SendException("An error occured while sending a chat message!", ex);
sender.sendMessage("§cAn error occured while sending the message.");
return true;
}
PluginMain.Instance.getServer().getConsoleSender().sendMessage(String.format("%s <%s> %s", channelidentifier,

View file

@ -5,6 +5,7 @@ import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
@ -17,7 +18,10 @@ import org.htmlcleaner.TagNode;
import buttondevteam.chat.commands.YeehawCommand;
import buttondevteam.chat.listener.PlayerListener;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.Color;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.chat.Channel.RecipientTestResult;
import buttondevteam.lib.player.TBMCPlayerBase;
import com.earth2me.essentials.Essentials;
@ -25,7 +29,9 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.palmergames.bukkit.towny.Towny;
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;
import com.palmergames.bukkit.towny.object.TownyUniverse;
@ -34,6 +40,7 @@ import java.lang.String;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
@ -47,11 +54,16 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
// https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
public static PluginMain Instance;
public static ConsoleCommandSender Console;
public static Scoreboard SB;
public final static String FlairThreadURL = "https://www.reddit.com/r/Chromagamers/comments/51ys94/flair_thread_for_the_mc_server/";
public TownyUniverse TU;
public ArrayList<Town> Towns;
public ArrayList<Nation> Nations;
public static Scoreboard SB;
public static TownyUniverse TU;
public static ArrayList<Town> Towns;
public static ArrayList<Nation> Nations;
public static Channel TownChat;
public static Channel NationChat;
/**
* <p>
* This variable is used as a cache for flair state checking when reading the flair thread.
@ -72,37 +84,22 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
Console = this.getServer().getConsoleSender();
LoadFiles();
SB = PluginMain.Instance.getServer().getScoreboardManager().getMainScoreboard(); // Main can be detected with @a[score_...]
if (SB.getObjective("town") == null)
SB.registerNewObjective("town", "dummy");
if (SB.getObjective("nation") == null)
SB.registerNewObjective("nation", "dummy");
if (SB.getObjective("admin") == null)
SB.registerNewObjective("admin", "dummy");
if (SB.getObjective("mod") == null)
SB.registerNewObjective("mod", "dummy");
SB = getServer().getScoreboardManager().getMainScoreboard(); // Main can be detected with @a[score_...]
TU = ((Towny) Bukkit.getPluginManager().getPlugin("Towny")).getTownyUniverse();
Towns = new ArrayList<Town>(TU.getTownsMap().values());
Nations = new ArrayList<Nation>(TU.getNationsMap().values());
Towns = new ArrayList<Town>(TU.getTownsMap().values()); // Creates a snapshot of towns, new towns will be added when needed
Nations = new ArrayList<Nation>(TU.getNationsMap().values()); // Same here but with nations
TBMCChatAPI.RegisterChatChannel(
TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false)));
TBMCChatAPI.RegisterChatChannel(
NationChat = new Channel("§6NC§f", Color.Gold, "nc", s -> checkTownNationChat(s, true)));
setupChat();
setupEconomy();
setupPermissions();
Runnable r = new Runnable() {
public void run() {
FlairGetterThreadMethod();
}
};
Thread t = new Thread(r);
t.start();
r = new Runnable() {
public void run() {
AnnouncerThread.Run();
}
};
t = new Thread(r);
t.start();
new Thread(() -> FlairGetterThreadMethod()).start();
new Thread(new AnnouncerThread()).start();
}
public Boolean stop = false;
@ -153,24 +150,21 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
}
PlayersWithFlairs.add(ign); // Don't redownload even if flair isn't accepted
}
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
} catch (Exception e) {
errorcount++;
if (errorcount >= 10) {
errorcount = 0;
TBMCCoreAPI.SendException("Error while getting flairs from Reddit!", e);
if (!e.getMessage().contains("Server returned HTTP response code")
&& !(e instanceof UnknownHostException))
TBMCCoreAPI.SendException("Error while getting flairs from Reddit!", e);
}
}
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
@ -323,4 +317,47 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
return (economy != null);
}
/**
* Return the error message for the message sender if they can't send it and the score
*/
private static RecipientTestResult checkTownNationChat(CommandSender sender, boolean nationchat) {
if (!(sender instanceof Player))
return new RecipientTestResult("§cYou are not a player!");
try {
Resident resident = PluginMain.TU.getResidentMap().get(sender.getName().toLowerCase());
if (resident != null && resident.getModes().contains("spy"))
return null;
/*
* p.sendMessage(String.format("[SPY-%s] - %s: %s", channel.DisplayName, ((Player) sender).getDisplayName(), message));
*/
Town town = null;
if (resident != null && resident.hasTown())
town = resident.getTown();
if (town == null)
return new RecipientTestResult("You aren't in a town.");
Nation nation = null;
int index = -1;
if (nationchat) {
if (town.hasNation())
nation = town.getNation();
if (nation == null)
return new RecipientTestResult("Your town isn't in a nation.");
index = PluginMain.Nations.indexOf(nation);
if (index < 0) {
PluginMain.Nations.add(nation);
index = PluginMain.Nations.size() - 1;
}
} else {
index = PluginMain.Towns.indexOf(town);
if (index < 0) {
PluginMain.Towns.add(town);
index = PluginMain.Towns.size() - 1;
}
}
return new RecipientTestResult(index);
} catch (NotRegisteredException e) {
return new RecipientTestResult("You (probably) aren't knwon by Towny! (Not in a town)");
}
}
}

View file

@ -1,14 +1,15 @@
package buttondevteam.chat.commands;
import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.lib.chat.TBMCCommandBase;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.PlayerCommandBase;
import buttondevteam.lib.player.TBMCPlayer;
public final class ChatonlyCommand extends TBMCCommandBase {
@CommandClass(modOnly = false)
public final class ChatonlyCommand extends PlayerCommandBase {
@Override
public String[] GetHelpText(String alias) {
@ -20,8 +21,7 @@ public final class ChatonlyCommand extends TBMCCommandBase {
}
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
Player player = (Player) sender;
public boolean OnCommand(Player player, String alias, String[] args) {
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
p.ChatOnly = true;
player.setGameMode(GameMode.SPECTATOR);
@ -29,19 +29,4 @@ public final class ChatonlyCommand extends TBMCCommandBase {
return true;
}
@Override
public String GetCommandPath() {
return "chatonly";
}
@Override
public boolean GetPlayerOnly() {
return false;
}
@Override
public boolean GetModOnly() {
return false;
}
}

View file

@ -5,8 +5,10 @@ import java.net.URLEncoder;
import org.bukkit.command.CommandSender;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.TBMCCommandBase;
@CommandClass(modOnly = false)
public class MWikiCommand extends TBMCCommandBase {
@Override
@ -37,19 +39,4 @@ public class MWikiCommand extends TBMCCommandBase {
return true;
}
@Override
public String GetCommandPath() {
return "mwiki";
}
@Override
public boolean GetPlayerOnly() {
return false;
}
@Override
public boolean GetModOnly() {
return false;
}
}

View file

@ -1,13 +1,14 @@
package buttondevteam.chat.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.lib.chat.TBMCCommandBase;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.PlayerCommandBase;
import buttondevteam.lib.player.TBMCPlayer;
public final class OOCCommand extends TBMCCommandBase {
@CommandClass(modOnly = false)
public final class OOCCommand extends PlayerCommandBase {
@Override
public String[] GetHelpText(String alias) {
@ -17,8 +18,7 @@ public final class OOCCommand extends TBMCCommandBase {
}
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
Player player = (Player) sender;
public boolean OnCommand(Player player, String alias, String[] args) {
if (args.length == 0) {
return false;
} else {
@ -33,19 +33,4 @@ public final class OOCCommand extends TBMCCommandBase {
return true;
}
@Override
public String GetCommandPath() {
return "ooc";
}
@Override
public boolean GetPlayerOnly() {
return true;
}
@Override
public boolean GetModOnly() {
return false;
}
}

View file

@ -6,8 +6,10 @@ import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.TBMCCommandBase;
@CommandClass(modOnly = false)
public final class UnlolCommand extends TBMCCommandBase {
public static CommandSender Lastlol = null;
@ -26,7 +28,7 @@ public final class UnlolCommand extends TBMCCommandBase {
if (Lastlol != null) {
if (Lastlol instanceof Player)
((Player) Lastlol)
.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 2 * 20, 5, false, false));
String msg = (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName())
+ (Lastlolornot ? " unlolled " : " unlaughed ")
+ (Lastlol instanceof Player ? ((Player) Lastlol).getDisplayName() : Lastlol.getName());
@ -35,19 +37,4 @@ public final class UnlolCommand extends TBMCCommandBase {
}
return true;
}
@Override
public String GetCommandPath() {
return "unlol";
}
@Override
public boolean GetPlayerOnly() {
return false;
}
@Override
public boolean GetModOnly() {
return false;
}
}

View file

@ -4,20 +4,26 @@ import java.util.Arrays;
import java.util.stream.Collectors;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.listener.PlayerListener;
import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.chat.TBMCCommandBase;
import buttondevteam.lib.player.TBMCPlayer;
@CommandClass(modOnly = false)
public class WaitWhatCommand extends TBMCCommandBase {
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
Channel channel;
if (sender instanceof Player && ((Player) sender).isOnline())
channel = TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class).CurrentChannel;
else if (sender instanceof ConsoleCommandSender)
channel = PlayerListener.ConsoleChannel;
else
channel = Channel.GlobalChat;
final String message;
@ -36,14 +42,4 @@ public class WaitWhatCommand extends TBMCCommandBase {
"Wait what" //
};
}
@Override
public boolean GetPlayerOnly() {
return false;
}
@Override
public boolean GetModOnly() {
return false;
}
}

View file

@ -4,9 +4,11 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.TBMCCommandBase;
import buttondevteam.lib.player.TBMCYEEHAWEvent;
@CommandClass(modOnly = false)
public class YeehawCommand extends TBMCCommandBase {
@Override
@ -26,19 +28,4 @@ public class YeehawCommand extends TBMCCommandBase {
Bukkit.getPluginManager().callEvent(new TBMCYEEHAWEvent(sender));
return true;
}
@Override
public String GetCommandPath() {
return "yeehaw";
}
@Override
public boolean GetPlayerOnly() {
return false;
}
@Override
public boolean GetModOnly() {
return false;
}
}

View file

@ -6,10 +6,12 @@ import org.bukkit.entity.Player;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.listener.PlayerListener;
import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.chat.TBMCCommandBase;
import buttondevteam.lib.player.TBMCPlayer;
@CommandClass(modOnly = false, excludeFromPath = true)
public abstract class AppendTextCommandBase extends TBMCCommandBase {
public abstract String[] GetHelpText(String alias);
@ -31,14 +33,4 @@ public abstract class AppendTextCommandBase extends TBMCCommandBase {
TBMCChatAPI.SendChatMessage(Channel.GlobalChat, sender, msg);
return true;
}
@Override
public boolean GetPlayerOnly() {
return false;
}
@Override
public boolean GetModOnly() {
return false;
}
}

View file

@ -4,10 +4,10 @@ public final class ShrugCommand extends AppendTextCommandBase {
@Override
public String[] GetHelpText(String alias) {
return new String[] { "§6---- Shrug ----",
"This command appends a shrug after your message",
"Or just makes you shrug",
"Use either /" + alias + " <message> or just /" + alias };
return new String[] { "§6---- Shrug ----", //
"This command appends a shrug after your message", //
"Or just makes you shrug", //
"Use either /" + alias + " <message> or just /" + alias }; //
}
@Override
@ -15,9 +15,4 @@ public final class ShrugCommand extends AppendTextCommandBase {
return "¯\\\\\\_(ツ)\\_/¯";
}
@Override
public String GetCommandPath() {
return "shrug";
}
}

View file

@ -4,9 +4,9 @@ public final class TableflipCommand extends AppendTextCommandBase {
@Override
public String[] GetHelpText(String alias) {
return new String[] { "§6---- Tableflip ----",
"This command appends a tableflip after your message",
"Or just makes you tableflip",
return new String[] { "§6---- Tableflip ----", //
"This command appends a tableflip after your message", //
"Or just makes you tableflip", //
"Use either /" + alias + " <message> or just /" + alias };
}
@ -14,9 +14,4 @@ public final class TableflipCommand extends AppendTextCommandBase {
public String GetAppendedText() {
return "(╯°□°)╯︵ ┻━┻";
}
@Override
public String GetCommandPath() {
return "tableflip";
}
}

View file

@ -4,9 +4,9 @@ public final class UnflipCommand extends AppendTextCommandBase {
@Override
public String[] GetHelpText(String alias) {
return new String[] { "§6---- Unflip ----",
"This command appends an unflip after your message",
"Or just unflips as you",
return new String[] { "§6---- Unflip ----", //
"This command appends an unflip after your message", //
"Or just unflips as you", //
"Use either /" + alias + " <message> or just /" + alias };
}
@ -15,9 +15,4 @@ public final class UnflipCommand extends AppendTextCommandBase {
return "┬─┬ ( ゜-゜ノ)";
}
@Override
public String GetCommandPath() {
return "unflip";
}
}

View file

@ -10,8 +10,12 @@ import buttondevteam.chat.FlairStates;
import buttondevteam.chat.PlayerJoinTimerTask;
import buttondevteam.chat.PluginMain;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
import buttondevteam.lib.player.TBMCPlayer;
@CommandClass(modOnly = false)
@OptionallyPlayerCommandClass(playerOnly = true)
public class AcceptCommand extends UCommandBase {
@Override
@ -92,9 +96,4 @@ public class AcceptCommand extends UCommandBase {
return true;
}
@Override
public String GetUCommandPath() {
return "accept";
}
}

View file

@ -8,6 +8,8 @@ import buttondevteam.chat.PluginMain;
import buttondevteam.lib.chat.*;
import buttondevteam.lib.player.TBMCPlayer;
@CommandClass(modOnly = false)
@OptionallyPlayerCommandClass(playerOnly = true)
public class CCommand extends UCommandBase {
@Override
@ -54,9 +56,4 @@ public class CCommand extends UCommandBase {
return true;
}
@Override
public String GetUCommandPath() {
return "c";
}
}

View file

@ -6,9 +6,11 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import buttondevteam.chat.PluginMain;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.chat.TBMCCommandBase;
@CommandClass(modOnly = false)
public final class HelpCommand extends UCommandBase {
@Override
@ -35,8 +37,8 @@ public final class HelpCommand extends UCommandBase {
ArrayList<String> text = new ArrayList<String>();
text.add("§6---- Command list ----");
for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values())
if (!cmd.GetModOnly() || PluginMain.permission.has(sender, "tbmc.admin"))
if (!cmd.GetPlayerOnly() || sender instanceof Player)
if (!cmd.getClass().getAnnotation(CommandClass.class).modOnly() || PluginMain.permission.has(sender, "tbmc.admin"))
if (!cmd.isPlayerOnly() || sender instanceof Player)
if (!cmd.GetCommandPath().contains(" "))
text.add("/" + cmd.GetCommandPath());
else {
@ -79,14 +81,4 @@ public final class HelpCommand extends UCommandBase {
return true;
}
@Override
public String GetUCommandPath() {
return "help";
}
@Override
public boolean GetPlayerOnly() {
return false;
}
}

View file

@ -5,8 +5,12 @@ import org.bukkit.entity.Player;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.FlairStates;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
import buttondevteam.lib.player.TBMCPlayer;
@CommandClass(modOnly = false)
@OptionallyPlayerCommandClass(playerOnly = true)
public final class IgnoreCommand extends UCommandBase {
@Override
@ -38,9 +42,4 @@ public final class IgnoreCommand extends UCommandBase {
return true;
}
@Override
public String GetUCommandPath() {
return "ignore";
}
}

View file

@ -3,10 +3,12 @@ package buttondevteam.chat.commands.ucmds;
import org.bukkit.command.CommandSender;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
import buttondevteam.lib.player.TBMCPlayerBase;
@CommandClass(modOnly = false)
public class InfoCommand extends UCommandBase {
@Override
@ -18,11 +20,6 @@ public class InfoCommand extends UCommandBase {
};
}
@Override
public String GetUCommandPath() {
return "info";
}
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
if (args.length == 0)
@ -44,9 +41,4 @@ public class InfoCommand extends UCommandBase {
}
return true;
}
@Override
public boolean GetPlayerOnly() {
return false;
}
}

View file

@ -2,6 +2,9 @@ package buttondevteam.chat.commands.ucmds;
import org.bukkit.command.CommandSender;
import buttondevteam.lib.chat.CommandClass;
@CommandClass(modOnly = false)
public class OpmeCommand extends UCommandBase {
@Override
@ -15,9 +18,4 @@ public class OpmeCommand extends UCommandBase {
return true;
}
@Override
public String GetUCommandPath() {
return "opme";
}
}

View file

@ -1,25 +1,13 @@
package buttondevteam.chat.commands.ucmds;
import buttondevteam.lib.chat.TBMCCommandBase;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.OptionallyPlayerCommandBase;
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
public abstract class UCommandBase extends TBMCCommandBase {
@CommandClass(modOnly = false, path = "u")
@OptionallyPlayerCommandClass(playerOnly = false)
public abstract class UCommandBase extends OptionallyPlayerCommandBase {
public abstract String[] GetHelpText(String alias);
@Override
public String GetCommandPath() {
return "u " + GetUCommandPath();
}
public abstract String GetUCommandPath();
@Override
public boolean GetPlayerOnly() {
return true;
}
@Override
public boolean GetModOnly() {
return false;
}
}

View file

@ -1,25 +1,11 @@
package buttondevteam.chat.commands.ucmds.admin;
import buttondevteam.chat.commands.ucmds.UCommandBase;
import buttondevteam.lib.chat.CommandClass;
@CommandClass(modOnly = true)
public abstract class AdminCommandBase extends UCommandBase {
public abstract String[] GetHelpText(String alias);
@Override
public String GetUCommandPath() {
return "admin " + GetAdminCommandPath();
}
@Override
public boolean GetPlayerOnly() {
return false; // Allow admin commands in console
}
public abstract String GetAdminCommandPath();
@Override
public boolean GetModOnly() {
return true;
}
}

View file

@ -13,11 +13,6 @@ public class DebugCommand extends AdminCommandBase {
"Toggles debug mode, which prints debug messages to the console." };
}
@Override
public String GetAdminCommandPath() {
return "debug";
}
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
sender.sendMessage("§eDebug mode " + ((DebugMode = !DebugMode) ? "§aenabled." : "§cdisabled."));

View file

@ -40,9 +40,4 @@ public class PlayerInfoCommand extends AdminCommandBase {
return true;
}
@Override
public String GetAdminCommandPath() {
return "playerinfo";
}
}

View file

@ -20,9 +20,4 @@ public class SaveCommand extends AdminCommandBase {
return true;
}
@Override
public String GetAdminCommandPath() {
return "save";
}
}

View file

@ -68,9 +68,4 @@ public class SetFlairCommand extends AdminCommandBase {
return true;
}
@Override
public String GetAdminCommandPath() {
return "setflair";
}
}

View file

@ -39,9 +39,4 @@ public class UpdatePlugin extends AdminCommandBase {
}
}
@Override
public String GetAdminCommandPath() {
return "updateplugin";
}
}

View file

@ -34,9 +34,4 @@ public class AddCommand extends AnnounceCommandBase {
return true;
}
@Override
public String GetAnnounceCommandPath() {
return "add";
}
}

View file

@ -1,25 +1,13 @@
package buttondevteam.chat.commands.ucmds.announce;
import buttondevteam.chat.commands.ucmds.UCommandBase;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
@CommandClass(modOnly = true)
@OptionallyPlayerCommandClass(playerOnly = false)
public abstract class AnnounceCommandBase extends UCommandBase {
public abstract String[] GetHelpText(String alias);
@Override
public String GetUCommandPath() {
return "announce " + GetAnnounceCommandPath();
}
public abstract String GetAnnounceCommandPath();
@Override
public boolean GetPlayerOnly() {
return false;
}
@Override
public boolean GetModOnly() {
return true;
}
}

View file

@ -42,9 +42,4 @@ public class EditCommand extends AnnounceCommandBase {
return true;
}
@Override
public String GetAnnounceCommandPath() {
return "edit";
}
}

View file

@ -25,9 +25,4 @@ public class ListCommand extends AnnounceCommandBase {
return true;
}
@Override
public String GetAnnounceCommandPath() {
return "list";
}
}

View file

@ -27,9 +27,4 @@ public class RemoveCommand extends AnnounceCommandBase {
return true;
}
@Override
public String GetAnnounceCommandPath() {
return "remove";
}
}

View file

@ -30,9 +30,4 @@ public class SetTimeCommand extends AnnounceCommandBase {
return true;
}
@Override
public String GetAnnounceCommandPath() {
return "settime";
}
}

View file

@ -1,37 +1,23 @@
package buttondevteam.chat.listener;
import java.util.ArrayList;
import java.util.*;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import com.palmergames.bukkit.towny.Towny;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.*;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.*;
import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.help.HelpTopic;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.ChatProcessing;
import buttondevteam.chat.PluginMain;
import buttondevteam.chat.*;
import buttondevteam.lib.TBMCChatEvent;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.ChatChannelRegisterEvent;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
@ -39,13 +25,6 @@ import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.palmergames.bukkit.towny.war.eventwar.War;
import com.palmergames.bukkit.towny.object.WorldCoord;
import com.vexsoftware.votifier.model.Vote;
import com.vexsoftware.votifier.model.VotifierEvent;
@ -86,7 +65,7 @@ public class PlayerListener implements Listener {
if (index == -1) {
cmd = event.getMessage().substring(1);
for (Channel channel : Channel.getChannels()) {
if (cmd.equalsIgnoreCase(channel.Command)) {
if (cmd.equalsIgnoreCase(channel.ID)) {
if (mp.CurrentChannel.equals(channel))
mp.CurrentChannel = Channel.GlobalChat;
else
@ -99,7 +78,7 @@ public class PlayerListener implements Listener {
} else {
cmd = event.getMessage().substring(1, index);
for (Channel channel : Channel.getChannels()) {
if (cmd.equalsIgnoreCase(channel.Command)) {
if (cmd.equalsIgnoreCase(channel.ID)) {
event.setCancelled(true);
Channel c = mp.CurrentChannel;
mp.CurrentChannel = channel;
@ -119,42 +98,7 @@ public class PlayerListener implements Listener {
}
}
}
if (cmd.equalsIgnoreCase("sethome")) { // TODO: Move out?
TownyUniverse tu = PluginMain.Instance.TU;
try {
TownBlock tb = WorldCoord.parseWorldCoord(event.getPlayer()).getTownBlock();
if (tb.hasTown()) {
Town town = tb.getTown();
if (town.hasNation()) {
Resident res = tu.getResidentMap().get(event.getPlayer().getName());
if (res != null && res.hasTown()) {
Town town2 = res.getTown();
if (town2.hasNation()) {
if (town.getNation().getEnemies().contains(town2.getNation())) {
event.getPlayer().sendMessage("§cYou cannot set homes in enemy territory.");
event.setCancelled(true);
return;
}
}
}
}
}
} catch (NotRegisteredException e) {
return;
}
} else if (cmd.equalsIgnoreCase("home") || cmd.equalsIgnoreCase("tpa") || cmd.equalsIgnoreCase("tp")) {
String currentWorld = event.getPlayer().getLocation().getWorld().getName();
Location currentLocation = event.getPlayer().getLocation();
TownyUniverse universe = Towny.getPlugin(Towny.class).getTownyUniverse();
if (TownyUniverse.isWarTime()) {
War war = universe.getWarEvent();
if (war.isWarZone(
new WorldCoord(currentWorld, currentLocation.getBlockX(), currentLocation.getBlockZ()))) {
event.getPlayer().sendMessage("§cError: You can't teleport out of a war zone!");
event.setCancelled(true);
}
}
} else if (cmd.toLowerCase().startsWith("un")) {
if (cmd.toLowerCase().startsWith("un")) {
for (HelpTopic ht : PluginMain.Instance.getServer().getHelpMap().getHelpTopics()) {
if (ht.getName().equalsIgnoreCase("/" + cmd))
return;
@ -175,15 +119,6 @@ public class PlayerListener implements Listener {
}
}
}
if (cmd.equalsIgnoreCase("f")) {
String[] args = event.getMessage().substring(index + 1).split(" ");
if (args.length > 1) {
if (args[0].toLowerCase().equals("enemy") && args[1].equalsIgnoreCase("newhaven")) {
event.setCancelled(true);
event.getPlayer().sendMessage("§cYou are not allowed to set New Haven as your enemy faction.");
}
}
}
}
@EventHandler
@ -274,7 +209,7 @@ public class PlayerListener implements Listener {
if (index == -1) {
cmd = event.getCommand();
for (Channel channel : Channel.getChannels()) {
if (cmd.equalsIgnoreCase(channel.Command)) {
if (cmd.equalsIgnoreCase(channel.ID)) {
if (ConsoleChannel.equals(channel))
ConsoleChannel = Channel.GlobalChat;
else
@ -287,7 +222,7 @@ public class PlayerListener implements Listener {
} else {
cmd = event.getCommand().substring(0, index);
for (Channel channel : Channel.getChannels()) {
if (cmd.equalsIgnoreCase(channel.Command)) {
if (cmd.equalsIgnoreCase(channel.ID)) {
Channel c = ConsoleChannel;
ConsoleChannel = channel;
TBMCChatAPI.SendChatMessage(PlayerListener.ConsoleChannel, Bukkit.getConsoleSender(),
@ -339,7 +274,7 @@ public class PlayerListener implements Listener {
try {
if (e.isCancelled())
return;
e.setCancelled(ChatProcessing.ProcessChat(e.getChannel(), e.getSender(), e.getMessage()));
e.setCancelled(ChatProcessing.ProcessChat(e));
} catch (Exception ex) {
for (Player p : Bukkit.getOnlinePlayers())
p.sendMessage("§c!§r["
@ -349,4 +284,10 @@ public class PlayerListener implements Listener {
TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex);
}
}
@EventHandler
public void onChannelRegistered(ChatChannelRegisterEvent e) {
if (e.getChannel().filteranderrormsg != null && PluginMain.SB.getObjective(e.getChannel().ID) == null) // Not global chat and doesn't exist yet
PluginMain.SB.registerNewObjective(e.getChannel().ID, "dummy");
}
}