-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
BuildTools
committed
Feb 27, 2021
1 parent
a09f895
commit d7bb1f3
Showing
11 changed files
with
363 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...et/ddns/xhue/cometals/ArmorStandData.java → ...va/net/ddns/xhue/cometals/EntityData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/net/ddns/xhue/cometals/Utils/CALSCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package net.ddns.xhue.cometals.Utils; | ||
|
||
import net.ddns.xhue.cometals.ALSConfig; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import static net.ddns.xhue.cometals.Utils.Centering.CenteredMessages.sendCenteredMessage; | ||
|
||
|
||
public class CALSCommand implements CommandExecutor { | ||
|
||
private ALSConfig config; | ||
private JavaPlugin plugin; | ||
|
||
public CALSCommand(JavaPlugin plugin, ALSConfig config) { | ||
this.config = config; | ||
this.plugin = plugin; | ||
} | ||
|
||
ColorUtils cu = new ColorUtils(); | ||
|
||
|
||
@Override | ||
public boolean onCommand( CommandSender sender, Command cmd, String commandLabel, String[] args) { | ||
|
||
|
||
String prefix = cu.translateAll(config.getConfig().getString("prefix")); | ||
|
||
if (cmd.getName().equalsIgnoreCase("cometals")) { | ||
if (sender instanceof Player) { | ||
if (sender.hasPermission("cometals.help")) { | ||
Player p = ((Player) sender).getPlayer(); | ||
|
||
assert p != null; | ||
sendCenteredMessage(p, " "); | ||
sendCenteredMessage(p, cu.translateAll("&8&m &8[ #7F00FF:&lComet#FF6000:&lALS &8]&8&m ")); | ||
sendCenteredMessage(p, cu.translateAll( "&6&oThe ultimate solution to those pesky exploit-stands.")); | ||
sendCenteredMessage(p, cu.translateAll( " ")); | ||
sendCenteredMessage(p, cu.translateAll( "&7Version: &d") + plugin.getDescription().getVersion()); | ||
sendCenteredMessage(p, cu.translateAll( "&7Author: &dxHue")); | ||
sendCenteredMessage(p, cu.translateAll( " ")); | ||
sendCenteredMessage(p, cu.translateAll( "&7&nCommands:")); | ||
sendCenteredMessage(p, cu.translateAll( "&d/ca-rl &6- &7Reloads the plugin configuration file.")); | ||
sendCenteredMessage(p, cu.translateAll( " ")); | ||
sendCenteredMessage(p, cu.translateAll( "&d/cometals &6- &7Opens this help page.")); | ||
sendCenteredMessage(p, cu.translateAll( "&8&m ")); | ||
sendCenteredMessage(p, cu.translateAll( " ")); | ||
|
||
|
||
} | ||
else { | ||
sender.sendMessage(prefix + " " + cu.translateAll("#FF0000:&lSorry! &cYou do not have permission to perform that command!")); | ||
return true; | ||
} | ||
} else { | ||
sender.sendMessage(prefix + " " + cu.translateAll("#FF0000:&lSorry! &cYou can only execute this command as a player!")); | ||
return true; | ||
} | ||
return true; | ||
} | ||
return true; | ||
|
||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/net/ddns/xhue/cometals/Utils/Centering/CenteredMessages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package net.ddns.xhue.cometals.Utils.Centering; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.bukkit.entity.Player; | ||
|
||
public class CenteredMessages { | ||
|
||
private final static int CENTER_PX = 154; | ||
|
||
public static void sendCenteredMessage(Player player, String message){ | ||
if(message == null || message.equals("")) player.sendMessage(""); | ||
assert message != null; | ||
message = ChatColor.translateAlternateColorCodes('&', message); | ||
|
||
int messagePxSize = 0; | ||
boolean previousCode = false; | ||
boolean isBold = false; | ||
|
||
for(char c : message.toCharArray()){ | ||
if(c == '§'){ | ||
previousCode = true; | ||
}else if(previousCode){ | ||
previousCode = false; | ||
isBold = c == 'l' || c == 'L'; | ||
}else{ | ||
DefaultFontInfo dFI = DefaultFontInfo.getDefaultFontInfo(c); | ||
messagePxSize += isBold ? dFI.getBoldLength() : dFI.getLength(); | ||
messagePxSize++; | ||
} | ||
} | ||
|
||
int halvedMessageSize = messagePxSize / 2; | ||
int toCompensate = CENTER_PX - halvedMessageSize; | ||
int spaceLength = DefaultFontInfo.SPACE.getLength() + 1; | ||
int compensated = 0; | ||
StringBuilder sb = new StringBuilder(); | ||
while(compensated < toCompensate){ | ||
sb.append(" "); | ||
compensated += spaceLength; | ||
} | ||
player.sendMessage(sb.toString() + message); | ||
} | ||
|
||
public static String sendCenteredString(String message){ | ||
String[] lines = ChatColor.translateAlternateColorCodes('&', message).split("\n", 40); | ||
StringBuilder returnMessage = new StringBuilder(); | ||
|
||
|
||
for (String line : lines) { | ||
int messagePxSize = 0; | ||
boolean previousCode = false; | ||
boolean isBold = false; | ||
|
||
for (char c : line.toCharArray()) { | ||
if (c == '§') { | ||
previousCode = true; | ||
} else if (previousCode) { | ||
previousCode = false; | ||
isBold = c == 'l'; | ||
} else { | ||
DefaultFontInfo dFI = DefaultFontInfo.getDefaultFontInfo(c); | ||
messagePxSize = isBold ? messagePxSize + dFI.getBoldLength() : messagePxSize + dFI.getLength(); | ||
messagePxSize++; | ||
} | ||
} | ||
int toCompensate = CENTER_PX - messagePxSize / 2; | ||
int spaceLength = DefaultFontInfo.SPACE.getLength() + 1; | ||
int compensated = 0; | ||
StringBuilder sb = new StringBuilder(); | ||
while(compensated < toCompensate){ | ||
sb.append(" "); | ||
compensated += spaceLength; | ||
} | ||
returnMessage.append(sb.toString()).append(line).append("\n"); | ||
} | ||
|
||
return returnMessage.toString(); | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
src/main/java/net/ddns/xhue/cometals/Utils/Centering/DefaultFontInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package net.ddns.xhue.cometals.Utils.Centering; | ||
|
||
public enum DefaultFontInfo { | ||
|
||
A('A', 5), | ||
a('a', 5), | ||
B('B', 5), | ||
b('b', 5), | ||
C('C', 5), | ||
c('c', 5), | ||
D('D', 5), | ||
d('d', 5), | ||
E('E', 5), | ||
e('e', 5), | ||
F('F', 5), | ||
f('f', 4), | ||
G('G', 5), | ||
g('g', 5), | ||
H('H', 5), | ||
h('h', 5), | ||
I('I', 3), | ||
i('i', 1), | ||
J('J', 5), | ||
j('j', 5), | ||
K('K', 5), | ||
k('k', 4), | ||
L('L', 5), | ||
l('l', 1), | ||
M('M', 5), | ||
m('m', 5), | ||
N('N', 5), | ||
n('n', 5), | ||
O('O', 5), | ||
o('o', 5), | ||
P('P', 5), | ||
p('p', 5), | ||
Q('Q', 5), | ||
q('q', 5), | ||
R('R', 5), | ||
r('r', 5), | ||
S('S', 5), | ||
s('s', 5), | ||
T('T', 5), | ||
t('t', 4), | ||
U('U', 5), | ||
u('u', 5), | ||
V('V', 5), | ||
v('v', 5), | ||
W('W', 5), | ||
w('w', 5), | ||
X('X', 5), | ||
x('x', 5), | ||
Y('Y', 5), | ||
y('y', 5), | ||
Z('Z', 5), | ||
z('z', 5), | ||
NUM_1('1', 5), | ||
NUM_2('2', 5), | ||
NUM_3('3', 5), | ||
NUM_4('4', 5), | ||
NUM_5('5', 5), | ||
NUM_6('6', 5), | ||
NUM_7('7', 5), | ||
NUM_8('8', 5), | ||
NUM_9('9', 5), | ||
NUM_0('0', 5), | ||
EXCLAMATION_POINT('!', 1), | ||
AT_SYMBOL('@', 6), | ||
NUM_SIGN('#', 5), | ||
DOLLAR_SIGN('$', 5), | ||
PERCENT('%', 5), | ||
UP_ARROW('^', 5), | ||
AMPERSAND('&', 5), | ||
ASTERISK('*', 5), | ||
LEFT_PARENTHESIS('(', 4), | ||
RIGHT_PERENTHESIS(')', 4), | ||
MINUS('-', 5), | ||
UNDERSCORE('_', 5), | ||
PLUS_SIGN('+', 5), | ||
EQUALS_SIGN('=', 5), | ||
LEFT_CURL_BRACE('{', 4), | ||
RIGHT_CURL_BRACE('}', 4), | ||
LEFT_BRACKET('[', 3), | ||
RIGHT_BRACKET(']', 3), | ||
COLON(':', 1), | ||
SEMI_COLON(';', 1), | ||
DOUBLE_QUOTE('"', 3), | ||
SINGLE_QUOTE('\'', 1), | ||
LEFT_ARROW('<', 4), | ||
RIGHT_ARROW('>', 4), | ||
QUESTION_MARK('?', 5), | ||
SLASH('/', 5), | ||
BACK_SLASH('\\', 5), | ||
LINE('|', 1), | ||
TILDE('~', 5), | ||
TICK('`', 2), | ||
PERIOD('.', 1), | ||
COMMA(',', 1), | ||
SPACE(' ', 3), | ||
DEFAULT('a', 4); | ||
|
||
private char character; | ||
private int length; | ||
|
||
DefaultFontInfo(char character, int length) { | ||
this.character = character; | ||
this.length = length; | ||
} | ||
|
||
public char getCharacter(){ | ||
return this.character; | ||
} | ||
|
||
public int getLength(){ | ||
return this.length; | ||
} | ||
|
||
public int getBoldLength(){ | ||
if(this == DefaultFontInfo.SPACE) return this.getLength(); | ||
return this.length + 1; | ||
} | ||
|
||
public static DefaultFontInfo getDefaultFontInfo(char c){ | ||
for(DefaultFontInfo dFI : DefaultFontInfo.values()){ | ||
if(dFI.getCharacter() == c) return dFI; | ||
} | ||
return DefaultFontInfo.DEFAULT; | ||
} | ||
} |
Oops, something went wrong.