mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2025-02-07 07:52:08 +01:00
refactor: java 8 compat (#516)
This commit is contained in:
parent
c3708f1d16
commit
dfacc7fbf3
@ -48,8 +48,8 @@ allprojects {
|
||||
}
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_16
|
||||
targetCompatibility = JavaVersion.VERSION_16
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
ext.branch = rootProject.ext.branch
|
||||
ext.snapshotName = rootProject.ext.snapshotName
|
||||
|
@ -32,7 +32,8 @@ public class EventListener implements Listener {
|
||||
if (!(event.getSender() instanceof Server))
|
||||
return;
|
||||
|
||||
if (event.getReceiver() instanceof ProxiedPlayer player) {
|
||||
if (event.getReceiver() instanceof ProxiedPlayer) {
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
||||
this.proxyCore.incomingMessage(
|
||||
new BungeeProxyPlayerContainer(player), event.getData());
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.proxycore.connector.container.ProxyContainer;
|
||||
import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
public class BungeeProxyContainer implements ProxyContainer {
|
||||
private final AdvancedPortalsBungeePlugin plugin;
|
||||
@ -17,7 +19,8 @@ public class BungeeProxyContainer implements ProxyContainer {
|
||||
public void invokeCommand(ProxyPlayerContainer proxyPlayer,
|
||||
String command) {
|
||||
// Should never not be true but just to be safe
|
||||
if (proxyPlayer instanceof BungeeProxyPlayerContainer playerContainer) {
|
||||
if (proxyPlayer instanceof BungeeProxyPlayerContainer) {
|
||||
BungeeProxyPlayerContainer playerContainer = (BungeeProxyPlayerContainer) proxyPlayer;
|
||||
plugin.getProxy().getPluginManager().dispatchCommand(
|
||||
playerContainer.getPlayer(), command);
|
||||
}
|
||||
@ -27,9 +30,10 @@ public class BungeeProxyContainer implements ProxyContainer {
|
||||
public void transferPlayer(ProxyPlayerContainer proxyPlayer,
|
||||
String serverName) {
|
||||
// Should never not be true but just to be safe
|
||||
if (proxyPlayer instanceof BungeeProxyPlayerContainer playerContainer) {
|
||||
var serverInfo = plugin.getProxy().getServerInfo(serverName);
|
||||
var player = playerContainer.getPlayer();
|
||||
if (proxyPlayer instanceof BungeeProxyPlayerContainer) {
|
||||
BungeeProxyPlayerContainer playerContainer = (BungeeProxyPlayerContainer) proxyPlayer;
|
||||
ServerInfo serverInfo = plugin.getProxy().getServerInfo(serverName);
|
||||
ProxiedPlayer player = playerContainer.getPlayer();
|
||||
if (serverInfo == null) {
|
||||
player.sendMessage(new TextComponent(
|
||||
Lang.convertColors("&cCould not find server: &e")
|
||||
|
@ -7,6 +7,7 @@ import com.sekwah.advancedportals.core.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.commands.subcommands.desti.*;
|
||||
import com.sekwah.advancedportals.core.commands.subcommands.portal.*;
|
||||
import com.sekwah.advancedportals.core.connector.commands.CommandRegister;
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
|
||||
import com.sekwah.advancedportals.core.module.AdvancedPortalsModule;
|
||||
import com.sekwah.advancedportals.core.permissions.Permissions;
|
||||
@ -217,7 +218,7 @@ public class AdvancedPortalsCore {
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
for (var playerContainer : this.serverContainer.getPlayers()) {
|
||||
for (PlayerContainer playerContainer : this.serverContainer.getPlayers()) {
|
||||
playerDataRepository.playerLeave(playerContainer);
|
||||
}
|
||||
this.infoLogger.info(Lang.translate("logger.plugindisable"));
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.sekwah.advancedportals.core;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.connector.containers.EntityContainer;
|
||||
@ -11,6 +12,7 @@ import com.sekwah.advancedportals.core.network.ServerDestiPacket;
|
||||
import com.sekwah.advancedportals.core.permissions.Permissions;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerData;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.services.DestinationServices;
|
||||
import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
||||
@ -64,12 +66,13 @@ public class CoreListeners {
|
||||
|
||||
public void incomingMessage(PlayerContainer player, String channel,
|
||||
byte[] message) {
|
||||
var buffer = ByteStreams.newDataInput(message);
|
||||
var messageType = buffer.readUTF();
|
||||
ByteArrayDataInput buffer = ByteStreams.newDataInput(message);
|
||||
String messageType = buffer.readUTF();
|
||||
|
||||
switch (messageType) {
|
||||
case ProxyMessages.SERVER_DESTI -> {
|
||||
var serverDestiPacket = ServerDestiPacket.decode(buffer);
|
||||
case ProxyMessages.SERVER_DESTI:
|
||||
{
|
||||
ServerDestiPacket serverDestiPacket = ServerDestiPacket.decode(buffer);
|
||||
this.destinationServices.teleportToDestination(serverDestiPacket.getDestination(), player, true);
|
||||
}
|
||||
}
|
||||
@ -129,7 +132,7 @@ public class CoreListeners {
|
||||
if (itemInHandName.equals("\u00A75Portal Block Placer")) {
|
||||
world.setBlock(blockPos, "NETHER_PORTAL");
|
||||
for (Direction direction : Direction.values()) {
|
||||
var checkLoc = new BlockLocation(blockPos, direction);
|
||||
BlockLocation checkLoc = new BlockLocation(blockPos, direction);
|
||||
if (world.getBlock(checkLoc).equals("NETHER_PORTAL")) {
|
||||
world.setBlockAxis(blockPos,
|
||||
world.getBlockAxis(checkLoc));
|
||||
@ -217,9 +220,10 @@ public boolean preventEntityCombust(EntityContainer entity) {
|
||||
}
|
||||
|
||||
public boolean entityPortalEvent(EntityContainer entity) {
|
||||
var pos = entity.getBlockLoc();
|
||||
if (entity instanceof PlayerContainer player) {
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
BlockLocation pos = entity.getBlockLoc();
|
||||
if (entity instanceof PlayerContainer ) {
|
||||
PlayerContainer player = (PlayerContainer) entity;
|
||||
PlayerData playerData = playerDataServices.getPlayerData(player);
|
||||
if (playerData.getPortalBlockCooldown()) {
|
||||
return false;
|
||||
}
|
||||
@ -231,13 +235,13 @@ public boolean entityPortalEvent(EntityContainer entity) {
|
||||
}
|
||||
|
||||
public boolean playerPortalEvent(PlayerContainer player, PlayerLocation toLoc) {
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
PlayerData playerData = playerDataServices.getPlayerData(player);
|
||||
|
||||
if (playerData.getPortalBlockCooldown()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var portalResult = this.portalServices.checkPortalActivation(
|
||||
PortalServices.PortalActivationResult portalResult = this.portalServices.checkPortalActivation(
|
||||
player, toLoc, TriggerType.PORTAL);
|
||||
|
||||
if (portalResult != PortalServices.PortalActivationResult.NOT_IN_PORTAL) {
|
||||
@ -246,10 +250,10 @@ public boolean playerPortalEvent(PlayerContainer player, PlayerLocation toLoc) {
|
||||
|
||||
// Extra checks to prevent the player from being teleported by touching a
|
||||
// portal but not having their body fully in the portal
|
||||
var pos = player.getBlockLoc();
|
||||
BlockLocation pos = player.getBlockLoc();
|
||||
|
||||
var feetInPortal = portalServices.inPortalRegion(pos, 1);
|
||||
var headInPortal =
|
||||
boolean feetInPortal = portalServices.inPortalRegion(pos, 1);
|
||||
boolean headInPortal =
|
||||
portalServices.inPortalRegion(pos.addY((int) player.getHeight()), 1);
|
||||
|
||||
return !(feetInPortal || headInPortal);
|
||||
|
@ -36,7 +36,8 @@ public class CommandWithSubCommands implements CommandTemplate {
|
||||
boolean result =
|
||||
this.subCommandRegistry.registerSubCommand(arg, subCommand)
|
||||
|| hasRegistered;
|
||||
if (subCommand instanceof SubCommand.SubCommandOnInit init) {
|
||||
if (subCommand instanceof SubCommand.SubCommandOnInit ) {
|
||||
SubCommand.SubCommandOnInit init = (SubCommand.SubCommandOnInit) subCommand;
|
||||
init.registered();
|
||||
}
|
||||
return result;
|
||||
@ -86,7 +87,7 @@ public class CommandWithSubCommands implements CommandTemplate {
|
||||
if (this.subCommandRegistry.isArgRegistered(
|
||||
subCommand)) {
|
||||
sender.sendMessage("");
|
||||
var helpTitle = Lang.centeredTitle(
|
||||
String helpTitle = Lang.centeredTitle(
|
||||
Lang.translateInsertVariables(
|
||||
"command.help.subcommandheader", command,
|
||||
subCommand));
|
||||
@ -105,7 +106,7 @@ public class CommandWithSubCommands implements CommandTemplate {
|
||||
}
|
||||
sender.sendMessage("");
|
||||
|
||||
var helpTitle =
|
||||
String helpTitle =
|
||||
Lang.centeredTitle(Lang.translateInsertVariables(
|
||||
"command.help.header", command, helpPage, pages));
|
||||
|
||||
|
@ -5,10 +5,8 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContain
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
||||
import com.sekwah.advancedportals.core.util.TagReader;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class CreateTaggedSubCommand implements SubCommand {
|
||||
@ -18,27 +16,27 @@ public abstract class CreateTaggedSubCommand implements SubCommand {
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
if (TagReader.isClosedString(args)) {
|
||||
return List.of();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<Tag> allTags = this.getRelatedTags();
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
if (args.length > 0) {
|
||||
var lastArg = args[args.length - 1];
|
||||
String lastArg = args[args.length - 1];
|
||||
// Check if the split results in exactly 2 or if its 1 and ends
|
||||
// with :
|
||||
var split = lastArg.split(":");
|
||||
String[] split = lastArg.split(":");
|
||||
if (split.length == 2
|
||||
|| (split.length == 1 && lastArg.endsWith(":"))) {
|
||||
// Loop over tags in allTags and check if the first half of
|
||||
// split is equal to the tag name or alias
|
||||
for (Tag tag : allTags) {
|
||||
// Check if the last tag starts with the tag name or alias
|
||||
var startsWith = false;
|
||||
boolean startsWith = false;
|
||||
if (lastArg.startsWith(tag.getName())) {
|
||||
startsWith = true;
|
||||
} else {
|
||||
var aliases = tag.getAliases();
|
||||
String[] aliases = tag.getAliases();
|
||||
if (aliases != null) {
|
||||
for (String alias : aliases) {
|
||||
if (lastArg.startsWith(alias)) {
|
||||
@ -49,14 +47,16 @@ public abstract class CreateTaggedSubCommand implements SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
if (tag instanceof Tag.AutoComplete autoComplete
|
||||
if (tag instanceof Tag.AutoComplete
|
||||
&& startsWith) {
|
||||
var argData = split.length == 2 ? split[1] : "";
|
||||
var tagSuggestions = autoComplete.autoComplete(argData);
|
||||
Tag.AutoComplete autoComplete = (Tag.AutoComplete) tag;
|
||||
String argData = split.length == 2 ? split[1] : "";
|
||||
List<String> tagSuggestions = autoComplete.autoComplete(argData);
|
||||
|
||||
if (tagSuggestions != null) {
|
||||
if (tag instanceof Tag.Split splitTag) {
|
||||
var multiTagSplit = splitTag.splitString();
|
||||
if (tag instanceof Tag.Split ) {
|
||||
Tag.Split splitTag = (Tag.Split) tag;
|
||||
String multiTagSplit = splitTag.splitString();
|
||||
boolean endsWithSplit =
|
||||
argData.endsWith(multiTagSplit);
|
||||
String[] items = argData.split(multiTagSplit);
|
||||
@ -90,7 +90,7 @@ public abstract class CreateTaggedSubCommand implements SubCommand {
|
||||
// Remap so the auto completes actually
|
||||
// show
|
||||
.map(s -> baseString + s)
|
||||
.toList();
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// Loop over suggestions and add split[0] + ":" to
|
||||
@ -114,7 +114,7 @@ public abstract class CreateTaggedSubCommand implements SubCommand {
|
||||
if (argTag.NAME.equals(tag.getName())) {
|
||||
return false;
|
||||
}
|
||||
var aliases = tag.getAliases();
|
||||
String[] aliases = tag.getAliases();
|
||||
if (aliases != null) {
|
||||
for (String alias : aliases) {
|
||||
if (argTag.NAME.equals(alias)) {
|
||||
@ -127,16 +127,14 @@ public abstract class CreateTaggedSubCommand implements SubCommand {
|
||||
})
|
||||
.forEach(tag -> {
|
||||
suggestions.add(tag.getName());
|
||||
var aliases = tag.getAliases();
|
||||
String[] aliases = tag.getAliases();
|
||||
if (aliases != null) {
|
||||
suggestions.addAll(Arrays.stream(aliases).toList());
|
||||
suggestions.addAll(Arrays.stream(aliases).collect(Collectors.toList()));
|
||||
}
|
||||
});
|
||||
|
||||
// Loop over all suggestions and add : to the end
|
||||
for (int i = 0; i < suggestions.size(); i++) {
|
||||
suggestions.set(i, suggestions.get(i) + ":");
|
||||
}
|
||||
suggestions.replaceAll(s -> s + ":");
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
@ -145,17 +143,18 @@ public abstract class CreateTaggedSubCommand implements SubCommand {
|
||||
List<Tag> relatedTags = this.getRelatedTags();
|
||||
List<DataTag> processedTags = new ArrayList<>();
|
||||
|
||||
for (var dataTag : dataTags) {
|
||||
for (DataTag dataTag : dataTags) {
|
||||
for (Tag tag : relatedTags) {
|
||||
if (tag instanceof Tag.Split splitTag) {
|
||||
var splitString = splitTag.splitString();
|
||||
if (tag instanceof Tag.Split ) {
|
||||
Tag.Split splitTag = (Tag.Split) tag;
|
||||
String splitString = splitTag.splitString();
|
||||
if (splitString != null) {
|
||||
List<String> newValues = new ArrayList<>();
|
||||
for (String split : dataTag.VALUES) {
|
||||
newValues.addAll(
|
||||
Arrays.stream(split.split(splitString))
|
||||
.map(String::trim)
|
||||
.toList());
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
dataTag = new DataTag(dataTag.NAME,
|
||||
newValues.toArray(new String[0]));
|
||||
|
@ -15,6 +15,7 @@ import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CreateDestiSubCommand extends CreateTaggedSubCommand {
|
||||
@Inject
|
||||
@ -90,13 +91,13 @@ public class CreateDestiSubCommand extends CreateTaggedSubCommand {
|
||||
|
||||
@Override
|
||||
protected List<Tag> getRelatedTags() {
|
||||
var tags = tagRegistry.getTags();
|
||||
List<Tag> tags = tagRegistry.getTags();
|
||||
// Filter tags that support Destination
|
||||
return tags.stream()
|
||||
.filter(tag
|
||||
-> Arrays.asList(tag.getTagTypes())
|
||||
.contains(Tag.TagType.DESTINATION))
|
||||
.toList();
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,6 +9,7 @@ import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
|
||||
import com.sekwah.advancedportals.core.destination.Destination;
|
||||
import com.sekwah.advancedportals.core.permissions.Permissions;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerData;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.serializeddata.Vector;
|
||||
import com.sekwah.advancedportals.core.services.DestinationServices;
|
||||
@ -53,7 +54,7 @@ public class ShowDestiSubCommand
|
||||
return;
|
||||
}
|
||||
|
||||
var tempData =
|
||||
PlayerData tempData =
|
||||
tempDataServices.getPlayerData(sender.getPlayerContainer());
|
||||
if (tempData.isDestiVisible()) {
|
||||
sender.sendMessage(
|
||||
@ -92,14 +93,14 @@ public class ShowDestiSubCommand
|
||||
public void registered() {
|
||||
gameScheduler.intervalTickEvent("show_portal", () -> {
|
||||
for (PlayerContainer player : serverContainer.getPlayers()) {
|
||||
var tempData = tempDataServices.getPlayerData(player);
|
||||
PlayerData tempData = tempDataServices.getPlayerData(player);
|
||||
if (!tempData.isDestiVisible()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Destination destination :
|
||||
destinationServices.getDestinations()) {
|
||||
var pos = destination.getLoc();
|
||||
PlayerLocation pos = destination.getLoc();
|
||||
if (Objects.equals(pos.getWorldName(),
|
||||
player.getWorldName())
|
||||
&& pos.distanceTo(player.getLoc())
|
||||
|
@ -18,6 +18,7 @@ import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CreatePortalSubCommand extends CreateTaggedSubCommand {
|
||||
@Inject
|
||||
@ -67,7 +68,7 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand {
|
||||
}
|
||||
sender.sendMessage("");
|
||||
|
||||
var triggerBlockTag =
|
||||
DataTag triggerBlockTag =
|
||||
portalTags.stream()
|
||||
.filter(tag -> tag.NAME.equals(TriggerBlockTag.TAG_NAME))
|
||||
.findFirst()
|
||||
@ -102,13 +103,13 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand {
|
||||
|
||||
@Override
|
||||
protected List<Tag> getRelatedTags() {
|
||||
var tags = tagRegistry.getTags();
|
||||
List<Tag> tags = tagRegistry.getTags();
|
||||
// Filter tags that support Destination
|
||||
return tags.stream()
|
||||
.filter(tag
|
||||
-> Arrays.asList(tag.getTagTypes())
|
||||
.contains(Tag.TagType.PORTAL))
|
||||
.toList();
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,6 +4,7 @@ import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
|
||||
import com.sekwah.advancedportals.core.permissions.Permissions;
|
||||
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.services.PortalServices;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import java.util.List;
|
||||
@ -15,8 +16,8 @@ public class DisableBeaconSubCommand implements SubCommand {
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
if (args.length > 1) {
|
||||
var portalName = args[1];
|
||||
var portal = portalServices.getPortal(portalName);
|
||||
String portalName = args[1];
|
||||
AdvancedPortal portal = portalServices.getPortal(portalName);
|
||||
if (portal == null) {
|
||||
sender.sendMessage(
|
||||
Lang.getNegativePrefix()
|
||||
|
@ -4,6 +4,7 @@ import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
|
||||
import com.sekwah.advancedportals.core.permissions.Permissions;
|
||||
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.services.PortalServices;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.util.TagReader;
|
||||
@ -16,8 +17,8 @@ public class InfoPortalSubCommand implements SubCommand {
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
if (args.length > 1) {
|
||||
var portalName = args[1];
|
||||
var portal = portalServices.getPortal(portalName);
|
||||
String portalName = args[1];
|
||||
AdvancedPortal portal = portalServices.getPortal(portalName);
|
||||
if (portal == null) {
|
||||
sender.sendMessage(
|
||||
Lang.getNegativePrefix()
|
||||
|
@ -6,10 +6,12 @@ import com.sekwah.advancedportals.core.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
|
||||
import com.sekwah.advancedportals.core.connector.containers.WorldContainer;
|
||||
import com.sekwah.advancedportals.core.permissions.Permissions;
|
||||
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerData;
|
||||
import com.sekwah.advancedportals.core.serializeddata.Vector;
|
||||
import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
||||
import com.sekwah.advancedportals.core.services.PortalServices;
|
||||
@ -65,7 +67,7 @@ public class ShowPortalSubCommand
|
||||
return;
|
||||
}
|
||||
|
||||
var tempData =
|
||||
PlayerData tempData =
|
||||
playerDataServices.getPlayerData(sender.getPlayerContainer());
|
||||
if (tempData.isPortalVisible()) {
|
||||
sender.sendMessage(
|
||||
@ -104,14 +106,14 @@ public class ShowPortalSubCommand
|
||||
gameScheduler.intervalTickEvent("show_portal", () -> {
|
||||
alternate_show_trigger = !alternate_show_trigger;
|
||||
for (PlayerContainer player : serverContainer.getPlayers()) {
|
||||
var tempData = playerDataServices.getPlayerData(player);
|
||||
PlayerData tempData = playerDataServices.getPlayerData(player);
|
||||
|
||||
if (!tempData.isPortalVisible()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var pos1 = tempData.getPos1();
|
||||
var pos2 = tempData.getPos2();
|
||||
BlockLocation pos1 = tempData.getPos1();
|
||||
BlockLocation pos2 = tempData.getPos2();
|
||||
|
||||
if (pos1 != null && pos2 != null
|
||||
&& pos1.getWorldName().equals(player.getWorldName())
|
||||
@ -144,7 +146,7 @@ public class ShowPortalSubCommand
|
||||
}
|
||||
}
|
||||
|
||||
for (var portal : portalServices.getPortals()) {
|
||||
for (AdvancedPortal portal : portalServices.getPortals()) {
|
||||
if (Objects.equals(portal.getMinLoc().getWorldName(),
|
||||
player.getWorldName())
|
||||
&& portal.isLocationInPortal(
|
||||
@ -216,9 +218,9 @@ public class ShowPortalSubCommand
|
||||
int maxY = Math.max(pos1.getPosY(), pos2.getPosY());
|
||||
int maxZ = Math.max(pos1.getPosZ(), pos2.getPosZ());
|
||||
|
||||
var size = pos1.getSize(pos2);
|
||||
int size = pos1.getSize(pos2);
|
||||
|
||||
var world = player.getWorld();
|
||||
WorldContainer world = player.getWorld();
|
||||
|
||||
if (size <= config.maxPortalVisualisationSize()) {
|
||||
drawBox(player, pos1, pos2, color, 0.5f);
|
||||
@ -226,7 +228,7 @@ public class ShowPortalSubCommand
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
var pos =
|
||||
BlockLocation pos =
|
||||
new BlockLocation(pos1.getWorldName(), x, y, z);
|
||||
boolean isTrigger = portal != null
|
||||
&& portal.isTriggerBlock(world.getBlock(pos));
|
||||
|
@ -74,8 +74,9 @@ public class Destination implements TagTarget {
|
||||
}
|
||||
|
||||
this.destiTags.sort(Comparator.comparingInt(o -> {
|
||||
var tag = tagRegistry.getTag(o.NAME);
|
||||
if (tag instanceof Tag.OrderPriority tagPriority) {
|
||||
Tag tag = tagRegistry.getTag(o.NAME);
|
||||
if (tag instanceof Tag.OrderPriority ) {
|
||||
Tag.OrderPriority tagPriority = (Tag.OrderPriority) tag;
|
||||
return tagPriority.getPriority().ordinal();
|
||||
} else {
|
||||
return Tag.Priority.NORMAL.ordinal();
|
||||
|
@ -49,7 +49,7 @@ public class PermissionBuilder {
|
||||
}
|
||||
|
||||
public PermissionBuilder createChild(String permissionTag) {
|
||||
var child = new PermissionBuilder(permissionTag, this);
|
||||
PermissionBuilder child = new PermissionBuilder(permissionTag, this);
|
||||
children.add(child);
|
||||
|
||||
return child;
|
||||
@ -57,7 +57,7 @@ public class PermissionBuilder {
|
||||
|
||||
public PermissionBuilder createChild(String permissionTag,
|
||||
PermissionDefault permissionDefault) {
|
||||
var child =
|
||||
PermissionBuilder child =
|
||||
new PermissionBuilder(permissionTag, this, permissionDefault);
|
||||
children.add(child);
|
||||
|
||||
@ -90,12 +90,18 @@ public class PermissionBuilder {
|
||||
if (Permissions.hasPermissionManager) {
|
||||
return sender.hasPermission(this.toString());
|
||||
}
|
||||
return switch (permissionDefault) {
|
||||
case TRUE -> true;
|
||||
case FALSE -> false;
|
||||
case OP -> sender.isOp();
|
||||
case NOT_OP -> !sender.isOp();
|
||||
};
|
||||
switch (permissionDefault) {
|
||||
case TRUE:
|
||||
return true;
|
||||
case FALSE:
|
||||
return false;
|
||||
case OP:
|
||||
return sender.isOp();
|
||||
case NOT_OP:
|
||||
return !sender.isOp();
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + permissionDefault);
|
||||
}
|
||||
}
|
||||
|
||||
public List<PermissionBuilder> getChildren() {
|
||||
|
@ -7,6 +7,7 @@ import com.sekwah.advancedportals.core.registry.TagTarget;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerData;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
||||
import com.sekwah.advancedportals.core.tags.TriggerBlockTag;
|
||||
@ -85,8 +86,9 @@ public class AdvancedPortal implements TagTarget {
|
||||
|
||||
// sort the tags by priority
|
||||
this.portalTags.sort(Comparator.comparingInt(o -> {
|
||||
var tag = tagRegistry.getTag(o.NAME);
|
||||
if (tag instanceof Tag.OrderPriority tagPriority) {
|
||||
Tag tag = tagRegistry.getTag(o.NAME);
|
||||
if (tag instanceof Tag.OrderPriority ) {
|
||||
Tag.OrderPriority tagPriority = (Tag.OrderPriority) tag;
|
||||
return tagPriority.getPriority().ordinal();
|
||||
} else {
|
||||
return Tag.Priority.NORMAL.ordinal();
|
||||
@ -142,17 +144,17 @@ public class AdvancedPortal implements TagTarget {
|
||||
updatePortalTagList();
|
||||
}
|
||||
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
PlayerData playerData = playerDataServices.getPlayerData(player);
|
||||
|
||||
if (playerData.hasJoinCooldown()) {
|
||||
var cooldown =
|
||||
int cooldown =
|
||||
(int) Math.ceil(playerData.getJoinCooldownLeft() / 1000D);
|
||||
player.sendMessage(Lang.translateInsertVariables(
|
||||
"portal.cooldown.join", cooldown,
|
||||
Lang.translate(cooldown == 1 ? "time.second"
|
||||
: "time.seconds")));
|
||||
if (configRepository.playFailSound()) {
|
||||
var rand = new Random();
|
||||
Random rand = new Random();
|
||||
player.playSound("block.portal.travel", 0.05f,
|
||||
rand.nextFloat() * 0.4F + 0.8F);
|
||||
}
|
||||
@ -165,15 +167,15 @@ public class AdvancedPortal implements TagTarget {
|
||||
Tag.Activation activationHandler = tagRegistry.getActivationHandler(
|
||||
portalTag.NAME, Tag.TagType.PORTAL);
|
||||
if (activationHandler != null) {
|
||||
var preActivated = activationHandler.preActivated(
|
||||
boolean preActivated = activationHandler.preActivated(
|
||||
this, player, data, this.getArgValues(portalTag.NAME));
|
||||
|
||||
if (!preActivated) {
|
||||
if (activationHandler
|
||||
instanceof Tag.DenyBehavior denyBehavior
|
||||
&& denyBehavior.getDenyBehavior()
|
||||
== Tag.DenyBehavior.Behaviour.SILENT) {
|
||||
return ActivationResult.FAILED_DO_NOTHING;
|
||||
if (activationHandler instanceof Tag.DenyBehavior) {
|
||||
Tag.DenyBehavior denyBehaviorHandler = (Tag.DenyBehavior) activationHandler;
|
||||
if (denyBehaviorHandler.getDenyBehavior().equals(Tag.DenyBehavior.Behaviour.SILENT)) {
|
||||
return ActivationResult.FAILED_DO_NOTHING;
|
||||
}
|
||||
}
|
||||
return ActivationResult.FAILED_DO_KNOCKBACK;
|
||||
}
|
||||
@ -243,7 +245,7 @@ public class AdvancedPortal implements TagTarget {
|
||||
}
|
||||
|
||||
public boolean isTriggerBlock(String blockMaterial) {
|
||||
var triggerBlocks = this.getArgValues(TriggerBlockTag.TAG_NAME);
|
||||
String[] triggerBlocks = this.getArgValues(TriggerBlockTag.TAG_NAME);
|
||||
if (triggerBlocks != null) {
|
||||
for (String triggerBlock : triggerBlocks) {
|
||||
if (blockMaterial.equals(triggerBlock)) {
|
||||
|
@ -35,7 +35,7 @@ public class TagRegistry {
|
||||
*/
|
||||
public Tag.Activation getActivationHandler(String arg,
|
||||
Tag.TagType targetType) {
|
||||
var tag = this.activationTags.get(arg);
|
||||
Tag.Activation tag = this.activationTags.get(arg);
|
||||
if (tag != null
|
||||
&& Arrays.asList(tag.getTagTypes()).contains(targetType)) {
|
||||
return tag;
|
||||
@ -79,7 +79,7 @@ public class TagRegistry {
|
||||
return false;
|
||||
}
|
||||
|
||||
var aliases = tag.getAliases();
|
||||
String[] aliases = tag.getAliases();
|
||||
this.literalTags.add(tagName);
|
||||
if (aliases != null) {
|
||||
for (String alias : aliases) {
|
||||
@ -100,13 +100,16 @@ public class TagRegistry {
|
||||
|
||||
this.tagMap.put(tagName, tag);
|
||||
|
||||
if (tag instanceof Tag.Activation tagActivation) {
|
||||
if (tag instanceof Tag.Activation) {
|
||||
Tag.Activation tagActivation = (Tag.Activation) tag;
|
||||
this.activationTags.put(tagName, tagActivation);
|
||||
}
|
||||
if (tag instanceof Tag.TagStatus tagStatus) {
|
||||
if (tag instanceof Tag.TagStatus) {
|
||||
Tag.TagStatus tagStatus = (Tag.TagStatus) tag;
|
||||
this.statusTags.put(tagName, tagStatus);
|
||||
}
|
||||
if (tag instanceof Tag.Creation tagCreation) {
|
||||
if (tag instanceof Tag.Creation) {
|
||||
Tag.Creation tagCreation = (Tag.Creation) tag;
|
||||
this.creationTags.put(tagName, tagCreation);
|
||||
}
|
||||
return true;
|
||||
|
@ -41,8 +41,9 @@ public class WarpEffectRegistry {
|
||||
|
||||
public WarpEffect.Visual getVisualEffect(String name) {
|
||||
if (this.warpEffects.containsKey(name.toLowerCase())) {
|
||||
var effect = this.warpEffects.get(name);
|
||||
if (effect instanceof WarpEffect.Visual visual) {
|
||||
WarpEffect effect = this.warpEffects.get(name);
|
||||
if (effect instanceof WarpEffect.Visual) {
|
||||
WarpEffect.Visual visual = (WarpEffect.Visual) effect;
|
||||
return visual;
|
||||
} else {
|
||||
this.infoLogger.warning("Effect called " + name
|
||||
@ -58,9 +59,9 @@ public class WarpEffectRegistry {
|
||||
|
||||
public WarpEffect.Sound getSoundEffect(String name) {
|
||||
if (this.warpEffects.containsKey(name)) {
|
||||
var effect = this.warpEffects.get(name);
|
||||
if (effect instanceof WarpEffect.Sound sound) {
|
||||
return sound;
|
||||
WarpEffect effect = this.warpEffects.get(name);
|
||||
if (effect instanceof WarpEffect.Sound) {
|
||||
return (WarpEffect.Sound) effect;
|
||||
} else {
|
||||
this.infoLogger.warning("Effect called " + name
|
||||
+ " is not a sound effect");
|
||||
|
@ -43,7 +43,7 @@ public class PortalRepositoryImpl implements IPortalRepository {
|
||||
|
||||
@Override
|
||||
public AdvancedPortal get(String name) {
|
||||
var portal = dataStorage.loadFile(AdvancedPortal.class,
|
||||
AdvancedPortal portal = dataStorage.loadFile(AdvancedPortal.class,
|
||||
fileLocation + name + ".yaml");
|
||||
if (portal != null) {
|
||||
AdvancedPortalsCore.getInstance()
|
||||
|
@ -36,12 +36,12 @@ public class DataStorage {
|
||||
|
||||
loaderOptions.setTagInspector(tagInspector);
|
||||
|
||||
var options = new DumperOptions();
|
||||
DumperOptions options = new DumperOptions();
|
||||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
var representer = new ReflectiveRepresenter(options);
|
||||
ReflectiveRepresenter representer = new ReflectiveRepresenter(options);
|
||||
representer.addClassTag(clazz, Tag.MAP);
|
||||
representer.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
var constructor = new ReflectiveConstructor(clazz, loaderOptions);
|
||||
ReflectiveConstructor constructor = new ReflectiveConstructor(clazz, loaderOptions);
|
||||
|
||||
AdvancedPortalsCore.getInstance()
|
||||
.getModule()
|
||||
|
@ -53,10 +53,10 @@ public class PlayerLocation extends WorldLocation {
|
||||
double rotX = this.getYaw();
|
||||
double rotY = this.getPitch();
|
||||
|
||||
var y = -Math.sin(Math.toRadians(rotY));
|
||||
double y = -Math.sin(Math.toRadians(rotY));
|
||||
double xz = Math.cos(Math.toRadians(rotY));
|
||||
var x = (-xz * Math.sin(Math.toRadians(rotX)));
|
||||
var z = Math.cos(Math.toRadians(rotX));
|
||||
double x = (-xz * Math.sin(Math.toRadians(rotX)));
|
||||
double z = Math.cos(Math.toRadians(rotX));
|
||||
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
@ -33,10 +33,10 @@ public class ReflectiveConstructor<T> extends Constructor {
|
||||
private Object constructObject(Class<?> currentClass, Node node) {
|
||||
if (node instanceof MappingNode) {
|
||||
return constructFromMappingNode(currentClass, (MappingNode) node);
|
||||
} else if (node instanceof ScalarNode scalarNode) {
|
||||
return constructFromScalarNode(scalarNode);
|
||||
} else if (node instanceof SequenceNode sequenceNode) {
|
||||
return constructFromSequenceNode(sequenceNode);
|
||||
} else if (node instanceof ScalarNode) {
|
||||
return constructFromScalarNode((ScalarNode) node);
|
||||
} else if (node instanceof SequenceNode) {
|
||||
return constructFromSequenceNode((SequenceNode) node);
|
||||
} else {
|
||||
infoLogger.warning("Unexpected node type encountered: "
|
||||
+ node.getClass().getSimpleName());
|
||||
@ -67,18 +67,20 @@ public class ReflectiveConstructor<T> extends Constructor {
|
||||
if (currentClass.equals(HashMap.class)) {
|
||||
Map<String, Object> values = new HashMap<>();
|
||||
for (NodeTuple tuple : mappingNode.getValue()) {
|
||||
var key = (String) constructObject(tuple.getKeyNode());
|
||||
String key = (String) constructObject(tuple.getKeyNode());
|
||||
|
||||
var node = tuple.getValueNode();
|
||||
Node node = tuple.getValueNode();
|
||||
|
||||
if (node instanceof ScalarNode scalarNode) {
|
||||
var constructedItem = constructFromScalarNode(scalarNode);
|
||||
if (node instanceof ScalarNode) {
|
||||
Object constructedItem = constructFromScalarNode((ScalarNode) node);
|
||||
values.put(key, constructedItem);
|
||||
} else if (node instanceof SequenceNode sequenceNode) {
|
||||
var constructedItem =
|
||||
} else if (node instanceof SequenceNode) {
|
||||
SequenceNode sequenceNode = (SequenceNode) node;
|
||||
Object constructedItem =
|
||||
constructFromSequenceNode(sequenceNode);
|
||||
values.put(key, constructedItem);
|
||||
} else if (node instanceof MappingNode mappingNodeChild) {
|
||||
} else if (node instanceof MappingNode) {
|
||||
MappingNode mappingNodeChild = (MappingNode) node;
|
||||
try {
|
||||
Object value = constructFromMappingNode(
|
||||
Object.class, mappingNodeChild);
|
||||
@ -166,15 +168,17 @@ public class ReflectiveConstructor<T> extends Constructor {
|
||||
MappingNode mappingNode) {
|
||||
Map<String, Object> values = new HashMap<>();
|
||||
for (NodeTuple tuple : mappingNode.getValue()) {
|
||||
var key = (String) super.constructObject(tuple.getKeyNode());
|
||||
String key = (String) super.constructObject(tuple.getKeyNode());
|
||||
|
||||
var node = tuple.getValueNode();
|
||||
Node node = tuple.getValueNode();
|
||||
|
||||
if (node instanceof ScalarNode scalarNode) {
|
||||
if (node instanceof ScalarNode) {
|
||||
ScalarNode scalarNode = (ScalarNode) node;
|
||||
values.put(key, constructFromScalarNode(scalarNode));
|
||||
} else if (node instanceof MappingNode mappingNodeChild) {
|
||||
} else if (node instanceof MappingNode) {
|
||||
MappingNode mappingNodeChild = (MappingNode) node;
|
||||
try {
|
||||
var field = currentClass.getDeclaredField(key);
|
||||
Field field = currentClass.getDeclaredField(key);
|
||||
Object value = constructFromMappingNode(field.getType(),
|
||||
mappingNodeChild);
|
||||
values.put(key, value);
|
||||
|
@ -154,13 +154,13 @@ public class DestinationServices {
|
||||
|
||||
player.teleport(this.destinationRepository.get(name).getLoc());
|
||||
if (doEffect && configRepository.getWarpEffectEnabled()) {
|
||||
var warpEffectVisual = warpEffectRegistry.getVisualEffect(
|
||||
WarpEffect.Visual warpEffectVisual = warpEffectRegistry.getVisualEffect(
|
||||
configRepository.getWarpVisual());
|
||||
if (warpEffectVisual != null) {
|
||||
warpEffectVisual.onWarpVisual(player,
|
||||
WarpEffect.Action.ENTER);
|
||||
}
|
||||
var warpEffectSound = warpEffectRegistry.getSoundEffect(
|
||||
WarpEffect.Sound warpEffectSound = warpEffectRegistry.getSoundEffect(
|
||||
configRepository.getWarpSound());
|
||||
if (warpEffectSound != null) {
|
||||
warpEffectSound.onWarpSound(player,
|
||||
|
@ -27,7 +27,7 @@ public final class PlayerDataServices {
|
||||
|
||||
public PlayerData getPlayerData(PlayerContainer player) {
|
||||
return tempDataMap.computeIfAbsent(player.getUUID(), uuid -> {
|
||||
var tempData = tempDataRepository.get(player.getUUID().toString());
|
||||
PlayerData tempData = tempDataRepository.get(player.getUUID().toString());
|
||||
|
||||
if (tempData == null) {
|
||||
tempData = new PlayerData();
|
||||
@ -37,7 +37,7 @@ public final class PlayerDataServices {
|
||||
}
|
||||
|
||||
public void setJoinCooldown(PlayerContainer player) {
|
||||
var tempData = getPlayerData(player);
|
||||
PlayerData tempData = getPlayerData(player);
|
||||
tempData.setJoinCooldown(configRepository.getPortalCooldown() * 1000);
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ public final class PlayerDataServices {
|
||||
public void playerSelectorActivate(PlayerContainer player,
|
||||
BlockLocation blockLoc,
|
||||
boolean leftClick) {
|
||||
var tempData = getPlayerData(player);
|
||||
PlayerData tempData = getPlayerData(player);
|
||||
if (leftClick) {
|
||||
tempData.setPos1(blockLoc);
|
||||
} else {
|
||||
|
@ -4,6 +4,7 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.sekwah.advancedportals.core.connector.containers.GameMode;
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.connector.containers.WorldContainer;
|
||||
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.registry.TagRegistry;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
@ -108,19 +109,19 @@ public class PortalServices {
|
||||
return PortalActivationResult.NOT_IN_PORTAL;
|
||||
}
|
||||
|
||||
var blockLoc = toLoc.toBlockPos();
|
||||
var blockEntityTopLoc = blockLoc.addY(player.getHeight());
|
||||
var world = player.getWorld();
|
||||
var blockMaterial = world.getBlock(blockLoc);
|
||||
var blockEntityTopMaterial = world.getBlock(blockEntityTopLoc);
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
BlockLocation blockLoc = toLoc.toBlockPos();
|
||||
BlockLocation blockEntityTopLoc = blockLoc.addY(player.getHeight());
|
||||
WorldContainer world = player.getWorld();
|
||||
String blockMaterial = world.getBlock(blockLoc);
|
||||
String blockEntityTopMaterial = world.getBlock(blockEntityTopLoc);
|
||||
PlayerData playerData = playerDataServices.getPlayerData(player);
|
||||
|
||||
for (AdvancedPortal portal : portalCache.values()) {
|
||||
if ((portal.isLocationInPortal(toLoc)
|
||||
&& portal.isTriggerBlock(blockMaterial))
|
||||
|| (portal.isLocationInPortal(blockEntityTopLoc)
|
||||
&& portal.isTriggerBlock(blockEntityTopMaterial))) {
|
||||
var portalName = portal.getName();
|
||||
String portalName = portal.getName();
|
||||
if (Objects.equals(playerData.inPortal(), portalName)) {
|
||||
return PortalActivationResult.PORTAL_DENIED;
|
||||
}
|
||||
@ -130,7 +131,7 @@ public class PortalServices {
|
||||
return PortalActivationResult.PORTAL_ACTIVATED;
|
||||
case FAILED_DO_KNOCKBACK:
|
||||
playerData.setInPortal(portal.getName());
|
||||
var strength = configRepository.getThrowbackStrength();
|
||||
double strength = configRepository.getThrowbackStrength();
|
||||
PlayerUtils.throwPlayerBack(player, strength);
|
||||
return PortalActivationResult.PORTAL_DENIED;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.sekwah.advancedportals.core.network.ProxyCommandPacket;
|
||||
import com.sekwah.advancedportals.core.permissions.Permissions;
|
||||
import com.sekwah.advancedportals.core.registry.TagTarget;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.config.CommandPortalConfig;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
@ -50,7 +51,7 @@ public class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
|
||||
@Override
|
||||
public boolean preActivated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activeData, String[] argData) {
|
||||
var commandPortals = configRepository.getCommandPortals();
|
||||
CommandPortalConfig commandPortals = configRepository.getCommandPortals();
|
||||
|
||||
if (!commandPortals.enabled) {
|
||||
player.sendMessage(Lang.getNegativePrefix()
|
||||
@ -128,7 +129,7 @@ public class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
|
||||
CommandLevel.PERMISSION_WILDCARD);
|
||||
break;
|
||||
case '%':
|
||||
var packet =
|
||||
ProxyCommandPacket packet =
|
||||
new ProxyCommandPacket(formattedCommand.substring(1));
|
||||
player.sendPacket(ProxyMessages.CHANNEL_NAME,
|
||||
packet.encode());
|
||||
@ -155,7 +156,7 @@ public class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
|
||||
public boolean created(TagTarget target, PlayerContainer player,
|
||||
String[] argData) {
|
||||
if (argData != null) {
|
||||
var commandPortals = configRepository.getCommandPortals();
|
||||
com.sekwah.advancedportals.core.serializeddata.config.CommandPortalConfig commandPortals = configRepository.getCommandPortals();
|
||||
if (!commandPortals.enabled) {
|
||||
player.sendMessage(Lang.getNegativePrefix()
|
||||
+ Lang.translate("tag.command.disabled"));
|
||||
@ -163,48 +164,46 @@ public class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
|
||||
}
|
||||
for (String command : argData) {
|
||||
char executionCommand = command.charAt(0);
|
||||
return switch (executionCommand) {
|
||||
case '!' -> {
|
||||
switch (executionCommand) {
|
||||
case '!':
|
||||
if (!commandPortals.op) {
|
||||
player.sendMessage(Lang.getNegativePrefix()
|
||||
+ Lang.translate("tag.command.op.disabled"));
|
||||
yield false;
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.CREATE_COMMAND_OP.hasPermission(player)) {
|
||||
player.sendMessage(Lang.getNegativePrefix()
|
||||
+ Lang.translateInsertVariables("tag.command.nopermission", "OP"));
|
||||
yield false;
|
||||
return false;
|
||||
}
|
||||
yield true;
|
||||
}
|
||||
case '#' -> {
|
||||
return true;
|
||||
case '#':
|
||||
if (!commandPortals.console) {
|
||||
player.sendMessage(Lang.getNegativePrefix()
|
||||
+ Lang.translate("tag.command.console.disabled"));
|
||||
yield false;
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.CREATE_COMMAND_CONSOLE.hasPermission(player)) {
|
||||
player.sendMessage(Lang.getNegativePrefix()
|
||||
+ Lang.translateInsertVariables("tag.command.nopermission","Console"));
|
||||
yield false;
|
||||
+ Lang.translateInsertVariables("tag.command.nopermission", "Console"));
|
||||
return false;
|
||||
}
|
||||
yield true;
|
||||
}
|
||||
case '^' -> {
|
||||
return true;
|
||||
case '^':
|
||||
if (!commandPortals.permsWildcard) {
|
||||
player.sendMessage(Lang.getNegativePrefix()
|
||||
+ Lang.translate("tag.command.permswildcard.disabled"));
|
||||
yield false;
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.CREATE_COMMAND_PERMS.hasPermission(player)) {
|
||||
player.sendMessage(Lang.getNegativePrefix()
|
||||
+ Lang.translateInsertVariables("tag.command.nopermission", "*"));
|
||||
yield false;
|
||||
return false;
|
||||
}
|
||||
yield true;
|
||||
}
|
||||
default -> true;
|
||||
};
|
||||
return true;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -5,6 +5,7 @@ import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.registry.TagTarget;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerData;
|
||||
import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
@ -52,11 +53,12 @@ public class CooldownTag implements Tag.Activation, Tag.Creation {
|
||||
public boolean preActivated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activationData,
|
||||
String[] argData) {
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
if (target instanceof AdvancedPortal portal) {
|
||||
var portalName = portal.getName();
|
||||
PlayerData playerData = playerDataServices.getPlayerData(player);
|
||||
if (target instanceof AdvancedPortal) {
|
||||
AdvancedPortal portal = (AdvancedPortal) target;
|
||||
String portalName = portal.getName();
|
||||
if (playerData.hasPortalCooldown(portalName)) {
|
||||
var cooldown = (int) Math.ceil(
|
||||
int cooldown = (int) Math.ceil(
|
||||
playerData.getPortalCooldownLeft(portalName) / 1000D);
|
||||
player.sendMessage(Lang.translateInsertVariables(
|
||||
"portal.cooldown.individual", cooldown,
|
||||
@ -77,8 +79,9 @@ public class CooldownTag implements Tag.Activation, Tag.Creation {
|
||||
public void postActivated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activationData, String[] argData) {
|
||||
if (activationData.hasActivated()) {
|
||||
if (target instanceof AdvancedPortal portal) {
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
if (target instanceof AdvancedPortal) {
|
||||
AdvancedPortal portal = (AdvancedPortal) target;
|
||||
PlayerData playerData = playerDataServices.getPlayerData(player);
|
||||
try {
|
||||
playerData.setPortalCooldown(
|
||||
portal.getName(), Integer.parseInt(argData[0]) * 1000);
|
||||
|
@ -9,6 +9,7 @@ import com.sekwah.advancedportals.core.registry.TagRegistry;
|
||||
import com.sekwah.advancedportals.core.registry.TagTarget;
|
||||
import com.sekwah.advancedportals.core.registry.WarpEffectRegistry;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
||||
import com.sekwah.advancedportals.core.services.DestinationServices;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||
@ -83,7 +84,7 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
||||
Destination destination =
|
||||
destinationServices.getDestination(selectedArg);
|
||||
if (destination != null) {
|
||||
for (var destiTag : destination.getArgs()) {
|
||||
for (DataTag destiTag : destination.getArgs()) {
|
||||
Tag.Activation activationHandler =
|
||||
tagRegistry.getActivationHandler(destiTag.NAME,
|
||||
Tag.TagType.DESTINATION);
|
||||
@ -105,11 +106,11 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
||||
return;
|
||||
}
|
||||
|
||||
var selectedArg = activationData.getMetadata(TAG_NAME);
|
||||
String selectedArg = activationData.getMetadata(TAG_NAME);
|
||||
Destination destination =
|
||||
destinationServices.getDestination(selectedArg);
|
||||
if (destination != null) {
|
||||
for (var destiTag : destination.getArgs()) {
|
||||
for (DataTag destiTag : destination.getArgs()) {
|
||||
Tag.Activation activationHandler =
|
||||
tagRegistry.getActivationHandler(destiTag.NAME,
|
||||
Tag.TagType.DESTINATION);
|
||||
@ -118,7 +119,7 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
||||
activationData, argData);
|
||||
}
|
||||
}
|
||||
var message = activationData.getMetadata(MessageTag.TAG_NAME);
|
||||
String message = activationData.getMetadata(MessageTag.TAG_NAME);
|
||||
if (message == null) {
|
||||
sendMessage(player,
|
||||
Lang.translateInsertVariables(
|
||||
@ -135,7 +136,7 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
||||
return true;
|
||||
}
|
||||
|
||||
var selectedArg = activationData.getMetadata(TAG_NAME);
|
||||
String selectedArg = activationData.getMetadata(TAG_NAME);
|
||||
Destination destination =
|
||||
destinationServices.getDestination(selectedArg);
|
||||
|
||||
@ -150,9 +151,9 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
||||
}
|
||||
|
||||
if (destination != null) {
|
||||
var warpEffectVisual = warpEffectRegistry.getVisualEffect(
|
||||
WarpEffect.Visual warpEffectVisual = warpEffectRegistry.getVisualEffect(
|
||||
configRepository.getWarpVisual());
|
||||
var warpEffectSound = warpEffectRegistry.getSoundEffect(
|
||||
WarpEffect.Sound warpEffectSound = warpEffectRegistry.getSoundEffect(
|
||||
configRepository.getWarpSound());
|
||||
if (configRepository.getWarpEffectEnabled()) {
|
||||
if (warpEffectVisual != null) {
|
||||
@ -167,7 +168,7 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
||||
|
||||
player.teleport(destination.getLoc());
|
||||
|
||||
for (var destiTag : destination.getArgs()) {
|
||||
for (DataTag destiTag : destination.getArgs()) {
|
||||
Tag.Activation activationHandler =
|
||||
tagRegistry.getActivationHandler(destiTag.NAME,
|
||||
Tag.TagType.DESTINATION);
|
||||
|
@ -49,8 +49,8 @@ public class MessageTag implements Tag.Activation {
|
||||
@Override
|
||||
public void postActivated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activationData, String[] argData) {
|
||||
var destination = activationData.getMetadata(DestiTag.TAG_NAME);
|
||||
var message = activationData.getMetadata(TAG_NAME);
|
||||
String destination = activationData.getMetadata(DestiTag.TAG_NAME);
|
||||
String message = activationData.getMetadata(TAG_NAME);
|
||||
if (destination == null) {
|
||||
destination = "";
|
||||
} else {
|
||||
|
@ -52,7 +52,7 @@ public class PermissionTag implements Tag.Activation {
|
||||
@Override
|
||||
public boolean preActivated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activeData, String[] argData) {
|
||||
var permission = argData[0];
|
||||
String permission = argData[0];
|
||||
if (permission.startsWith("!")) {
|
||||
permission = permission.substring(1);
|
||||
if (player.hasPermission(permission)) {
|
||||
|
@ -11,6 +11,8 @@ import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
import com.sekwah.advancedportals.core.warphandler.TriggerType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import javax.annotation.Nullable;
|
||||
@ -78,7 +80,7 @@ public class PortalEventTag implements Tag.Activation, Tag.AutoComplete,
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> autoComplete(String argData) {
|
||||
return List.of("true", "false");
|
||||
return Arrays.asList("true", "false");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,6 +3,7 @@ package com.sekwah.advancedportals.core.tags;
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.ProxyMessages;
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.network.Packet;
|
||||
import com.sekwah.advancedportals.core.network.ProxyTransferDestiPacket;
|
||||
import com.sekwah.advancedportals.core.network.ProxyTransferPacket;
|
||||
import com.sekwah.advancedportals.core.registry.TagTarget;
|
||||
@ -66,11 +67,14 @@ public class ProxyTag implements Tag.Activation, Tag.OrderPriority, Tag.Split {
|
||||
|
||||
String selectedArg = argData[random.nextInt(argData.length)];
|
||||
|
||||
var desti = activeData.getMetadata(DestiTag.TAG_NAME);
|
||||
String desti = activeData.getMetadata(DestiTag.TAG_NAME);
|
||||
|
||||
var packet = desti == null
|
||||
? new ProxyTransferPacket(selectedArg)
|
||||
: new ProxyTransferDestiPacket(selectedArg, desti);
|
||||
Packet packet;
|
||||
if (desti == null) {
|
||||
packet = new ProxyTransferPacket(selectedArg);
|
||||
} else {
|
||||
packet = new ProxyTransferDestiPacket(selectedArg, desti);
|
||||
}
|
||||
player.sendPacket(ProxyMessages.CHANNEL_NAME, packet.encode());
|
||||
activeData.setWarpStatus(ActivationData.WarpedStatus.WARPED);
|
||||
return true;
|
||||
|
@ -7,6 +7,7 @@ import com.sekwah.advancedportals.core.registry.TagTarget;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TriggerBlockTag
|
||||
implements Tag.AutoComplete, Tag.Split, Tag.Creation {
|
||||
@ -39,10 +40,10 @@ public class TriggerBlockTag
|
||||
|
||||
@Override
|
||||
public List<String> autoComplete(String argData) {
|
||||
var triggerBlocks = serverContainer.getCommonTriggerBlocks()
|
||||
.stream()
|
||||
.filter(block -> block.contains(argData))
|
||||
.toList();
|
||||
List<String> triggerBlocks = serverContainer.getCommonTriggerBlocks()
|
||||
.stream()
|
||||
.filter(block -> block.contains(argData))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (triggerBlocks.isEmpty()) {
|
||||
return serverContainer.getAllTriggerBlocks();
|
||||
|
@ -126,13 +126,16 @@ public class Lang {
|
||||
* @return
|
||||
*/
|
||||
public static String centeredTitle(String title) {
|
||||
var titleLength = 54 - (Lang.textLength(title));
|
||||
int titleLength = 54 - (Lang.textLength(title));
|
||||
|
||||
int eachSide = titleLength / 2;
|
||||
|
||||
return "\u00A7e"
|
||||
+ "=".repeat(eachSide) + " " + title + " \u00A7e"
|
||||
+ "=".repeat(eachSide);
|
||||
StringBuilder repeatedEquals = new StringBuilder();
|
||||
for (int i = 0; i < eachSide; i++) {
|
||||
repeatedEquals.append("=");
|
||||
}
|
||||
|
||||
return "\u00A7e" + repeatedEquals.toString() + " " + title + " \u00A7e" + repeatedEquals.toString();
|
||||
}
|
||||
|
||||
private void injectTranslations(String fileName) {
|
||||
|
@ -1,11 +1,12 @@
|
||||
package com.sekwah.advancedportals.core.util;
|
||||
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.serializeddata.Vector;
|
||||
|
||||
public class PlayerUtils {
|
||||
public static void throwPlayerBack(PlayerContainer player,
|
||||
double strength) {
|
||||
var playerLoc = player.getLoc().getDirection();
|
||||
Vector playerLoc = player.getLoc().getDirection();
|
||||
player.setVelocity(
|
||||
playerLoc.setY(0).normalize().multiply(-1).setY(0.5).multiply(
|
||||
strength));
|
||||
|
@ -17,7 +17,7 @@ public class TagReader {
|
||||
currentValue = new StringBuilder(arg.substring(colonIndex + 1));
|
||||
inQuotes = currentValue.toString().startsWith("\"");
|
||||
} else {
|
||||
if (!currentValue.isEmpty()) {
|
||||
if (currentValue.length() != 0) {
|
||||
currentValue.append(" ");
|
||||
}
|
||||
currentValue.append(arg);
|
||||
@ -57,7 +57,7 @@ public class TagReader {
|
||||
currentValue.deleteCharAt(0);
|
||||
}
|
||||
} else {
|
||||
if (!currentValue.isEmpty()) {
|
||||
if (currentValue.length() != 0) {
|
||||
currentValue.append(" ");
|
||||
}
|
||||
currentValue.append(arg);
|
||||
|
@ -11,6 +11,7 @@ import com.sekwah.advancedportals.proxycore.connector.container.ProxyContainer;
|
||||
import com.sekwah.advancedportals.proxycore.connector.container.ProxyJoinData;
|
||||
import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer;
|
||||
import com.sekwah.advancedportals.proxycore.connector.container.ProxyServerContainer;
|
||||
import com.sekwah.advancedportals.shadowed.guava.io.ByteArrayDataInput;
|
||||
import com.sekwah.advancedportals.shadowed.guava.io.ByteStreams;
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -37,7 +38,7 @@ public class AdvancedPortalsProxyCore {
|
||||
public void onServerConnect(ProxyServerContainer server,
|
||||
ProxyPlayerContainer player) {
|
||||
if (this.playerJoinMap.containsKey(player.getUUID())) {
|
||||
var joinData = this.playerJoinMap.get(player.getUUID());
|
||||
ProxyJoinData joinData = this.playerJoinMap.get(player.getUUID());
|
||||
if (joinData.isExpired())
|
||||
return;
|
||||
player.sendServerPluginMessage(
|
||||
@ -57,31 +58,31 @@ public class AdvancedPortalsProxyCore {
|
||||
* @param message
|
||||
*/
|
||||
public void incomingMessage(ProxyPlayerContainer player, byte[] message) {
|
||||
var buffer = ByteStreams.newDataInput(message);
|
||||
var messageType = buffer.readUTF();
|
||||
ByteArrayDataInput buffer = ByteStreams.newDataInput(message);
|
||||
String messageType = buffer.readUTF();
|
||||
|
||||
// Might be a bit overboard for some as they'll only have one value, but
|
||||
// try to keep the decode behavior with the encode behavior in the
|
||||
// packets
|
||||
switch (messageType) {
|
||||
case ProxyMessages.PROXY_TRANSFER -> {
|
||||
var transferPacket = ProxyTransferPacket.decode(buffer);
|
||||
case ProxyMessages.PROXY_TRANSFER:
|
||||
ProxyTransferPacket transferPacket = ProxyTransferPacket.decode(buffer);
|
||||
this.logger.info("Transfer request for " + player.getName() + " to " + transferPacket.getServerName());
|
||||
this.proxyContainer.transferPlayer(player, transferPacket.getServerName());
|
||||
}
|
||||
case ProxyMessages.PROXY_COMMAND -> {
|
||||
var commandPacket = ProxyCommandPacket.decode(buffer);
|
||||
break;
|
||||
case ProxyMessages.PROXY_COMMAND:
|
||||
ProxyCommandPacket commandPacket = ProxyCommandPacket.decode(buffer);
|
||||
this.logger.info("Command request for " + player.getName() + " to run /" + commandPacket.getCommand());
|
||||
this.proxyContainer.invokeCommand(player, commandPacket.getCommand());
|
||||
}
|
||||
case ProxyMessages.PROXY_TRANSFER_DESTI -> {
|
||||
var transferDestiPacket = ProxyTransferDestiPacket.decode(buffer);
|
||||
break;
|
||||
case ProxyMessages.PROXY_TRANSFER_DESTI:
|
||||
ProxyTransferDestiPacket transferDestiPacket = ProxyTransferDestiPacket.decode(buffer);
|
||||
this.proxyContainer.transferPlayer(player, transferDestiPacket.getServerName());
|
||||
this.playerJoinMap.put(player.getUUID(), new ProxyJoinData(transferDestiPacket.getDestination(), transferDestiPacket.getServerName()));
|
||||
}
|
||||
default -> {
|
||||
break;
|
||||
default:
|
||||
this.logger.info("Unknown message type: " + messageType);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,9 +22,9 @@ dependencies {
|
||||
|
||||
// For spigot api
|
||||
// We are using an older version to try and ensure that we are not using anything new older versions cant use.
|
||||
implementation "org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT"
|
||||
implementation "net.md-5:bungeecord-api:1.16-R0.4"
|
||||
implementation "com.mojang:authlib:3.5.41"
|
||||
compileOnly "org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT"
|
||||
compileOnly "net.md-5:bungeecord-api:1.16-R0.4"
|
||||
// compileOnly "com.mojang:authlib:3.5.41"
|
||||
// Be careful to only use what you need to from paper, otherwise it will become incompatible with spigot.
|
||||
// compileOnly 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT'
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
|
||||
String mcVersion = this.getServer().getVersion();
|
||||
Pattern pattern = Pattern.compile("\\(MC: ([\\d.]+)\\)");
|
||||
Matcher matcher = pattern.matcher(mcVersion);
|
||||
var serverContainer = new SpigotServerContainer(this.getServer());
|
||||
SpigotServerContainer serverContainer = new SpigotServerContainer(this.getServer());
|
||||
this.portalsCore = new AdvancedPortalsCore(
|
||||
matcher.find() ? matcher.group(1) : "0.0.0", this.getDataFolder(),
|
||||
new SpigotInfoLogger(this), serverContainer);
|
||||
@ -77,7 +77,7 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
|
||||
this.getServer().getScheduler().scheduleSyncRepeatingTask(
|
||||
this, scheduler::tick, 1, 1);
|
||||
|
||||
var warpEffects = new SpigotWarpEffects();
|
||||
SpigotWarpEffects warpEffects = new SpigotWarpEffects();
|
||||
injector.injectMembers(warpEffects);
|
||||
warpEffects.registerEffects();
|
||||
|
||||
|
@ -23,6 +23,7 @@ import org.bukkit.event.block.*;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Some of these will be passed to the core listener to handle the events,
|
||||
@ -51,7 +52,7 @@ public class Listeners implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onMoveEvent(PlayerMoveEvent event) {
|
||||
var to = event.getTo();
|
||||
Location to = event.getTo();
|
||||
coreListeners.playerMove(new SpigotPlayerContainer(event.getPlayer()),
|
||||
ContainerHelpers.toPlayerLocation(to));
|
||||
}
|
||||
@ -189,7 +190,7 @@ public class Listeners implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
var itemInHand = event.getPlayer().getItemInHand();
|
||||
ItemStack itemInHand = event.getPlayer().getItemInHand();
|
||||
if (!coreListeners.blockBreak(
|
||||
new SpigotPlayerContainer(event.getPlayer()),
|
||||
ContainerHelpers.toBlockLocation(
|
||||
@ -228,7 +229,7 @@ public class Listeners implements Listener {
|
||||
BlockState[] tileEntities = event.getChunk().getTileEntities();
|
||||
for (BlockState block : tileEntities) {
|
||||
if (block.getType() == Material.END_GATEWAY) {
|
||||
var loc = block.getLocation();
|
||||
Location loc = block.getLocation();
|
||||
if (portalServices.inPortalRegion(
|
||||
new BlockLocation(loc.getWorld().getName(),
|
||||
loc.getBlockX(), loc.getBlockY(),
|
||||
|
@ -3,6 +3,8 @@ package com.sekwah.advancedportals.spigot;
|
||||
import com.sekwah.advancedportals.core.permissions.PermissionBuilder;
|
||||
import com.sekwah.advancedportals.core.permissions.Permissions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PermissionsGeneratorSpigot {
|
||||
private PermissionsGeneratorSpigot() {
|
||||
}
|
||||
@ -25,7 +27,7 @@ public class PermissionsGeneratorSpigot {
|
||||
builder.append(indent).append(indent).append("description: ");
|
||||
builder.append(permission.getDescription()).append("\n");
|
||||
}
|
||||
var children = permission.getGrantChildren();
|
||||
List<PermissionBuilder> children = permission.getGrantChildren();
|
||||
if (!children.isEmpty()) {
|
||||
builder.append(indent).append(indent).append("children:\n");
|
||||
for (PermissionBuilder child : children) {
|
||||
|
@ -12,6 +12,8 @@ import com.sekwah.advancedportals.shadowed.inject.Inject;
|
||||
import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin;
|
||||
import com.sekwah.advancedportals.spigot.importer.ConfigAccessor;
|
||||
import com.sekwah.advancedportals.spigot.importer.LegacyImporter;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@ -58,7 +60,7 @@ public class ImportPortalSubCommand implements SubCommand {
|
||||
public int getDestinationCount() {
|
||||
ConfigAccessor destiConfig = new ConfigAccessor(
|
||||
AdvancedPortalsPlugin.getInstance(), "destinations.yaml");
|
||||
var config = destiConfig.getConfig();
|
||||
FileConfiguration config = destiConfig.getConfig();
|
||||
Set<String> destiSet = config.getKeys(false);
|
||||
|
||||
return destiSet.size();
|
||||
@ -67,7 +69,7 @@ public class ImportPortalSubCommand implements SubCommand {
|
||||
public int getPortalCount() {
|
||||
ConfigAccessor portalConfig = new ConfigAccessor(
|
||||
AdvancedPortalsPlugin.getInstance(), "portals.yaml");
|
||||
var config = portalConfig.getConfig();
|
||||
FileConfiguration config = portalConfig.getConfig();
|
||||
Set<String> portalSet = config.getKeys(false);
|
||||
|
||||
return portalSet.size();
|
||||
|
@ -10,8 +10,11 @@ import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
|
||||
@ -27,10 +30,10 @@ public class SpigotServerContainer implements ServerContainer {
|
||||
Material.END_PORTAL)
|
||||
.stream()
|
||||
.map(Enum::name)
|
||||
.toList();
|
||||
.collect(Collectors.toList());
|
||||
|
||||
private final List<String> fullTriggerBlockList =
|
||||
Arrays.stream(Material.values()).map(Enum::name).toList();
|
||||
Arrays.stream(Material.values()).map(Enum::name).collect(Collectors.toList());
|
||||
|
||||
public SpigotServerContainer(Server server) {
|
||||
this.server = server;
|
||||
@ -38,7 +41,7 @@ public class SpigotServerContainer implements ServerContainer {
|
||||
|
||||
@Override
|
||||
public WorldContainer getWorld(String name) {
|
||||
var world = server.getWorld(name);
|
||||
World world = server.getWorld(name);
|
||||
if (world != null) {
|
||||
return new SpigotWorldContainer(world);
|
||||
} else {
|
||||
@ -48,7 +51,7 @@ public class SpigotServerContainer implements ServerContainer {
|
||||
|
||||
@Override
|
||||
public PlayerContainer getPlayer(String name) {
|
||||
var player = server.getPlayer(name);
|
||||
Player player = server.getPlayer(name);
|
||||
if (player != null) {
|
||||
return new SpigotPlayerContainer(player);
|
||||
} else {
|
||||
@ -58,7 +61,7 @@ public class SpigotServerContainer implements ServerContainer {
|
||||
|
||||
@Override
|
||||
public PlayerContainer getPlayer(UUID name) {
|
||||
var player = server.getPlayer(name);
|
||||
Player player = server.getPlayer(name);
|
||||
if (player != null) {
|
||||
return new SpigotPlayerContainer(player);
|
||||
} else {
|
||||
@ -110,7 +113,8 @@ public class SpigotServerContainer implements ServerContainer {
|
||||
case PLAYER:
|
||||
server.dispatchCommand(player, command);
|
||||
break;
|
||||
case OP, PERMISSION_WILDCARD:
|
||||
case OP:
|
||||
case PERMISSION_WILDCARD:
|
||||
executeCommandWithPermission(player, server, command,
|
||||
commandLevel);
|
||||
break;
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.Particle;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.EndGateway;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Orientable;
|
||||
|
||||
public class SpigotWorldContainer implements WorldContainer {
|
||||
@ -52,10 +53,11 @@ public class SpigotWorldContainer implements WorldContainer {
|
||||
|
||||
@Override
|
||||
public BlockAxis getBlockAxis(BlockLocation location) {
|
||||
var block = world.getBlockAt(location.getPosX(), location.getPosY(),
|
||||
Block block = world.getBlockAt(location.getPosX(), location.getPosY(),
|
||||
location.getPosZ());
|
||||
var matData = block.getState().getBlockData();
|
||||
if (matData instanceof Orientable rotatable) {
|
||||
BlockData matData = block.getState().getBlockData();
|
||||
if (matData instanceof Orientable) {
|
||||
Orientable rotatable = (Orientable) matData;
|
||||
try {
|
||||
return BlockAxis.valueOf(rotatable.getAxis().toString());
|
||||
} catch (IllegalArgumentException e) {
|
||||
@ -67,10 +69,11 @@ public class SpigotWorldContainer implements WorldContainer {
|
||||
|
||||
@Override
|
||||
public void setBlockAxis(BlockLocation location, BlockAxis axis) {
|
||||
var block = world.getBlockAt(location.getPosX(), location.getPosY(),
|
||||
Block block = world.getBlockAt(location.getPosX(), location.getPosY(),
|
||||
location.getPosZ());
|
||||
var matData = block.getState().getBlockData();
|
||||
if (matData instanceof Orientable rotatable) {
|
||||
BlockData matData = block.getState().getBlockData();
|
||||
if (matData instanceof Orientable) {
|
||||
Orientable rotatable = (Orientable) matData;
|
||||
rotatable.setAxis(Axis.valueOf(axis.toString()));
|
||||
block.setBlockData(rotatable);
|
||||
}
|
||||
@ -80,11 +83,12 @@ public class SpigotWorldContainer implements WorldContainer {
|
||||
public void disableBeacon(BlockLocation location) {
|
||||
if (!endGatewaySetAgeExists)
|
||||
return;
|
||||
var block = this.world.getBlockAt(
|
||||
Block block = this.world.getBlockAt(
|
||||
location.getPosX(), location.getPosY(), location.getPosZ());
|
||||
var blockType = block.getType();
|
||||
Material blockType = block.getType();
|
||||
if (blockType == Material.END_GATEWAY
|
||||
&& block.getState() instanceof EndGateway endGateway) {
|
||||
&& block.getState() instanceof EndGateway) {
|
||||
EndGateway endGateway = (EndGateway) block.getState();
|
||||
endGateway.setAge(Long.MIN_VALUE);
|
||||
endGateway.update();
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.sekwah.advancedportals.spigot.importer;
|
||||
|
||||
import com.sekwah.advancedportals.core.destination.Destination;
|
||||
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
||||
@ -10,10 +12,12 @@ import com.sekwah.advancedportals.core.serializeddata.config.WarpEffectConfig;
|
||||
import com.sekwah.advancedportals.core.services.DestinationServices;
|
||||
import com.sekwah.advancedportals.core.services.PortalServices;
|
||||
import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class LegacyImporter {
|
||||
private LegacyImporter() {
|
||||
@ -23,7 +27,7 @@ public class LegacyImporter {
|
||||
// Check if the file exists and skip if it doesn't
|
||||
ConfigAccessor portalConfig = new ConfigAccessor(
|
||||
AdvancedPortalsPlugin.getInstance(), "portals.yml");
|
||||
var config = portalConfig.getConfig();
|
||||
FileConfiguration config = portalConfig.getConfig();
|
||||
Set<String> portalSet = config.getKeys(false);
|
||||
|
||||
int count = 0;
|
||||
@ -40,16 +44,16 @@ public class LegacyImporter {
|
||||
config.getInt(portalName + ".pos2.Z"));
|
||||
List<DataTag> args = new ArrayList<>();
|
||||
args.add(new DataTag("name", portalName));
|
||||
var triggerblock = config.getString(portalName + ".triggerblock");
|
||||
String triggerblock = config.getString(portalName + ".triggerblock");
|
||||
if (triggerblock != null)
|
||||
args.add(new DataTag("triggerblock", triggerblock.split(",")));
|
||||
// It's called bungee as that's the implementation behind it
|
||||
|
||||
var destination = config.getString(portalName + ".destination");
|
||||
String destination = config.getString(portalName + ".destination");
|
||||
if (destination != null)
|
||||
args.add(new DataTag("destination", destination.split(",")));
|
||||
|
||||
var bungee = config.getString(portalName + ".bungee");
|
||||
String bungee = config.getString(portalName + ".bungee");
|
||||
if (bungee != null) {
|
||||
if (destination == null) {
|
||||
args.add(new DataTag("bungee", bungee.split(",")));
|
||||
@ -89,17 +93,17 @@ public class LegacyImporter {
|
||||
}
|
||||
args.stream()
|
||||
.filter(dataTag -> dataTag.NAME.startsWith("command."))
|
||||
.toList()
|
||||
.collect(Collectors.toList())
|
||||
.forEach(args::remove);
|
||||
|
||||
// Find an arg called "delayed" and add a new one called portalEvent
|
||||
var delayed = getArg(args, "delayed");
|
||||
String delayed = getArg(args, "delayed");
|
||||
if (delayed != null) {
|
||||
args.add(new DataTag("portalEvent", delayed));
|
||||
args.removeIf(dataTag -> dataTag.NAME.equals("delayed"));
|
||||
}
|
||||
|
||||
var portal = portalServices.createPortal(null, pos1, pos2, args);
|
||||
AdvancedPortal portal = portalServices.createPortal(null, pos1, pos2, args);
|
||||
|
||||
if (portal != null)
|
||||
count++;
|
||||
@ -112,13 +116,13 @@ public class LegacyImporter {
|
||||
DestinationServices destinationServices) {
|
||||
ConfigAccessor destiConfig = new ConfigAccessor(
|
||||
AdvancedPortalsPlugin.getInstance(), "destinations.yml");
|
||||
var config = destiConfig.getConfig();
|
||||
FileConfiguration config = destiConfig.getConfig();
|
||||
Set<String> destiSet = config.getKeys(false);
|
||||
|
||||
int count = 0;
|
||||
for (String destiName : destiSet) {
|
||||
var destiPos = destiName + ".pos";
|
||||
var desti = destinationServices.createDesti(
|
||||
String destiPos = destiName + ".pos";
|
||||
Destination desti = destinationServices.createDesti(
|
||||
new PlayerLocation(
|
||||
config.getString(destiName + ".world"),
|
||||
config.getDouble(destiPos + ".X"),
|
||||
@ -126,7 +130,7 @@ public class LegacyImporter {
|
||||
config.getDouble(destiPos + ".Z"),
|
||||
(float) config.getDouble(destiPos + ".yaw"),
|
||||
(float) config.getDouble(destiPos + ".pitch")),
|
||||
List.of(new DataTag("name", destiName)));
|
||||
Collections.singletonList(new DataTag("name", destiName)));
|
||||
if (desti != null)
|
||||
count++;
|
||||
}
|
||||
@ -143,10 +147,10 @@ public class LegacyImporter {
|
||||
}
|
||||
|
||||
public static void importConfig(ConfigRepository configRepo) {
|
||||
var config = new Config();
|
||||
Config config = new Config();
|
||||
ConfigAccessor configOldAccessor = new ConfigAccessor(
|
||||
AdvancedPortalsPlugin.getInstance(), "config.yml");
|
||||
var configOld = configOldAccessor.getConfig();
|
||||
FileConfiguration configOld = configOldAccessor.getConfig();
|
||||
|
||||
config.useOnlySpecialAxe = configOld.getBoolean(
|
||||
"UseOnlyServerMadeAxe", config.useOnlySpecialAxe);
|
||||
@ -181,7 +185,7 @@ public class LegacyImporter {
|
||||
"DisableGatewayBeam", config.disableGatewayBeam);
|
||||
|
||||
CommandPortalConfig commandConfig = new CommandPortalConfig();
|
||||
var commandString = configOld.getString("CommandLevels", "opcb");
|
||||
String commandString = configOld.getString("CommandLevels", "opcb");
|
||||
commandConfig.enabled = !commandString.contains("n");
|
||||
commandConfig.op = commandString.contains("o");
|
||||
commandConfig.permsWildcard = commandString.contains("p");
|
||||
|
@ -111,14 +111,20 @@ public class ConditionsTag implements Tag.Activation, Tag.Split, Tag.Creation {
|
||||
double actualNumeric = Double.parseDouble(actualValue);
|
||||
double expectedNumeric = Double.parseDouble(expectedValue);
|
||||
|
||||
return switch (operator) {
|
||||
case "==" -> actualNumeric == expectedNumeric;
|
||||
case "<" -> actualNumeric < expectedNumeric;
|
||||
case ">" -> actualNumeric > expectedNumeric;
|
||||
case "<=" -> actualNumeric <= expectedNumeric;
|
||||
case ">=" -> actualNumeric >= expectedNumeric;
|
||||
default -> false; // Unsupported operator
|
||||
};
|
||||
switch (operator) {
|
||||
case "==":
|
||||
return actualNumeric == expectedNumeric;
|
||||
case "<":
|
||||
return actualNumeric < expectedNumeric;
|
||||
case ">":
|
||||
return actualNumeric > expectedNumeric;
|
||||
case "<=":
|
||||
return actualNumeric <= expectedNumeric;
|
||||
case ">=":
|
||||
return actualNumeric >= expectedNumeric;
|
||||
default:
|
||||
return false; // Unsupported operator
|
||||
}
|
||||
} else if (isBoolean(actualValue) && isBoolean(expectedValue)) {
|
||||
// Boolean comparison
|
||||
boolean actualBoolean = Boolean.parseBoolean(actualValue);
|
||||
|
@ -3,17 +3,18 @@ package com.sekwah.advancedportals.spigot.warpeffects;
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.effect.WarpEffect;
|
||||
import com.sekwah.advancedportals.spigot.connector.container.SpigotPlayerContainer;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class EnderWarpEffect implements WarpEffect.Visual, WarpEffect.Sound {
|
||||
@Override
|
||||
public void onWarpSound(PlayerContainer playerContainer,
|
||||
WarpEffect.Action action) {
|
||||
if (playerContainer
|
||||
instanceof SpigotPlayerContainer spigotPlayerContainer) {
|
||||
var player = spigotPlayerContainer.getPlayer();
|
||||
instanceof SpigotPlayerContainer) {
|
||||
SpigotPlayerContainer spigotPlayerContainer =
|
||||
(SpigotPlayerContainer) playerContainer;
|
||||
org.bukkit.entity.Player player = spigotPlayerContainer.getPlayer();
|
||||
|
||||
player.getWorld().playSound(player.getLocation(),
|
||||
"entity.enderman.teleport", 1, 1);
|
||||
@ -24,10 +25,12 @@ public class EnderWarpEffect implements WarpEffect.Visual, WarpEffect.Sound {
|
||||
public void onWarpVisual(PlayerContainer playerContainer,
|
||||
WarpEffect.Action action) {
|
||||
if (playerContainer
|
||||
instanceof SpigotPlayerContainer spigotPlayerContainer) {
|
||||
var player = spigotPlayerContainer.getPlayer();
|
||||
var world = player.getWorld();
|
||||
var loc = player.getLocation().clone();
|
||||
instanceof SpigotPlayerContainer) {
|
||||
SpigotPlayerContainer spigotPlayerContainer =
|
||||
(SpigotPlayerContainer) playerContainer;
|
||||
Player player = spigotPlayerContainer.getPlayer();
|
||||
World world = player.getWorld();
|
||||
Location loc = player.getLocation().clone();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
world.playEffect(loc, Effect.ENDER_SIGNAL, 0);
|
||||
}
|
||||
|
@ -51,7 +51,8 @@ public class AdvancedPortalsVelocityPlugin {
|
||||
public void onPluginMessage(PluginMessageEvent event) {
|
||||
if (event.getIdentifier().equals(AP_CHANNEL)) {
|
||||
if (event.getSource()
|
||||
instanceof ServerConnection serverConnection) {
|
||||
instanceof ServerConnection) {
|
||||
ServerConnection serverConnection = (ServerConnection) event.getSource();
|
||||
this.proxyCore.incomingMessage(
|
||||
new VelocityProxyPlayerContainer(
|
||||
serverConnection.getPlayer(), AP_CHANNEL),
|
||||
|
@ -16,7 +16,9 @@ public class VelocityProxyContainer implements ProxyContainer {
|
||||
public void invokeCommand(ProxyPlayerContainer proxyPlayer,
|
||||
String command) {
|
||||
if (proxyPlayer
|
||||
instanceof VelocityProxyPlayerContainer playerContainer) {
|
||||
instanceof VelocityProxyPlayerContainer) {
|
||||
VelocityProxyPlayerContainer playerContainer
|
||||
= (VelocityProxyPlayerContainer) proxyPlayer;
|
||||
this.proxy.getCommandManager().executeAsync(
|
||||
playerContainer.getPlayer(), command);
|
||||
}
|
||||
@ -26,19 +28,18 @@ public class VelocityProxyContainer implements ProxyContainer {
|
||||
public void transferPlayer(ProxyPlayerContainer proxyPlayer,
|
||||
String serverName) {
|
||||
if (proxyPlayer
|
||||
instanceof VelocityProxyPlayerContainer playerContainer) {
|
||||
this.proxy.getServer(serverName)
|
||||
.ifPresentOrElse(
|
||||
server
|
||||
-> {
|
||||
playerContainer.getPlayer()
|
||||
.createConnectionRequest(server)
|
||||
.fireAndForget();
|
||||
},
|
||||
()
|
||||
-> playerContainer.getPlayer().sendMessage(
|
||||
Component.text("Could not find server: "
|
||||
+ serverName)));
|
||||
instanceof VelocityProxyPlayerContainer) {
|
||||
VelocityProxyPlayerContainer playerContainer
|
||||
= (VelocityProxyPlayerContainer) proxyPlayer;
|
||||
this.proxy.getServer(serverName);
|
||||
if (this.proxy.getServer(serverName).isPresent()) {
|
||||
playerContainer.getPlayer()
|
||||
.createConnectionRequest(this.proxy.getServer(serverName).get())
|
||||
.fireAndForget();
|
||||
} else {
|
||||
playerContainer.getPlayer().sendMessage(
|
||||
Component.text("Could not find server: " + serverName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user