CoreProtect v20.0 release
This commit is contained in:
parent
415d7b323a
commit
48ef18e2c8
173 changed files with 25072 additions and 1 deletions
75
src/main/java/net/coreprotect/spigot/SpigotAdapter.java
Normal file
75
src/main/java/net/coreprotect/spigot/SpigotAdapter.java
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
package net.coreprotect.spigot;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import net.coreprotect.bukkit.BukkitAdapter;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.utility.Chat;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class SpigotAdapter implements SpigotInterface {
|
||||
|
||||
public static SpigotInterface ADAPTER;
|
||||
public static final int SPIGOT_UNAVAILABLE = 0;
|
||||
public static final int SPIGOT_v1_13 = BukkitAdapter.BUKKIT_v1_13;
|
||||
public static final int SPIGOT_v1_14 = BukkitAdapter.BUKKIT_v1_14;
|
||||
public static final int SPIGOT_v1_15 = BukkitAdapter.BUKKIT_v1_15;
|
||||
public static final int SPIGOT_v1_16 = BukkitAdapter.BUKKIT_v1_16;
|
||||
public static final int SPIGOT_v1_17 = BukkitAdapter.BUKKIT_v1_17;
|
||||
|
||||
public static void loadAdapter() {
|
||||
int SPIGOT_VERSION = ConfigHandler.SERVER_VERSION;
|
||||
if (!ConfigHandler.isSpigot) {
|
||||
SPIGOT_VERSION = SPIGOT_UNAVAILABLE;
|
||||
}
|
||||
|
||||
switch (SPIGOT_VERSION) {
|
||||
case SPIGOT_UNAVAILABLE:
|
||||
SpigotAdapter.ADAPTER = new SpigotAdapter();
|
||||
break;
|
||||
case SPIGOT_v1_13:
|
||||
case SPIGOT_v1_14:
|
||||
case SPIGOT_v1_15:
|
||||
SpigotAdapter.ADAPTER = new SpigotHandler();
|
||||
break;
|
||||
case SPIGOT_v1_16:
|
||||
case SPIGOT_v1_17:
|
||||
default:
|
||||
SpigotAdapter.ADAPTER = new Spigot_v1_16();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHoverComponent(Object message, String[] data) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendComponent(CommandSender sender, String string, String bypass) {
|
||||
StringBuilder message = new StringBuilder();
|
||||
|
||||
Matcher matcher = Util.tagParser.matcher(string);
|
||||
while (matcher.find()) {
|
||||
String value = matcher.group(1);
|
||||
if (value != null) {
|
||||
String[] data = value.split("\\|", 3);
|
||||
if (data[0].equals(Chat.COMPONENT_COMMAND) || data[0].equals(Chat.COMPONENT_POPUP)) {
|
||||
message.append(data[2]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
message.append(matcher.group(2));
|
||||
}
|
||||
}
|
||||
|
||||
if (bypass != null) {
|
||||
message.append(bypass);
|
||||
}
|
||||
|
||||
Chat.sendMessage(sender, message.toString());
|
||||
}
|
||||
|
||||
}
|
||||
82
src/main/java/net/coreprotect/spigot/SpigotHandler.java
Normal file
82
src/main/java/net/coreprotect/spigot/SpigotHandler.java
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
package net.coreprotect.spigot;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
|
||||
import net.coreprotect.utility.Chat;
|
||||
import net.coreprotect.utility.Util;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class SpigotHandler extends SpigotAdapter implements SpigotInterface {
|
||||
|
||||
public static ChatColor DARK_AQUA = ChatColor.DARK_AQUA;
|
||||
|
||||
@Override
|
||||
public void setHoverComponent(Object message, String[] data) {
|
||||
((TextComponent) message).addExtra(data[2]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendComponent(CommandSender sender, String string, String bypass) {
|
||||
TextComponent message = new TextComponent();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
string = string.replace(SpigotHandler.DARK_AQUA.toString(), ChatColor.DARK_AQUA.toString());
|
||||
}
|
||||
|
||||
Matcher matcher = Util.tagParser.matcher(string);
|
||||
while (matcher.find()) {
|
||||
String value = matcher.group(1);
|
||||
if (value != null) {
|
||||
if (builder.length() > 0) {
|
||||
addBuilder(message, builder);
|
||||
}
|
||||
|
||||
String[] data = value.split("\\|", 3);
|
||||
if (data[0].equals(Chat.COMPONENT_COMMAND)) {
|
||||
TextComponent component = new TextComponent(TextComponent.fromLegacyText(data[2]));
|
||||
component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, data[1]));
|
||||
message.addExtra(component);
|
||||
}
|
||||
else if (data[0].equals(Chat.COMPONENT_POPUP)) {
|
||||
SpigotAdapter.ADAPTER.setHoverComponent(message, data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
builder.append(matcher.group(2));
|
||||
}
|
||||
}
|
||||
|
||||
if (builder.length() > 0) {
|
||||
addBuilder(message, builder);
|
||||
}
|
||||
|
||||
if (bypass != null) {
|
||||
message.addExtra(bypass);
|
||||
}
|
||||
|
||||
sender.spigot().sendMessage(message);
|
||||
}
|
||||
|
||||
private static void addBuilder(TextComponent message, StringBuilder builder) {
|
||||
String[] splitBuilder = builder.toString().split(SpigotHandler.DARK_AQUA.toString());
|
||||
for (int i = 0; i < splitBuilder.length; i++) {
|
||||
if (i > 0) {
|
||||
TextComponent textComponent = new TextComponent(splitBuilder[i]);
|
||||
textComponent.setColor(SpigotHandler.DARK_AQUA);
|
||||
message.addExtra(textComponent);
|
||||
}
|
||||
else {
|
||||
message.addExtra(splitBuilder[i]);
|
||||
}
|
||||
}
|
||||
|
||||
builder.setLength(0);
|
||||
}
|
||||
|
||||
}
|
||||
11
src/main/java/net/coreprotect/spigot/SpigotInterface.java
Normal file
11
src/main/java/net/coreprotect/spigot/SpigotInterface.java
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package net.coreprotect.spigot;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public interface SpigotInterface {
|
||||
|
||||
public void setHoverComponent(Object message, String[] data);
|
||||
|
||||
public void sendComponent(CommandSender sender, String string, String bypass);
|
||||
|
||||
}
|
||||
34
src/main/java/net/coreprotect/spigot/Spigot_v1_16.java
Normal file
34
src/main/java/net/coreprotect/spigot/Spigot_v1_16.java
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package net.coreprotect.spigot;
|
||||
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.utility.Color;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
|
||||
public class Spigot_v1_16 extends SpigotHandler implements SpigotInterface {
|
||||
|
||||
public Spigot_v1_16() {
|
||||
SpigotHandler.DARK_AQUA = ChatColor.of("#31b0e8");
|
||||
Color.DARK_AQUA = SpigotHandler.DARK_AQUA.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHoverComponent(Object message, String[] data) {
|
||||
try {
|
||||
if (Config.getGlobal().HOVER_EVENTS) {
|
||||
TextComponent component = new TextComponent(TextComponent.fromLegacyText(data[2]));
|
||||
component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(TextComponent.fromLegacyText(data[1]))));
|
||||
((TextComponent) message).addExtra(component);
|
||||
}
|
||||
else {
|
||||
super.setHoverComponent(message, data);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue