More components, broadcasts #98

Merged
NorbiPeti merged 13 commits from dev into master 2019-03-17 01:28:22 +00:00
9 changed files with 68 additions and 41 deletions
Showing only changes of commit e510667215 - Show all commits

View file

@ -9,6 +9,7 @@ import buttondevteam.chat.components.towncolors.TownColorComponent;
import buttondevteam.chat.components.towny.TownyComponent;
import buttondevteam.chat.listener.PlayerJoinLeaveListener;
import buttondevteam.chat.listener.PlayerListener;
import buttondevteam.core.MainPlugin;
import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.architecture.ButtonPlugin;
@ -17,7 +18,6 @@ import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.chat.Color;
import buttondevteam.lib.chat.TBMCChatAPI;
import com.earth2me.essentials.Essentials;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
@ -50,6 +50,7 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this);
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerJoinLeaveListener(), this);
TBMCChatAPI.AddCommands(this, YeehawCommand.class);
MainPlugin.Instance.setChatHandlerEnabled(false); //Disable Core chat handler
Console = this.getServer().getConsoleSender();
SB = getServer().getScoreboardManager().getMainScoreboard(); // Main can be detected with @a[score_...]
@ -79,7 +80,6 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15
public static Permission permission = null;
public static Economy economy = null;
public static Chat chat = null;
private boolean setupPermissions() {
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager()

View file

@ -1,5 +1,6 @@
package buttondevteam.chat.components.announce;
import buttondevteam.chat.PluginMain;
import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.TBMCSystemChatEvent;
import buttondevteam.lib.architecture.Component;
@ -9,7 +10,7 @@ import org.bukkit.Bukkit;
import java.util.ArrayList;
public class AnnouncerComponent extends Component implements Runnable {
public class AnnouncerComponent extends Component<PluginMain> implements Runnable {
public ConfigData<ArrayList<String>> AnnounceMessages() {
return getConfig().getData("announceMessages", new ArrayList<>(0));
}

View file

@ -1,6 +1,7 @@
package buttondevteam.chat.components.flair;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.PluginMain;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.architecture.ConfigData;
@ -21,7 +22,7 @@ import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.*;
public class FlairComponent extends Component {
public class FlairComponent extends Component<PluginMain> {
private ConfigData<String> FlairThreadURL() {
return getConfig().getData("flairThreadURL", "https://www.reddit.com/r/Chromagamers/comments/51ys94/flair_thread_for_the_mc_server/");
}

View file

@ -11,7 +11,6 @@ import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.player.ChromaGamerBase;
import buttondevteam.lib.player.TBMCPlayer;
import lombok.Getter;
import lombok.val;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@ -29,7 +28,7 @@ import org.bukkit.scheduler.BukkitTask;
import java.util.ArrayList;
import java.util.Random;
public class FunComponent extends Component implements Listener {
public class FunComponent extends Component<PluginMain> implements Listener {
private final static String[] LaughStrings = new String[]{"xd", "lel", "lawl", "kek", "lmao", "hue", "hah", "rofl"};
private boolean ActiveF = false;
private ChatPlayer FPlayer = null;

View file

@ -14,6 +14,7 @@ import buttondevteam.lib.player.TBMCPlayerJoinEvent;
import com.earth2me.essentials.User;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Nation;
import lombok.Getter;
import lombok.experimental.var;
import lombok.val;
import org.bukkit.Bukkit;
@ -35,7 +36,7 @@ import java.util.function.Function;
import java.util.stream.Collectors;
@ComponentMetadata(depends = TownyComponent.class)
public class TownColorComponent extends Component implements Listener {
public class TownColorComponent extends Component<PluginMain> implements Listener {
/**
* Names lowercased
*/
@ -49,17 +50,22 @@ public class TownColorComponent extends Component implements Listener {
return getConfig().getData("colorCount", (byte) 1, cc -> ((Integer) cc).byteValue(), Byte::intValue);
}
public ConfigData<Boolean> useNationColors() { //TODO
public ConfigData<Boolean> useNationColors() {
return getConfig().getData("useNationColors", true);
}
@Getter
private static TownColorComponent component;
@SuppressWarnings("unchecked")
@Override
protected void enable() {
component = this;
//TODO: Don't register all commands automatically (welp)
Consumer<ConfigurationSection> loadTC = cs -> TownColorComponent.TownColors.putAll(cs.getValues(true).entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, v -> ((List<String>) v.getValue()).stream()
.map(Color::valueOf).toArray(Color[]::new))));
boolean usenc = useNationColors().get();
Consumer<ConfigurationSection> loadNC = ncs ->
TownColorComponent.NationColor.putAll(ncs.getValues(true).entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, v -> Color.valueOf((String) v.getValue()))));
@ -68,14 +74,17 @@ public class TownColorComponent extends Component implements Listener {
loadTC.accept(cs);
else
load_old(loadTC, null); //Load old data
var ncs = getConfig().getConfig().getConfigurationSection("nationcolors");
if (ncs != null)
loadNC.accept(ncs);
else
load_old(null, loadNC); //Why not choose by making different args null
if (usenc) {
var ncs = getConfig().getConfig().getConfigurationSection("nationcolors");
if (ncs != null)
loadNC.accept(ncs);
else
load_old(null, loadNC); //Why not choose by making different args null
}
TownColors.keySet().removeIf(t -> !TownyComponent.TU.getTownsMap().containsKey(t)); // Removes town colors for deleted/renamed towns
NationColor.keySet().removeIf(n -> !TownyComponent.TU.getNationsMap().containsKey(n)); // Removes nation colors for deleted/renamed nations
if (usenc)
NationColor.keySet().removeIf(n -> !TownyComponent.TU.getNationsMap().containsKey(n)); // Removes nation colors for deleted/renamed nations
Bukkit.getScheduler().runTask(getPlugin(), () -> {
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
@ -86,7 +95,9 @@ public class TownColorComponent extends Component implements Listener {
val town = TownyComponent.TU.getTownsMap().get(entry.getKey());
Nation nation;
Color nc;
if (!town.hasNation() || (nation = town.getNation()) == null || (nc = NationColor.get(nation.getName().toLowerCase())) == null)
if (!useNationColors().get())
nc = null;
else if (!town.hasNation() || (nation = town.getNation()) == null || (nc = NationColor.get(nation.getName().toLowerCase())) == null)
nc = Color.White;
setTownColor(dtp, buttondevteam.chat.components.towncolors.admin.TownColorCommand.getTownNameCased(entry.getKey()), entry.getValue(), nc);
} catch (Exception e) {
@ -96,9 +107,11 @@ public class TownColorComponent extends Component implements Listener {
});
registerCommand(new TownColorCommand());
registerCommand(new NationColorCommand());
if (useNationColors().get())
registerCommand(new NationColorCommand());
registerCommand(new buttondevteam.chat.components.towncolors.admin.TownColorCommand());
registerCommand(new buttondevteam.chat.components.towncolors.admin.NationColorCommand());
if (useNationColors().get())
registerCommand(new buttondevteam.chat.components.towncolors.admin.NationColorCommand());
registerCommand(new TCCount());
registerListener(new TownyListener());
registerListener(this);
@ -108,8 +121,9 @@ public class TownColorComponent extends Component implements Listener {
protected void disable() {
getConfig().getConfig().createSection("towncolors", TownColors.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
v -> Arrays.stream(v.getValue()).map(Enum::toString).toArray(String[]::new))));
getConfig().getConfig().createSection("nationcolors", NationColor.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
v -> v.getValue().toString())));
if (useNationColors().get())
getConfig().getConfig().createSection("nationcolors", NationColor.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
v -> v.getValue().toString())));
}
/**
@ -157,18 +171,20 @@ public class TownColorComponent extends Component implements Listener {
len = name.length() / (clrs.length+1);
else
len = name.length() / clrs.length;*/
boolean usenc = component.useNationColors().get();
val nclar = cp.NameColorLocations().get();
int[] ncl = nclar == null ? null : nclar.stream().mapToInt(Integer::intValue).toArray();
if (ncl != null && (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length + 1)) //+1: Nation color
if (ncl != null && (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length + (usenc ? 1 : 0))) //+1: Nation color
ncl = null; // Reset if name length changed
//System.out.println("ncl: "+Arrays.toString(ncl)+" - sum: "+Arrays.stream(ncl).sum()+" - name len: "+name.length());
if (!res.getTown().hasNation()
|| (nc = NationColor.get(res.getTown().getNation().getName().toLowerCase())) == null)
nc = Color.White;
ret.append(anyColoredNamePart.apply(nc, ncl == null ? len : ncl[0])); //Make first color the nation color
if (usenc) {
if (!res.getTown().hasNation()
|| (nc = NationColor.get(res.getTown().getNation().getName().toLowerCase())) == null)
nc = Color.White;
ret.append(anyColoredNamePart.apply(nc, ncl == null ? len : ncl[0])); //Make first color the nation color
}
for (int i = 0; i < clrs.length; i++)
//ret.append(coloredNamePart.apply(ncl == null ? len : (nc==null?ncl[i]:ncl[i+1]), i));
ret.append(coloredNamePart.apply(ncl == null ? len : ncl[i + 1], i));
ret.append(coloredNamePart.apply(ncl == null ? len : (usenc ? ncl[i + 1] : ncl[i]), i));
return ret.toString();
} catch (NotRegisteredException e) {
return nickname;

View file

@ -61,6 +61,7 @@ public class TownyListener implements Listener {
@EventHandler
public void onNationRename(RenameNationEvent event) {
if (!TownColorComponent.getComponent().useNationColors().get()) return;
val clrs = TownColorComponent.NationColor.remove(event.getOldName().toLowerCase());
if (clrs != null)
TownColorComponent.NationColor.put(event.getNation().getName().toLowerCase(), clrs);
@ -68,21 +69,25 @@ public class TownyListener implements Listener {
@EventHandler //Gets called on town load as well
public void onNationJoin(NationAddTownEvent event) {
if (!TownColorComponent.getComponent().useNationColors().get()) return;
updateTownMembers(event.getTown());
}
@EventHandler
public void onNationLeave(NationRemoveTownEvent event) {
if (!TownColorComponent.getComponent().useNationColors().get()) return;
updateTownMembers(event.getTown()); //The town still has it's colours
}
@EventHandler
public void onNationDelete(DeleteNationEvent event) {
if (!TownColorComponent.getComponent().useNationColors().get()) return;
TownColorComponent.NationColor.remove(event.getNationName().toLowerCase());
}
@EventHandler
public void onNationCreate(NewNationEvent event) {
if (!TownColorComponent.getComponent().useNationColors().get()) return;
Player p = Bukkit.getPlayer(event.getNation().getCapital().getMayor().getName());
if (p != null)
p.sendMessage("§6Use /u nationcolor to set a color for the nation.");

View file

@ -51,21 +51,26 @@ public class TownColorCommand extends AdminCommandBase {
clrs[i - 1] = c.get();
}
Color tnc;
try {
tnc = TownColorComponent.NationColor.get(targetTown.getNation().getName().toLowerCase());
} catch (Exception e) {
tnc = null;
}
if (tnc == null) tnc = Color.White; //Default nation color - TODO: Make configurable
boolean usenc = TownColorComponent.getComponent().useNationColors().get();
if (usenc) {
try {
tnc = TownColorComponent.NationColor.get(targetTown.getNation().getName().toLowerCase());
} catch (Exception e) {
tnc = null;
}
if (tnc == null) tnc = Color.White; //Default nation color - TODO: Make configurable
} else tnc = null;
for (Map.Entry<String, Color[]> other : TownColorComponent.TownColors.entrySet()) {
Color nc;
try {
nc = TownColorComponent.NationColor.get(TownyComponent.TU.getTownsMap().get(other.getKey()).getNation().getName().toLowerCase());
} catch (Exception e) { //Too lazy for lots of null-checks and it may throw exceptions anyways
nc = null;
}
if (nc == null) nc = Color.White; //Default nation color
if (nc.getName().equals(tnc.getName())) {
if (usenc) {
try {
nc = TownColorComponent.NationColor.get(TownyComponent.TU.getTownsMap().get(other.getKey()).getNation().getName().toLowerCase());
} catch (Exception e) { //Too lazy for lots of null-checks and it may throw exceptions anyways
nc = null;
}
if (nc == null) nc = Color.White; //Default nation color
} else nc = null;
if (!usenc || nc.getName().equals(tnc.getName())) {
int C = 0;
if (clrs.length == other.getValue().length)
for (int i = 0; i < clrs.length; i++)

View file

@ -22,7 +22,7 @@ import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
public class TownyComponent extends Component {
public class TownyComponent extends Component<PluginMain> {
public static TownyUniverse TU;
private static ArrayList<String> Towns;
private static ArrayList<String> Nations;

View file

@ -1,4 +1,4 @@
name: ButtonChat
name: Thorpe-Chat
main: buttondevteam.chat.PluginMain
version: 4.0
commands: