Merge branch 'dev'
This commit is contained in:
commit
b4de61adf8
5 changed files with 101 additions and 17 deletions
|
@ -2,10 +2,10 @@ cache:
|
|||
directories:
|
||||
- $HOME/.m2/repository/org/
|
||||
before_install: | # Wget BuildTools and run if cached folder not found
|
||||
if [ ! -d "$HOME/.m2/repository/org/spigotmc/spigot/1.12.1-R0.1-SNAPSHOT" ]; then
|
||||
if [ ! -d "$HOME/.m2/repository/org/spigotmc/spigot/1.12.2-R0.1-SNAPSHOT" ]; then
|
||||
wget -O BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
|
||||
# grep so that download counts don't appear in log files
|
||||
java -jar BuildTools.jar --rev 1.12.1 | grep -vE "[^/ ]*/[^/ ]*\s*KB\s*$" | grep -v "^\s*$"
|
||||
java -jar BuildTools.jar --rev 1.12.2 | grep -vE "[^/ ]*/[^/ ]*\s*KB\s*$" | grep -v "^\s*$"
|
||||
fi
|
||||
language: java
|
||||
jdk:
|
||||
|
|
|
@ -42,6 +42,10 @@ public class ChatPlayer extends TBMCPlayerBase {
|
|||
return data(false);
|
||||
}
|
||||
|
||||
public PlayerData<ArrayList<Integer>> NameColorLocations() { // No byte[], no TIntArrayList
|
||||
return data(null);
|
||||
}
|
||||
|
||||
public Location SavedLocation;
|
||||
public boolean Working;
|
||||
// public int Tables = 10;
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package buttondevteam.chat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -257,15 +259,25 @@ public class ChatProcessing {
|
|||
val clrs = PluginMain.TownColors.get(res.getTown().getName().toLowerCase());
|
||||
if (clrs == null)
|
||||
return player.getDisplayName();
|
||||
String ret = "";
|
||||
StringBuilder ret = new StringBuilder();
|
||||
String name = ChatColor.stripColor(player.getDisplayName());
|
||||
AtomicInteger prevlen = new AtomicInteger();
|
||||
BiFunction<Integer, Integer, String> coloredNamePart = (len, i) -> "§"
|
||||
+ 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(prevlen.get())
|
||||
: name.substring(prevlen.get(), prevlen.addAndGet(len)));
|
||||
int len = name.length() / clrs.length;
|
||||
// val bounds = new int[clrs.length - 1];
|
||||
// for (int i = 0; i < clrs.length; i++)
|
||||
val nclar = ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations().get();
|
||||
int[] ncl = nclar == null ? null : nclar.stream().mapToInt(Integer::intValue).toArray();
|
||||
if (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length)
|
||||
ncl = null; // Reset if name length changed
|
||||
if (name.charAt(0) == '~') { // Ignore ~ in nicknames
|
||||
prevlen.incrementAndGet();
|
||||
ret.append("~");
|
||||
}
|
||||
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;
|
||||
ret.append(coloredNamePart.apply(ncl == null ? len : ncl[i], i));
|
||||
return ret.toString();
|
||||
} catch (NotRegisteredException e) {
|
||||
return player.getDisplayName();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||
|
||||
@OptionallyPlayerCommandClass(playerOnly = true)
|
||||
@CommandClass
|
||||
public class NColorCommand extends UCommandBase {
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { //
|
||||
"§6---- Name color ----", //
|
||||
"This command allows you to set how the town colors look on your name.", //
|
||||
"To use this command, you need to be in a town which has town colors set.", //
|
||||
"Use a vertical line as a separator between the colors.", //
|
||||
"Example: /u ncolor Norbi|Peti --> §6Norbi§ePeti" //
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(Player player, String alias, String[] args) {
|
||||
Resident res;
|
||||
Town town;
|
||||
try {
|
||||
if ((res = PluginMain.TU.getResidentMap().get(player.getName().toLowerCase())) == null || !res.hasTown()
|
||||
|| (town = res.getTown()) == null) {
|
||||
player.sendMessage("§cYou need to be in a town.");
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
player.sendMessage("§cYou need to be in a town. (" + e + ")");
|
||||
return true;
|
||||
}
|
||||
if (args.length == 0)
|
||||
return false;
|
||||
if (!args[0].replace("|", "").equalsIgnoreCase(ChatColor.stripColor(player.getDisplayName()))) {
|
||||
player.sendMessage("§cThe name you gave doesn't match your name. Make sure to use "
|
||||
+ ChatColor.stripColor(player.getDisplayName()) + "§c with added vertical lines (|).");
|
||||
return true;
|
||||
}
|
||||
String[] nameparts = args[0].split("\\|");
|
||||
Color[] towncolors = PluginMain.TownColors.get(town.getName().toLowerCase());
|
||||
if (towncolors == null) {
|
||||
player.sendMessage("§cYour town doesn't have a color set. The town mayor can set it using /u towncolor.");
|
||||
return true;
|
||||
}
|
||||
if (nameparts.length < towncolors.length) {
|
||||
player.sendMessage("§cYou need more vertical lines (|) in your name.");
|
||||
return true;
|
||||
}
|
||||
if (nameparts.length > towncolors.length * 2) {
|
||||
player.sendMessage("§cYou have waay too many vertical lines (|) in your name.");
|
||||
return true;
|
||||
}
|
||||
if (nameparts.length > towncolors.length) {
|
||||
player.sendMessage("§cYou have too many vertical lines (|) in your name.");
|
||||
return true;
|
||||
}
|
||||
ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations()
|
||||
.set(new ArrayList<>(Arrays.stream(nameparts).map(np -> np.length()).collect(Collectors.toList()))); // No byte[], no TIntArrayList
|
||||
player.sendMessage("§bName colors set.");
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,22 +1,13 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.dynmap.towny.DynmapTownyPlugin;
|
||||
|
||||
import com.mysql.fabric.xmlrpc.base.Array;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||
import lombok.val;
|
||||
|
||||
@CommandClass // TODO: /u u when annotation not present
|
||||
@OptionallyPlayerCommandClass(playerOnly = true)
|
||||
|
|
Loading…
Reference in a new issue