Moved and improved Channel stuff and removed old stuff
Removed tons of lines Also reduced unlol effect duration a few days ago, commiting now
This commit is contained in:
parent
8f69e40d8b
commit
9e1bd49cd0
5 changed files with 46 additions and 218 deletions
|
@ -23,6 +23,7 @@ import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
|||
import buttondevteam.chat.formatting.*;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import buttondevteam.lib.chat.Channel.RecipientTestResult;
|
||||
import buttondevteam.lib.chat.TellrawSerializableEnum;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
|
@ -122,125 +123,31 @@ 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");
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
try {
|
||||
if (town.getResidents().stream().anyMatch(r -> r.getName().equalsIgnoreCase(p.getName())))
|
||||
obj.getScore(p.getName()).setScore(index);
|
||||
if (channel.filteranderrormsg != null) {
|
||||
Objective obj = PluginMain.SB.getObjective(channel.ID);
|
||||
RecipientTestResult result = channel.filteranderrormsg.apply(player);
|
||||
if (result.errormessage != null)
|
||||
player.sendMessage("§c" + result.errormessage);
|
||||
else
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (p == player)
|
||||
continue;
|
||||
result = channel.filteranderrormsg.apply(p);
|
||||
if (result.errormessage == null)
|
||||
obj.getScore(p.getName()).setScore(result.score);
|
||||
else
|
||||
obj.getScore(p.getName()).setScore(-1);
|
||||
} catch (Exception e) {
|
||||
obj.getScore(p.getName()).setScore(-1);
|
||||
}
|
||||
}
|
||||
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));
|
||||
String.format("tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, result.score, jsonstr));
|
||||
} else
|
||||
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
||||
String.format("tellraw @a %s", jsonstr));
|
||||
} catch (Exception e) {
|
||||
} catch (
|
||||
|
||||
Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occured while sending a chat message!", e);
|
||||
player.sendMessage("§cAn error occured while sending the message.");
|
||||
return true;
|
||||
|
|
|
@ -47,11 +47,13 @@ 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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This variable is used as a cache for flair state checking when reading the flair thread.
|
||||
|
@ -72,37 +74,17 @@ 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
|
||||
|
||||
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(() -> AnnouncerThread.Run()).start();
|
||||
}
|
||||
|
||||
public Boolean stop = false;
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package buttondevteam.chat.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.PlayerCommandBase;
|
||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
|
||||
@CommandClass(modOnly = false)
|
||||
|
|
|
@ -28,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());
|
||||
|
|
|
@ -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(),
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue