Made /u ncolor, needs further testing
This commit is contained in:
parent
06ea519987
commit
cee69dc55b
5 changed files with 95 additions and 15 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:
|
||||
|
|
|
@ -11,6 +11,7 @@ import buttondevteam.lib.player.EnumPlayerData;
|
|||
import buttondevteam.lib.player.PlayerClass;
|
||||
import buttondevteam.lib.player.PlayerData;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
|
||||
@PlayerClass(pluginname = "Button1Chat")
|
||||
public class ChatPlayer extends TBMCPlayerBase {
|
||||
|
@ -42,6 +43,10 @@ public class ChatPlayer extends TBMCPlayerBase {
|
|||
return data(false);
|
||||
}
|
||||
|
||||
public PlayerData<TIntArrayList> NameColorLocations() { // No byte[]
|
||||
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;
|
||||
|
@ -259,12 +261,18 @@ public class ChatProcessing {
|
|||
return player.getDisplayName();
|
||||
String ret = "";
|
||||
String name = ChatColor.stripColor(player.getDisplayName());
|
||||
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(len * i) : name.substring(len * i, len * i + len));
|
||||
int len = name.length() / clrs.length;
|
||||
// val bounds = new int[clrs.length - 1];
|
||||
// for (int i = 0; i < clrs.length; i++)
|
||||
int[] ncl = ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations().get()
|
||||
.toArray();
|
||||
if (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length) {
|
||||
System.out.println("Name length changed: " + Arrays.stream(ncl).sum() + " -> " + name.length());
|
||||
ncl = null; // Reset if name length changed
|
||||
}
|
||||
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));
|
||||
ret += coloredNamePart.apply(ncl == null ? len : ncl[i], i);
|
||||
return ret;
|
||||
} catch (NotRegisteredException e) {
|
||||
return player.getDisplayName();
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
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;
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
|
||||
@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(TIntArrayList.wrap(Arrays.stream(nameparts).mapToInt(np -> np.length()).toArray())); // No byte[]
|
||||
player.sendMessage("§bName colors set."); // TODO: ArrayList is what it becomes I think
|
||||
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