Added town colors to chat (still need for Dynmap)

This commit is contained in:
Norbi Peti 2017-09-24 02:37:27 +02:00
parent e0459fa36f
commit 9abcde610e
5 changed files with 320 additions and 228 deletions

447
.gitignore vendored
View file

@ -1,223 +1,224 @@
#################
## Eclipse
#################
*.pydevproject
.metadata/
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
target/
.project
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.Publish.xml
*.pubxml
*.publishproj
# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
#############
## Windows detritus
#############
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac crap
.DS_Store
#############
## Python
#############
*.py[cod]
# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg
.metadata/*
TheButtonAutoFlair/out/artifacts/Autoflair/Autoflair.jar
*.iml
*.name
.idea/compiler.xml
*.xml
#################
## Eclipse
#################
*.pydevproject
.metadata/
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
target/
.project
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.Publish.xml
*.pubxml
*.publishproj
# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
#############
## Windows detritus
#############
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac crap
.DS_Store
#############
## Python
#############
*.py[cod]
# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg
.metadata/*
TheButtonAutoFlair/out/artifacts/Autoflair/Autoflair.jar
*.iml
*.name
.idea/compiler.xml
*.xml
/.apt_generated/

View file

@ -12,7 +12,7 @@ import buttondevteam.lib.player.PlayerClass;
import buttondevteam.lib.player.PlayerData;
import buttondevteam.lib.player.TBMCPlayerBase;
@PlayerClass(pluginname = "ButtonChat")
@PlayerClass(pluginname = "Button1Chat")
public class ChatPlayer extends TBMCPlayerBase {
public PlayerData<String> UserName() {
return data(null);

View file

@ -7,6 +7,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -16,6 +17,8 @@ import com.earth2me.essentials.Essentials;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import buttondevteam.chat.commands.UnlolCommand;
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
import buttondevteam.chat.formatting.*;
@ -169,8 +172,8 @@ public class ChatProcessing {
sender.sendMessage("§cAn error occured while sending the message.");
return true;
}
PluginMain.Instance.getServer().getConsoleSender().sendMessage(String.format("%s <%s> %s", channelidentifier,
(player != null ? player.getDisplayName() : sender.getName()), message));
PluginMain.Instance.getServer().getConsoleSender()
.sendMessage(String.format("%s <%s§r> %s", channelidentifier, getSenderName(sender, player), message));
DebugCommand.SendDebugMessage(
"-- Full ChatProcessing time: " + (System.nanoTime() - processstart) / 1000000f + " ms");
DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms");
@ -199,8 +202,8 @@ public class ChatProcessing {
json.addExtra(new TellrawPart(" <"));
json.addExtra(
new TellrawPart(
(player != null ? player.getDisplayName()
: sender.getName()))
getSenderName(
sender, player))
.setHoverEvent(
TellrawEvent
.create(TellrawEvent.HoverAction.SHOW_TEXT,
@ -244,6 +247,30 @@ public class ChatProcessing {
return json;
}
private static String getSenderName(CommandSender sender, Player player) {
if (player == null)
return sender.getName();
val res = PluginMain.TU.getResidentMap().get(player.getName().toLowerCase());
if (res == null || !res.hasTown())
return player.getDisplayName();
try {
val clrs = PluginMain.TownColors.get(res.getTown().getName().toLowerCase());
if (clrs == null)
return player.getDisplayName();
String ret = "";
String name = ChatColor.stripColor(player.getDisplayName());
int len = name.length() / clrs.length;
// val bounds = new int[clrs.length - 1];
// for (int i = 0; i < clrs.length; i++)
for (int i = 0; i < clrs.length; i++)
ret += "§" + Integer.toHexString(clrs[i].ordinal()) // 'Odds' are the last character is chopped off so we make sure to include all chars at the end
+ (i + 1 == clrs.length ? name.substring(len * i) : name.substring(len * i, len * i + len));
return ret;
} catch (NotRegisteredException e) {
return player.getDisplayName();
}
}
static String getChannelID(Channel channel, CommandSender sender) {
final String channelidentifier = ("[" + (sender instanceof IDiscordSender ? "d|" : "") + channel.DisplayName)
+ "]";

View file

@ -23,6 +23,8 @@ import buttondevteam.lib.chat.Color;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.chat.Channel.RecipientTestResult;
import buttondevteam.lib.player.TBMCPlayerBase;
import lombok.val;
import com.earth2me.essentials.Essentials;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
@ -42,11 +44,16 @@ import java.net.URLConnection;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.stream.Collectors;
public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
// A user, which flair isn't obtainable:
@ -89,6 +96,8 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
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
TownColors.keySet().removeIf(t -> !TU.getTownsMap().containsKey(t.toLowerCase())); // Removes town colors for deleted/renamed towns
TBMCChatAPI.RegisterChatChannel(
TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false)));
TBMCChatAPI.RegisterChatChannel(
@ -253,7 +262,9 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
public static ArrayList<String> AnnounceMessages = new ArrayList<>();
public static int AnnounceTime = 15 * 60 * 1000;
public static Map<String, Color[]> TownColors = new HashMap<>();
@SuppressWarnings("unchecked")
public static void LoadFiles() {
PluginMain.Instance.getLogger().info("Loading files...");
try {
@ -266,6 +277,11 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
AnnounceTime = yc.getInt("announcetime");
AnnounceMessages.addAll(yc.getStringList("announcements"));
PlayerListener.AlphaDeaths = yc.getInt("alphadeaths");
val cs = yc.getConfigurationSection("towncolors");
if (cs != null)
TownColors.putAll(cs.getValues(true).entrySet().stream()
.collect(Collectors.toMap(k -> k.getKey(), v -> ((List<String>) v.getValue()).stream()
.map(c -> Color.valueOf(c)).toArray(Color[]::new))));
}
PluginMain.Instance.getLogger().info("Loaded files!");
} catch (Exception e) {
@ -283,6 +299,8 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
yc.set("announcetime", AnnounceTime);
yc.set("announcements", AnnounceMessages);
yc.set("alphadeaths", PlayerListener.AlphaDeaths);
yc.createSection("towncolors", TownColors.entrySet().stream().collect(Collectors.toMap(k -> k.getKey(),
v -> Arrays.stream(v.getValue()).map(c -> c.toString()).toArray(String[]::new))));
yc.save(file);
PluginMain.Instance.getLogger().info("Saved files!");
} catch (Exception e) {

View file

@ -0,0 +1,46 @@
package buttondevteam.chat.commands.ucmds.admin;
import java.util.Arrays;
import org.bukkit.command.CommandSender;
import buttondevteam.chat.PluginMain;
import buttondevteam.lib.chat.Color;
import lombok.val;
public class TownColorCommand extends AdminCommandBase {
@Override
public String GetHelpText(String alias)[] { // TODO: Command path aliases
return new String[] { //
"§6---- Town Color ----", //
"This command allows setting a color for a town.", //
"The town will be shown with this color on Dynmap and all players in the town will appear in chat with these colors.", //
"The colors will split the name evenly.", //
"Usage: /" + GetCommandPath() + " <town> <colorname1> [colorname2...]", //
"Example: /" + GetCommandPath() + " Alderon blue gray" //
};
}
@Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
if (args.length < 2)
return false;
if (!PluginMain.TU.getTownsMap().containsKey(args[0])) {
sender.sendMessage("§cThe town '" + args[0] + "' cannot be found.");
return true;
}
val clrs = new Color[args.length - 1];
for (int i = 1; i < args.length; i++) {
val ii = i;
val c = Arrays.stream(Color.values()).filter(cc -> cc.getName().equalsIgnoreCase(args[ii])).findAny();
if (!c.isPresent()) {
sender.sendMessage("§cThe color '" + args[i] + "' cannot be found.");
return true;
}
clrs[i - 1] = c.get();
}
PluginMain.TownColors.put(args[0], clrs);
sender.sendMessage("§bColor(s) set.");
return true;
}
}