mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-24 11:37:06 +01:00
chore: switch to using clang format
This commit is contained in:
parent
c0cdcc327d
commit
79c935a931
11
.clang-format
Normal file
11
.clang-format
Normal file
@ -0,0 +1,11 @@
|
||||
BasedOnStyle: Google
|
||||
IndentWidth: 4
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
BreakBeforeBraces: Attach
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
AlignAfterOpenBracket: Align
|
||||
PenaltyBreakBeforeFirstCallParameter: 1
|
||||
ColumnLimit: 80
|
6
.github/workflows/pre-commit-check.yaml
vendored
6
.github/workflows/pre-commit-check.yaml
vendored
@ -18,12 +18,6 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
|
||||
- uses: dorny/paths-filter@v2
|
||||
id: filter
|
||||
with:
|
||||
|
@ -1,7 +1,7 @@
|
||||
# See https://pre-commit.com for more information
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.0.1
|
||||
rev: v4.6.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
@ -11,7 +11,7 @@ repos:
|
||||
- id: check-case-conflict
|
||||
|
||||
- repo: https://github.com/Lucas-C/pre-commit-hooks
|
||||
rev: v1.1.10
|
||||
rev: v1.5.5
|
||||
hooks:
|
||||
- id: remove-crlf
|
||||
- id: remove-tabs
|
||||
@ -19,9 +19,13 @@ repos:
|
||||
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
|
||||
rev: v2.13.0
|
||||
hooks:
|
||||
- id: pretty-format-java
|
||||
args: [--autofix, --aosp, --google-java-formatter-version=1.16.0]
|
||||
- id: pretty-format-yaml
|
||||
args: [--autofix]
|
||||
- id: pretty-format-toml
|
||||
args: [--autofix]
|
||||
|
||||
- repo: https://github.com/pocc/pre-commit-hooks
|
||||
rev: v1.3.5
|
||||
hooks:
|
||||
- id: clang-format
|
||||
args: [-i, --style=file]
|
||||
|
@ -20,12 +20,10 @@ import com.sekwah.advancedportals.core.tags.activation.*;
|
||||
import com.sekwah.advancedportals.core.util.GameScheduler;
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class AdvancedPortalsCore {
|
||||
|
||||
public static final String version = "1.0.0";
|
||||
|
||||
private final InfoLogger infoLogger;
|
||||
@ -34,8 +32,8 @@ public class AdvancedPortalsCore {
|
||||
private final AdvancedPortalsModule module;
|
||||
|
||||
/**
|
||||
* Use this to enable or alter certain features for different versions. If there is an issue
|
||||
* parsing it for any reason it will be set to 0.0.0
|
||||
* Use this to enable or alter certain features for different versions. If
|
||||
* there is an issue parsing it for any reason it will be set to 0.0.0
|
||||
*/
|
||||
private final int[] mcVersion;
|
||||
|
||||
@ -63,9 +61,7 @@ public class AdvancedPortalsCore {
|
||||
// TEMP REMOVE THIS THIS IS JUST FOR DEV
|
||||
@Inject private IPlayerDataRepository tempDataRepository;
|
||||
|
||||
public AdvancedPortalsCore(
|
||||
String mcVersion,
|
||||
File dataStorageLoc,
|
||||
public AdvancedPortalsCore(String mcVersion, File dataStorageLoc,
|
||||
InfoLogger infoLogger,
|
||||
ServerContainer serverContainer) {
|
||||
instance = this;
|
||||
@ -74,10 +70,12 @@ public class AdvancedPortalsCore {
|
||||
this.infoLogger = infoLogger;
|
||||
|
||||
int[] mcVersionTemp;
|
||||
infoLogger.info("Loading Advanced Portals Core v" + version + " for MC: " + mcVersion);
|
||||
infoLogger.info("Loading Advanced Portals Core v" + version
|
||||
+ " for MC: " + mcVersion);
|
||||
try {
|
||||
mcVersionTemp =
|
||||
Arrays.stream(mcVersion.split("\\.")).mapToInt(Integer::parseInt).toArray();
|
||||
mcVersionTemp = Arrays.stream(mcVersion.split("\\."))
|
||||
.mapToInt(Integer::parseInt)
|
||||
.toArray();
|
||||
} catch (NumberFormatException e) {
|
||||
infoLogger.info("Failed to parse MC version: " + mcVersion);
|
||||
e.printStackTrace();
|
||||
@ -92,13 +90,13 @@ public class AdvancedPortalsCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* For some platforms we could do this on construction but this just allows for a bit more
|
||||
* control
|
||||
* For some platforms we could do this on construction but this just allows
|
||||
* for a bit more control
|
||||
*/
|
||||
public void onEnable() {
|
||||
// Force values to get injected, either because the initial ones were created too early or
|
||||
// to ensure they are not null.
|
||||
// Do it here to give implementations a chance to interact with the module.
|
||||
// Force values to get injected, either because the initial ones were
|
||||
// created too early or to ensure they are not null. Do it here to give
|
||||
// implementations a chance to interact with the module.
|
||||
Injector injector = module.getInjector();
|
||||
injector.injectMembers(this);
|
||||
injector.injectMembers(Lang.instance);
|
||||
@ -124,7 +122,8 @@ public class AdvancedPortalsCore {
|
||||
this.tagRegistry.registerTag(new PermissionTag());
|
||||
}
|
||||
|
||||
/** */
|
||||
/**
|
||||
*/
|
||||
public void registerCommands() {
|
||||
this.registerPortalCommand(commandRegister);
|
||||
this.registerDestinationCommand(commandRegister);
|
||||
@ -133,43 +132,61 @@ public class AdvancedPortalsCore {
|
||||
private void registerPortalCommand(CommandRegister commandRegister) {
|
||||
this.portalCommand = new CommandWithSubCommands(this);
|
||||
|
||||
this.portalCommand.registerSubCommand("version", new VersionSubCommand());
|
||||
this.portalCommand.registerSubCommand("langupdate", new LangUpdateSubCommand());
|
||||
this.portalCommand.registerSubCommand("reload", new ReloadPortalSubCommand());
|
||||
this.portalCommand.registerSubCommand("selector", new SelectorSubCommand(), "wand");
|
||||
this.portalCommand.registerSubCommand("portalblock", new PortalBlockSubCommand());
|
||||
this.portalCommand.registerSubCommand("endportalblock", new EndPortalBlockSubCommand());
|
||||
this.portalCommand.registerSubCommand("endgatewayblock", new EndGatewayBlockSubCommand());
|
||||
this.portalCommand.registerSubCommand("create", new CreatePortalSubCommand());
|
||||
this.portalCommand.registerSubCommand("remove", new RemovePortalSubCommand());
|
||||
this.portalCommand.registerSubCommand("list", new ListPortalsSubCommand());
|
||||
this.portalCommand.registerSubCommand("show", new ShowPortalSubCommand());
|
||||
this.portalCommand.registerSubCommand("version",
|
||||
new VersionSubCommand());
|
||||
this.portalCommand.registerSubCommand("langupdate",
|
||||
new LangUpdateSubCommand());
|
||||
this.portalCommand.registerSubCommand("reload",
|
||||
new ReloadPortalSubCommand());
|
||||
this.portalCommand.registerSubCommand("selector",
|
||||
new SelectorSubCommand(), "wand");
|
||||
this.portalCommand.registerSubCommand("portalblock",
|
||||
new PortalBlockSubCommand());
|
||||
this.portalCommand.registerSubCommand("endportalblock",
|
||||
new EndPortalBlockSubCommand());
|
||||
this.portalCommand.registerSubCommand("endgatewayblock",
|
||||
new EndGatewayBlockSubCommand());
|
||||
this.portalCommand.registerSubCommand("create",
|
||||
new CreatePortalSubCommand());
|
||||
this.portalCommand.registerSubCommand("remove",
|
||||
new RemovePortalSubCommand());
|
||||
this.portalCommand.registerSubCommand("list",
|
||||
new ListPortalsSubCommand());
|
||||
this.portalCommand.registerSubCommand("show",
|
||||
new ShowPortalSubCommand());
|
||||
|
||||
commandRegister.registerCommand("portal", this.portalCommand);
|
||||
}
|
||||
|
||||
private void registerDestinationCommand(CommandRegister commandRegister) {
|
||||
this.destiCommand = new CommandWithSubCommands(this);
|
||||
this.destiCommand.registerSubCommand("create", new CreateDestiSubCommand());
|
||||
this.destiCommand.registerSubCommand("remove", new RemoveDestiSubCommand());
|
||||
this.destiCommand.registerSubCommand("teleport", new TeleportDestiSubCommand(), "tp");
|
||||
this.destiCommand.registerSubCommand("create",
|
||||
new CreateDestiSubCommand());
|
||||
this.destiCommand.registerSubCommand("remove",
|
||||
new RemoveDestiSubCommand());
|
||||
this.destiCommand.registerSubCommand(
|
||||
"teleport", new TeleportDestiSubCommand(), "tp");
|
||||
this.destiCommand.registerSubCommand("list", new ListDestiSubCommand());
|
||||
this.destiCommand.registerSubCommand("show", new ShowDestiSubCommand());
|
||||
|
||||
commandRegister.registerCommand("destination", this.destiCommand);
|
||||
}
|
||||
|
||||
public boolean registerPortalCommand(String arg, SubCommand subCommand, String... aliasArgs) {
|
||||
return this.portalCommand.registerSubCommand(arg, subCommand, aliasArgs);
|
||||
public boolean registerPortalCommand(String arg, SubCommand subCommand,
|
||||
String... aliasArgs) {
|
||||
return this.portalCommand.registerSubCommand(arg, subCommand,
|
||||
aliasArgs);
|
||||
}
|
||||
|
||||
public boolean registerDestiCommand(String arg, SubCommand subCommand, String... aliasArgs) {
|
||||
public boolean registerDestiCommand(String arg, SubCommand subCommand,
|
||||
String... aliasArgs) {
|
||||
return this.destiCommand.registerSubCommand(arg, subCommand, aliasArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the portal config into the memory and saves from the memory to check in case certain
|
||||
* things have changed (basically if values are missing or whatever)
|
||||
* Loads the portal config into the memory and saves from the memory to
|
||||
* check in case certain things have changed (basically if values are
|
||||
* missing or whatever)
|
||||
*/
|
||||
public void loadPortalConfig() {
|
||||
this.configRepository.loadConfig(this.dataStorage);
|
||||
|
@ -6,30 +6,24 @@ import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.connector.containers.WorldContainer;
|
||||
import com.sekwah.advancedportals.core.data.BlockAxis;
|
||||
import com.sekwah.advancedportals.core.data.Direction;
|
||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.services.PortalServices;
|
||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
||||
import com.sekwah.advancedportals.core.services.PortalServices;
|
||||
import com.sekwah.advancedportals.core.util.GameScheduler;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class CoreListeners {
|
||||
@Inject private PlayerDataServices playerDataServices;
|
||||
|
||||
@Inject
|
||||
private PlayerDataServices playerDataServices;
|
||||
@Inject private PortalServices portalServices;
|
||||
|
||||
@Inject
|
||||
private PortalServices portalServices;
|
||||
@Inject private ConfigRepository configRepository;
|
||||
|
||||
@Inject
|
||||
private ConfigRepository configRepository;
|
||||
|
||||
@Inject
|
||||
private GameScheduler gameScheduler;
|
||||
@Inject private GameScheduler gameScheduler;
|
||||
|
||||
public void playerJoin(PlayerContainer player) {
|
||||
this.playerDataServices.setJoinCooldown(player);
|
||||
@ -56,19 +50,24 @@ public class CoreListeners {
|
||||
}
|
||||
|
||||
/**
|
||||
* If the block is indirectly broken it will also take null for the player e.g. with tnt
|
||||
* If the block is indirectly broken it will also take null for the player
|
||||
* e.g. with tnt
|
||||
*
|
||||
* @player player causing the event (or null if not a player)
|
||||
* @param blockPos
|
||||
* @param blockMaterial
|
||||
* @return if the block is allowed to break
|
||||
*/
|
||||
public boolean blockBreak(PlayerContainer player, BlockLocation blockPos, String blockMaterial, String itemInHandMaterial, String itemInHandName) {
|
||||
if(player == null) {
|
||||
public boolean blockBreak(PlayerContainer player, BlockLocation blockPos,
|
||||
String blockMaterial, String itemInHandMaterial,
|
||||
String itemInHandName) {
|
||||
if (player == null) {
|
||||
return !portalServices.inPortalRegionProtected(blockPos);
|
||||
}
|
||||
if(!(PortalPermissions.BUILD.hasPermission(player) || !portalServices.inPortalRegionProtected(blockPos))) {
|
||||
player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("portal.nobuild"));
|
||||
if (!(PortalPermissions.BUILD.hasPermission(player)
|
||||
|| !portalServices.inPortalRegionProtected(blockPos))) {
|
||||
player.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("portal.nobuild"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -80,33 +79,36 @@ public class CoreListeners {
|
||||
* @param blockMaterial
|
||||
* @return if the block is allowed to be placed
|
||||
*/
|
||||
public boolean blockPlace(PlayerContainer player, BlockLocation blockPos, String blockMaterial, String itemInHandMaterial, String itemInHandName) {
|
||||
if(player != null && PortalPermissions.BUILD.hasPermission(player)) {
|
||||
public boolean blockPlace(PlayerContainer player, BlockLocation blockPos,
|
||||
String blockMaterial, String itemInHandMaterial,
|
||||
String itemInHandName) {
|
||||
if (player != null && PortalPermissions.BUILD.hasPermission(player)) {
|
||||
WorldContainer world = player.getWorld();
|
||||
if(itemInHandName.equals("\u00A75Portal Block Placer")) {
|
||||
if (itemInHandName.equals("\u00A75Portal Block Placer")) {
|
||||
world.setBlock(blockPos, "NETHER_PORTAL");
|
||||
for (Direction direction : Direction.values()) {
|
||||
var checkLoc = new BlockLocation(blockPos, direction);
|
||||
if (world.getBlock(checkLoc).equals("NETHER_PORTAL")) {
|
||||
world.setBlockAxis(blockPos, world.getBlockAxis(checkLoc));
|
||||
world.setBlockAxis(blockPos,
|
||||
world.getBlockAxis(checkLoc));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(itemInHandName.equals("\u00A78End Portal Block Placer")) {
|
||||
} else if (itemInHandName.equals(
|
||||
"\u00A78End Portal Block Placer")) {
|
||||
world.setBlock(blockPos, "END_PORTAL");
|
||||
return true;
|
||||
}
|
||||
else if(itemInHandName.equals("\u00A78Gateway Block Placer")) {
|
||||
} else if (itemInHandName.equals("\u00A78Gateway Block Placer")) {
|
||||
world.setBlock(blockPos, "END_GATEWAY");
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if(portalServices.inPortalRegionProtected(blockPos)) {
|
||||
if(player != null) {
|
||||
player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("portal.nobuild"));
|
||||
if (portalServices.inPortalRegionProtected(blockPos)) {
|
||||
if (player != null) {
|
||||
player.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("portal.nobuild"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -119,7 +121,8 @@ public class CoreListeners {
|
||||
* @param blockPos
|
||||
* @return
|
||||
*/
|
||||
public boolean blockInteract(PlayerContainer player, BlockLocation blockPos) {
|
||||
public boolean blockInteract(PlayerContainer player,
|
||||
BlockLocation blockPos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -129,25 +132,33 @@ public class CoreListeners {
|
||||
* @param leftClick true = left click, false = right click
|
||||
* @return if player is allowed to interact with block
|
||||
*/
|
||||
public boolean playerInteractWithBlock(PlayerContainer player, String blockMaterialname, String itemMaterialName, String itemName,
|
||||
BlockLocation blockLoc, boolean leftClick) {
|
||||
if(itemName != null && (player.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(player)) &&
|
||||
itemMaterialName.equalsIgnoreCase(this.configRepository.getSelectorMaterial())
|
||||
&& (!this.configRepository.getUseOnlySpecialAxe() || itemName.equals("\u00A7ePortal Region Selector"))) {
|
||||
this.playerDataServices.playerSelectorActivate(player, blockLoc, leftClick);
|
||||
public boolean playerInteractWithBlock(PlayerContainer player,
|
||||
String blockMaterialname,
|
||||
String itemMaterialName,
|
||||
String itemName,
|
||||
BlockLocation blockLoc,
|
||||
boolean leftClick) {
|
||||
if (itemName != null
|
||||
&& (player.isOp()
|
||||
|| PortalPermissions.CREATE_PORTAL.hasPermission(player))
|
||||
&& itemMaterialName.equalsIgnoreCase(
|
||||
this.configRepository.getSelectorMaterial())
|
||||
&& (!this.configRepository.getUseOnlySpecialAxe()
|
||||
|| itemName.equals("\u00A7ePortal Region Selector"))) {
|
||||
this.playerDataServices.playerSelectorActivate(player, blockLoc,
|
||||
leftClick);
|
||||
return false;
|
||||
}
|
||||
else if(itemName != null && leftClick &&
|
||||
Objects.equals(itemMaterialName, "PURPLE_WOOL") &&
|
||||
itemName.equals("\u00A75Portal Block Placer") && PortalPermissions.BUILD.hasPermission(player)) {
|
||||
if(!Objects.equals(blockMaterialname, "NETHER_PORTAL")) {
|
||||
} else if (itemName != null && leftClick
|
||||
&& Objects.equals(itemMaterialName, "PURPLE_WOOL")
|
||||
&& itemName.equals("\u00A75Portal Block Placer")
|
||||
&& PortalPermissions.BUILD.hasPermission(player)) {
|
||||
if (!Objects.equals(blockMaterialname, "NETHER_PORTAL")) {
|
||||
return false;
|
||||
}
|
||||
WorldContainer world = player.getWorld();
|
||||
if(world.getBlockAxis(blockLoc) == BlockAxis.X) {
|
||||
if (world.getBlockAxis(blockLoc) == BlockAxis.X) {
|
||||
world.setBlockAxis(blockLoc, BlockAxis.Z);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
world.setBlockAxis(blockLoc, BlockAxis.X);
|
||||
}
|
||||
return false;
|
||||
@ -166,14 +177,15 @@ public class CoreListeners {
|
||||
|
||||
public boolean entityPortalEvent(EntityContainer entity) {
|
||||
var pos = entity.getBlockLoc();
|
||||
if(entity instanceof PlayerContainer player) {
|
||||
if (entity instanceof PlayerContainer player) {
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
if(playerData.isNetherPortalCooldown()) {
|
||||
if (playerData.isNetherPortalCooldown()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
var feetInPortal = portalServices.inPortalRegion(pos, 1);
|
||||
var headInPortal = portalServices.inPortalRegion(pos.addY((int) entity.getHeight()), 1);
|
||||
var headInPortal = portalServices.inPortalRegion(
|
||||
pos.addY((int) entity.getHeight()), 1);
|
||||
return !(feetInPortal || headInPortal);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.sekwah.advancedportals.core.commands;
|
||||
|
||||
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -11,13 +10,14 @@ import java.util.List;
|
||||
* https://docs.spongepowered.org/stable/en/plugin/commands/arguments.html#custom-command-elements
|
||||
*/
|
||||
public interface CommandTemplate {
|
||||
|
||||
void onCommand(CommandSenderContainer sender, String commandExecuted, String[] args);
|
||||
void onCommand(CommandSenderContainer sender, String commandExecuted,
|
||||
String[] args);
|
||||
|
||||
/**
|
||||
* Fired when someone asks for a tab complete action.
|
||||
*
|
||||
* @param sender whoever triggered the command e.g. command block, server or player
|
||||
* @param sender whoever triggered the command e.g. command block, server or
|
||||
* player
|
||||
* @param args arguments for the command
|
||||
* @return a lot of strings that are possible completions
|
||||
*/
|
||||
|
@ -4,14 +4,12 @@ import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
|
||||
import com.sekwah.advancedportals.core.registry.SubCommandRegistry;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandWithSubCommands implements CommandTemplate {
|
||||
|
||||
private final SubCommandRegistry subCommandRegistry;
|
||||
|
||||
private final int subCommandsPerPage = 7;
|
||||
@ -22,128 +20,163 @@ public class CommandWithSubCommands implements CommandTemplate {
|
||||
this.pluginCore = advancedPortalsCore;
|
||||
}
|
||||
|
||||
public boolean registerSubCommand(String arg, SubCommand subCommand, String... aliasArgs) {
|
||||
public boolean registerSubCommand(String arg, SubCommand subCommand,
|
||||
String... aliasArgs) {
|
||||
pluginCore.getModule().getInjector().injectMembers(subCommand);
|
||||
boolean hasRegistered = false;
|
||||
for(String additionalArg : aliasArgs) {
|
||||
hasRegistered = this.subCommandRegistry.registerSubCommand(additionalArg,subCommand) || hasRegistered;
|
||||
for (String additionalArg : aliasArgs) {
|
||||
hasRegistered = this.subCommandRegistry.registerSubCommand(
|
||||
additionalArg, subCommand)
|
||||
|| hasRegistered;
|
||||
}
|
||||
boolean result = this.subCommandRegistry.registerSubCommand(arg,subCommand) || hasRegistered;
|
||||
if(subCommand instanceof SubCommand.SubCommandOnInit init) {
|
||||
boolean result =
|
||||
this.subCommandRegistry.registerSubCommand(arg, subCommand)
|
||||
|| hasRegistered;
|
||||
if (subCommand instanceof SubCommand.SubCommandOnInit init) {
|
||||
init.registered();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ArrayList<String> getSubCommands(){
|
||||
public ArrayList<String> getSubCommands() {
|
||||
return this.subCommandRegistry.getSubCommands();
|
||||
}
|
||||
|
||||
public boolean isArgRegistered(String arg){
|
||||
public boolean isArgRegistered(String arg) {
|
||||
return this.subCommandRegistry.isArgRegistered(arg);
|
||||
}
|
||||
|
||||
public SubCommand getSubCommand(String arg){
|
||||
public SubCommand getSubCommand(String arg) {
|
||||
return this.subCommandRegistry.getSubCommand(arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String commandExecuted, String[] args) {
|
||||
if(args.length > 0) {
|
||||
if(args[0].equalsIgnoreCase("help")) {
|
||||
public void onCommand(CommandSenderContainer sender, String commandExecuted,
|
||||
String[] args) {
|
||||
if (args.length > 0) {
|
||||
if (args[0].equalsIgnoreCase("help")) {
|
||||
int helpPage = 1;
|
||||
String[] subCommands = this.subCommandRegistry.getSubCommands().toArray(new String[0]);
|
||||
int pages = (int) Math.ceil(subCommands.length / (float) this.subCommandsPerPage);
|
||||
String command = commandExecuted.substring(0, 1).toUpperCase() + commandExecuted.substring(1).toLowerCase();
|
||||
if(args.length > 1) {
|
||||
String[] subCommands =
|
||||
this.subCommandRegistry.getSubCommands().toArray(
|
||||
new String[0]);
|
||||
int pages = (int) Math.ceil(subCommands.length
|
||||
/ (float) this.subCommandsPerPage);
|
||||
String command = commandExecuted.substring(0, 1).toUpperCase()
|
||||
+ commandExecuted.substring(1).toLowerCase();
|
||||
if (args.length > 1) {
|
||||
try {
|
||||
helpPage = Integer.parseInt(args[1]);
|
||||
if(helpPage > pages) {
|
||||
if (helpPage > pages) {
|
||||
helpPage = pages;
|
||||
}
|
||||
if(helpPage <= 0) {
|
||||
if (helpPage <= 0) {
|
||||
helpPage = 1;
|
||||
}
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
} catch (NumberFormatException e) {
|
||||
String subCommand = args[1].toLowerCase();
|
||||
if(this.subCommandRegistry.isArgRegistered(subCommand)) {
|
||||
if (this.subCommandRegistry.isArgRegistered(
|
||||
subCommand)) {
|
||||
sender.sendMessage("");
|
||||
var helpTitle = Lang.centeredTitle(Lang.translateInsertVariables("command.help.subcommandheader",
|
||||
command, subCommand));
|
||||
var helpTitle = Lang.centeredTitle(
|
||||
Lang.translateInsertVariables(
|
||||
"command.help.subcommandheader", command,
|
||||
subCommand));
|
||||
sender.sendMessage(helpTitle);
|
||||
sender.sendMessage("\u00A77" + this.getSubCommand(subCommand).getDetailedHelpText());
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translateInsertVariables("command.help.invalidhelp", args[1]));
|
||||
sender.sendMessage("\u00A77"
|
||||
+ this.getSubCommand(subCommand)
|
||||
.getDetailedHelpText());
|
||||
} else {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
+ Lang.translateInsertVariables(
|
||||
"command.help.invalidhelp", args[1]));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
sender.sendMessage("");
|
||||
|
||||
var helpTitle = Lang.centeredTitle(Lang.translateInsertVariables("command.help.header",
|
||||
command, helpPage, pages));
|
||||
var helpTitle =
|
||||
Lang.centeredTitle(Lang.translateInsertVariables(
|
||||
"command.help.header", command, helpPage, pages));
|
||||
|
||||
sender.sendMessage(helpTitle);
|
||||
sender.sendMessage("\u00A7a█\u00A77 = Permission \u00A7c█\u00A77 = No Permission");
|
||||
sender.sendMessage(
|
||||
"\u00A7a█\u00A77 = Permission \u00A7c█\u00A77 "
|
||||
+ "= No Permission");
|
||||
int subCommandOffset = (helpPage - 1) * this.subCommandsPerPage;
|
||||
int displayEnd = subCommandOffset + this.subCommandsPerPage;
|
||||
if(displayEnd > subCommands.length) {
|
||||
if (displayEnd > subCommands.length) {
|
||||
displayEnd = subCommands.length;
|
||||
}
|
||||
for(; subCommandOffset < displayEnd; subCommandOffset++) {
|
||||
SubCommand subCommand = this.getSubCommand(subCommands[subCommandOffset]);
|
||||
String colorCode = "\u00A7" + (subCommand.hasPermission(sender) ? "a" : "c");
|
||||
sender.sendMessage("\u00A7e/" + commandExecuted + " " + subCommands[subCommandOffset]
|
||||
+ colorCode + " - " + subCommand.getBasicHelpText());
|
||||
for (; subCommandOffset < displayEnd; subCommandOffset++) {
|
||||
SubCommand subCommand =
|
||||
this.getSubCommand(subCommands[subCommandOffset]);
|
||||
String colorCode = "\u00A7"
|
||||
+ (subCommand.hasPermission(sender) ? "a" : "c");
|
||||
sender.sendMessage("\u00A7e/" + commandExecuted + " "
|
||||
+ subCommands[subCommandOffset]
|
||||
+ colorCode + " - "
|
||||
+ subCommand.getBasicHelpText());
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(String subCommandName : this.subCommandRegistry.getSubCommands()) {
|
||||
if(subCommandName.equalsIgnoreCase(args[0])) {
|
||||
SubCommand subCommand = this.getSubCommand(subCommandName);
|
||||
if(subCommand.hasPermission(sender)) {
|
||||
} else {
|
||||
for (String subCommandName :
|
||||
this.subCommandRegistry.getSubCommands()) {
|
||||
if (subCommandName.equalsIgnoreCase(args[0])) {
|
||||
SubCommand subCommand =
|
||||
this.getSubCommand(subCommandName);
|
||||
if (subCommand.hasPermission(sender)) {
|
||||
subCommand.onCommand(sender, args);
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translateInsertVariables("command.subcommand.nopermission",
|
||||
} else {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
+ Lang.translateInsertVariables(
|
||||
"command.subcommand.nopermission",
|
||||
commandExecuted));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.subcommand.invalid"));
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("command.subcommand.invalid"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translateInsertVariables("command.noargs", commandExecuted));
|
||||
} else {
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translateInsertVariables(
|
||||
"command.noargs", commandExecuted));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
if(args.length > 1) {
|
||||
if(args[0].equalsIgnoreCase("help")) {
|
||||
List<String> allowedCommands = new ArrayList<>(this.subCommandRegistry.getSubCommands());
|
||||
int pages = (int) Math.ceil(allowedCommands.size() / (float) this.subCommandsPerPage);
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
if (args.length > 1) {
|
||||
if (args[0].equalsIgnoreCase("help")) {
|
||||
List<String> allowedCommands =
|
||||
new ArrayList<>(this.subCommandRegistry.getSubCommands());
|
||||
int pages = (int) Math.ceil(allowedCommands.size()
|
||||
/ (float) this.subCommandsPerPage);
|
||||
for (int i = 1; i <= pages; i++) {
|
||||
allowedCommands.add(String.valueOf(i));
|
||||
}
|
||||
Collections.sort(allowedCommands);
|
||||
return this.filterTabResults(allowedCommands, args[args.length - 1]);
|
||||
}
|
||||
else {
|
||||
for (String subCommandName : this.subCommandRegistry.getSubCommands()) {
|
||||
if (subCommandName.equalsIgnoreCase(args[0])) {
|
||||
SubCommand subCommand = this.getSubCommand(subCommandName);
|
||||
if (subCommand.hasPermission(sender)) {
|
||||
List<String> tabComplete = this.filterTabResults(this.getSubCommand(subCommandName).onTabComplete(sender, args),
|
||||
return this.filterTabResults(allowedCommands,
|
||||
args[args.length - 1]);
|
||||
if(tabComplete != null) {
|
||||
} else {
|
||||
for (String subCommandName :
|
||||
this.subCommandRegistry.getSubCommands()) {
|
||||
if (subCommandName.equalsIgnoreCase(args[0])) {
|
||||
SubCommand subCommand =
|
||||
this.getSubCommand(subCommandName);
|
||||
if (subCommand.hasPermission(sender)) {
|
||||
List<String> tabComplete = this.filterTabResults(
|
||||
this.getSubCommand(subCommandName)
|
||||
.onTabComplete(sender, args),
|
||||
args[args.length - 1]);
|
||||
if (tabComplete != null) {
|
||||
return tabComplete;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
} else {
|
||||
@ -152,12 +185,12 @@ public class CommandWithSubCommands implements CommandTemplate {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
List<String> allowedCommands = new ArrayList<>();
|
||||
for (String subCommandName : this.subCommandRegistry.getSubCommands()) {
|
||||
for (String subCommandName :
|
||||
this.subCommandRegistry.getSubCommands()) {
|
||||
SubCommand subCommand = this.getSubCommand(subCommandName);
|
||||
if(subCommand.hasPermission(sender)) {
|
||||
if (subCommand.hasPermission(sender)) {
|
||||
allowedCommands.add(subCommandName);
|
||||
}
|
||||
}
|
||||
@ -169,7 +202,7 @@ public class CommandWithSubCommands implements CommandTemplate {
|
||||
}
|
||||
|
||||
public List<String> filterTabResults(List<String> tabList, String lastArg) {
|
||||
if(tabList == null) {
|
||||
if (tabList == null) {
|
||||
return null;
|
||||
}
|
||||
return tabList.stream()
|
||||
|
@ -1,16 +1,14 @@
|
||||
package com.sekwah.advancedportals.core.commands;
|
||||
|
||||
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SubCommand {
|
||||
|
||||
/**
|
||||
* @param sender
|
||||
* @param args arguments including the subcommand that has been specified.
|
||||
* @return if the command has worked (if false it will just display a message from the command
|
||||
* suggesting to check help)
|
||||
* @return if the command has worked (if false it will just display a
|
||||
* message from the command suggesting to check help)
|
||||
*/
|
||||
void onCommand(CommandSenderContainer sender, String[] args);
|
||||
|
||||
|
@ -5,7 +5,6 @@ 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;
|
||||
@ -13,34 +12,36 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class CreateTaggedSubCommand implements SubCommand {
|
||||
|
||||
protected abstract List<Tag> getRelatedTags();
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
|
||||
if(TagReader.isClosedString(args)) {
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
if (TagReader.isClosedString(args)) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
List<Tag> allTags = this.getRelatedTags();
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
if(args.length > 0) {
|
||||
if (args.length > 0) {
|
||||
var lastArg = args[args.length - 1];
|
||||
// Check if the split results in exactly 2 or if its 1 and ends with :
|
||||
// Check if the split results in exactly 2 or if its 1 and ends
|
||||
// with :
|
||||
var 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) {
|
||||
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;
|
||||
if(lastArg.startsWith(tag.getName())) {
|
||||
if (lastArg.startsWith(tag.getName())) {
|
||||
startsWith = true;
|
||||
} else {
|
||||
var aliases = tag.getAliases();
|
||||
if(aliases != null) {
|
||||
if (aliases != null) {
|
||||
for (String alias : aliases) {
|
||||
if(lastArg.startsWith(alias)) {
|
||||
if (lastArg.startsWith(alias)) {
|
||||
startsWith = true;
|
||||
break;
|
||||
}
|
||||
@ -48,33 +49,52 @@ public abstract class CreateTaggedSubCommand implements SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
if(tag instanceof Tag.AutoComplete autoComplete && startsWith) {
|
||||
if (tag instanceof Tag.AutoComplete autoComplete
|
||||
&& startsWith) {
|
||||
var argData = split.length == 2 ? split[1] : "";
|
||||
var tagSuggestions = autoComplete.autoComplete(argData);
|
||||
|
||||
if(tagSuggestions != null) {
|
||||
if(tag instanceof Tag.Split splitTag) {
|
||||
if (tagSuggestions != null) {
|
||||
if (tag instanceof Tag.Split splitTag) {
|
||||
var multiTagSplit = splitTag.splitString();
|
||||
boolean endsWithSplit = argData.endsWith(multiTagSplit);
|
||||
boolean endsWithSplit =
|
||||
argData.endsWith(multiTagSplit);
|
||||
String[] items = argData.split(multiTagSplit);
|
||||
Set<String> existingItems = Arrays.stream(items, 0, endsWithSplit ? items.length : items.length - 1)
|
||||
Set<String> existingItems =
|
||||
Arrays
|
||||
.stream(items, 0,
|
||||
endsWithSplit
|
||||
? items.length
|
||||
: items.length - 1)
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
String partialInput = endsWithSplit ? "" : items[items.length - 1].trim();
|
||||
String baseString = endsWithSplit ? argData : argData.substring(0, argData.lastIndexOf(multiTagSplit) + 1);
|
||||
String partialInput = endsWithSplit
|
||||
? ""
|
||||
: items[items.length - 1].trim();
|
||||
String baseString = endsWithSplit
|
||||
? argData
|
||||
: argData.substring(
|
||||
0,
|
||||
argData.lastIndexOf(multiTagSplit)
|
||||
+ 1);
|
||||
|
||||
tagSuggestions = tagSuggestions.stream()
|
||||
tagSuggestions =
|
||||
tagSuggestions
|
||||
.stream()
|
||||
// Remove already listed items
|
||||
.filter(s -> !existingItems.contains(s))
|
||||
// Remove items that don't match the currently typed input
|
||||
// Remove items that don't match the
|
||||
// currently typed input
|
||||
.filter(s -> s.startsWith(partialInput))
|
||||
// Remap so the auto completes actually show
|
||||
// Remap so the auto completes actually
|
||||
// show
|
||||
.map(s -> baseString + s)
|
||||
.toList();
|
||||
}
|
||||
|
||||
// Loop over suggestions and add split[0] + ":" to the start
|
||||
// Loop over suggestions and add split[0] + ":" to
|
||||
// the start
|
||||
for (String tagSuggestion : tagSuggestions) {
|
||||
suggestions.add(split[0] + ":" + tagSuggestion);
|
||||
}
|
||||
@ -88,25 +108,27 @@ public abstract class CreateTaggedSubCommand implements SubCommand {
|
||||
|
||||
ArrayList<DataTag> tagsFromArgs = TagReader.getTagsFromArgs(args);
|
||||
|
||||
allTags.stream().filter(tag -> {
|
||||
allTags.stream()
|
||||
.filter(tag -> {
|
||||
for (DataTag argTag : tagsFromArgs) {
|
||||
if(argTag.NAME.equals(tag.getName())) {
|
||||
if (argTag.NAME.equals(tag.getName())) {
|
||||
return false;
|
||||
}
|
||||
var aliases = tag.getAliases();
|
||||
if(aliases != null) {
|
||||
if (aliases != null) {
|
||||
for (String alias : aliases) {
|
||||
if(argTag.NAME.equals(alias)) {
|
||||
if (argTag.NAME.equals(alias)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}).forEach(tag -> {
|
||||
})
|
||||
.forEach(tag -> {
|
||||
suggestions.add(tag.getName());
|
||||
var aliases = tag.getAliases();
|
||||
if(aliases != null) {
|
||||
if (aliases != null) {
|
||||
suggestions.addAll(Arrays.stream(aliases).toList());
|
||||
}
|
||||
});
|
||||
@ -125,24 +147,34 @@ public abstract class CreateTaggedSubCommand implements SubCommand {
|
||||
|
||||
for (var dataTag : dataTags) {
|
||||
for (Tag tag : relatedTags) {
|
||||
if(tag instanceof Tag.Split splitTag) {
|
||||
if (tag instanceof Tag.Split splitTag) {
|
||||
var splitString = splitTag.splitString();
|
||||
if(splitString != null) {
|
||||
if (splitString != null) {
|
||||
List<String> newValues = new ArrayList<>();
|
||||
for(String split : dataTag.VALUES) {
|
||||
newValues.addAll(Arrays.stream(split.split(splitString)).map(String::trim).toList());
|
||||
for (String split : dataTag.VALUES) {
|
||||
newValues.addAll(
|
||||
Arrays.stream(split.split(splitString))
|
||||
.map(String::trim)
|
||||
.toList());
|
||||
}
|
||||
dataTag = new DataTag(dataTag.NAME, newValues.toArray(new String[0]));
|
||||
dataTag = new DataTag(dataTag.NAME,
|
||||
newValues.toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
if (dataTag.NAME.equals(tag.getName())) {
|
||||
// DataTag name matches the tag's main name, add as is
|
||||
processedTags.add(dataTag);
|
||||
break;
|
||||
} else if (tag.getAliases() != null && Arrays.asList(tag.getAliases()).contains(dataTag.NAME)) {
|
||||
// There is currently an edge case where if someone uses multiple aliases or names for tags at the same time, it'll only use the last one applied to the mapping.
|
||||
// DataTag name matches an alias, create a new DataTag with the main name
|
||||
processedTags.add(new DataTag(tag.getName(), dataTag.VALUES));
|
||||
} else if (tag.getAliases() != null
|
||||
&& Arrays.asList(tag.getAliases())
|
||||
.contains(dataTag.NAME)) {
|
||||
// There is currently an edge case where if someone uses
|
||||
// multiple aliases or names for tags at the same time,
|
||||
// it'll only use the last one applied to the mapping.
|
||||
// DataTag name matches an alias, create a new DataTag with
|
||||
// the main name
|
||||
processedTags.add(
|
||||
new DataTag(tag.getName(), dataTag.VALUES));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -153,24 +185,26 @@ public abstract class CreateTaggedSubCommand implements SubCommand {
|
||||
dataTags.addAll(processedTags);
|
||||
// Sort the tags by name however make sure name is first
|
||||
dataTags.sort((o1, o2) -> {
|
||||
if(o1.NAME.equals("name")) {
|
||||
if (o1.NAME.equals("name")) {
|
||||
return -1;
|
||||
}
|
||||
if(o2.NAME.equals("name")) {
|
||||
if (o2.NAME.equals("name")) {
|
||||
return 1;
|
||||
}
|
||||
return o1.NAME.compareTo(o2.NAME);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
protected void printTags(CommandSenderContainer sender, List<DataTag> dataTags) {
|
||||
protected void printTags(CommandSenderContainer sender,
|
||||
List<DataTag> dataTags) {
|
||||
for (DataTag tag : dataTags) {
|
||||
if(tag.VALUES.length == 1) {
|
||||
sender.sendMessage(" \u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUES[0]);
|
||||
if (tag.VALUES.length == 1) {
|
||||
sender.sendMessage(" \u00A7a" + tag.NAME + "\u00A77:\u00A7e"
|
||||
+ tag.VALUES[0]);
|
||||
} else {
|
||||
for (int i = 0; i < tag.VALUES.length; i++) {
|
||||
sender.sendMessage(" \u00A7a" + tag.NAME + "\u00A77[" + i + "]:\u00A7e" + tag.VALUES[i]);
|
||||
sender.sendMessage(" \u00A7a" + tag.NAME + "\u00A77[" + i
|
||||
+ "]:\u00A7e" + tag.VALUES[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,13 +12,11 @@ import com.sekwah.advancedportals.core.services.DestinationServices;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
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;
|
||||
|
||||
public class CreateDestiSubCommand extends CreateTaggedSubCommand {
|
||||
|
||||
@Inject TagRegistry tagRegistry;
|
||||
|
||||
@Inject DestinationServices destinationServices;
|
||||
@ -34,29 +32,29 @@ public class CreateDestiSubCommand extends CreateTaggedSubCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<DataTag> destinationTags = TagReader.getTagsFromArgs(args);
|
||||
ArrayList<DataTag> destinationTags =
|
||||
TagReader.getTagsFromArgs(args);
|
||||
|
||||
// Find the tag with the "name" NAME
|
||||
DataTag nameTag =
|
||||
destinationTags.stream()
|
||||
DataTag nameTag = destinationTags.stream()
|
||||
.filter(tag -> tag.NAME.equals("name"))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
// If the tag is null, check if arg[1] has a : to check it's not a tag.
|
||||
// If the tag is null, check if arg[1] has a : to check it's not a
|
||||
// tag.
|
||||
if (nameTag == null && !args[1].contains(":")) {
|
||||
nameTag = new DataTag("name", args[1]);
|
||||
destinationTags.add(nameTag);
|
||||
}
|
||||
|
||||
if (nameTag == null) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("command.error.noname"));
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(
|
||||
Lang.centeredTitle(Lang.translate("command.create.destination.prep")));
|
||||
sender.sendMessage(Lang.centeredTitle(
|
||||
Lang.translate("command.create.destination.prep")));
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(Lang.translate("command.create.tags"));
|
||||
|
||||
@ -65,8 +63,8 @@ public class CreateDestiSubCommand extends CreateTaggedSubCommand {
|
||||
this.printTags(sender, destinationTags);
|
||||
}
|
||||
sender.sendMessage("");
|
||||
Destination destination =
|
||||
destinationServices.createDesti(player, player.getLoc(), destinationTags);
|
||||
Destination destination = destinationServices.createDesti(
|
||||
player, player.getLoc(), destinationTags);
|
||||
if (destination != null) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
@ -78,8 +76,7 @@ public class CreateDestiSubCommand extends CreateTaggedSubCommand {
|
||||
+ Lang.translate("command.create.destination.error"));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("command.error.noname"));
|
||||
}
|
||||
}
|
||||
@ -94,7 +91,9 @@ public class CreateDestiSubCommand extends CreateTaggedSubCommand {
|
||||
var tags = tagRegistry.getTags();
|
||||
// Filter tags that support Destination
|
||||
return tags.stream()
|
||||
.filter(tag -> Arrays.asList(tag.getTagTypes()).contains(Tag.TagType.DESTINATION))
|
||||
.filter(tag
|
||||
-> Arrays.asList(tag.getTagTypes())
|
||||
.contains(Tag.TagType.DESTINATION))
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
@ -5,23 +5,19 @@ import com.sekwah.advancedportals.core.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
|
||||
import com.sekwah.advancedportals.core.services.DestinationServices;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ListDestiSubCommand implements SubCommand {
|
||||
|
||||
@Inject DestinationServices portalServices;
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
+ Lang.translate("command.destination.list")
|
||||
+ " "
|
||||
+ portalServices.getDestinationNames().stream()
|
||||
.sorted()
|
||||
.collect(Collectors.joining(", ")));
|
||||
+ Lang.translate("command.destination.list") + " "
|
||||
+ portalServices.getDestinationNames().stream().sorted().collect(
|
||||
Collectors.joining(", ")));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -30,7 +26,8 @@ public class ListDestiSubCommand implements SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -6,18 +6,17 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContain
|
||||
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
|
||||
import com.sekwah.advancedportals.core.services.DestinationServices;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class RemoveDestiSubCommand implements SubCommand {
|
||||
|
||||
@Inject DestinationServices destinationServices;
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
if (args.length > 1) {
|
||||
if (destinationServices.removeDestination(args[1], sender.getPlayerContainer())) {
|
||||
if (destinationServices.removeDestination(
|
||||
args[1], sender.getPlayerContainer())) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
+ Lang.translate("command.destination.remove.complete"));
|
||||
@ -37,7 +36,8 @@ public class RemoveDestiSubCommand implements SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
if (args.length > 2) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -13,17 +13,16 @@ import com.sekwah.advancedportals.core.services.PlayerDataServices;
|
||||
import com.sekwah.advancedportals.core.util.Debug;
|
||||
import com.sekwah.advancedportals.core.util.GameScheduler;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* This will be different from the old show command and I believe it is 1.16+ till the latest
|
||||
* version as of writing this.
|
||||
* This will be different from the old show command and I believe it is 1.16+
|
||||
* till the latest version as of writing this.
|
||||
*/
|
||||
public class ShowDestiSubCommand implements SubCommand, SubCommand.SubCommandOnInit {
|
||||
|
||||
public class ShowDestiSubCommand
|
||||
implements SubCommand, SubCommand.SubCommandOnInit {
|
||||
@Inject PlayerDataServices tempDataServices;
|
||||
|
||||
@Inject GameScheduler gameScheduler;
|
||||
@ -45,7 +44,8 @@ public class ShowDestiSubCommand implements SubCommand, SubCommand.SubCommandOnI
|
||||
return;
|
||||
}
|
||||
|
||||
var tempData = tempDataServices.getPlayerData(sender.getPlayerContainer());
|
||||
var tempData =
|
||||
tempDataServices.getPlayerData(sender.getPlayerContainer());
|
||||
if (tempData.isDestiVisible()) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
@ -64,7 +64,8 @@ public class ShowDestiSubCommand implements SubCommand, SubCommand.SubCommandOnI
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -80,30 +81,26 @@ public class ShowDestiSubCommand implements SubCommand, SubCommand.SubCommandOnI
|
||||
|
||||
@Override
|
||||
public void registered() {
|
||||
gameScheduler.intervalTickEvent(
|
||||
"show_portal",
|
||||
() -> {
|
||||
gameScheduler.intervalTickEvent("show_portal", () -> {
|
||||
for (PlayerContainer player : serverContainer.getPlayers()) {
|
||||
var tempData = tempDataServices.getPlayerData(player);
|
||||
if (!tempData.isDestiVisible()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Destination destination : destinationServices.getDestinations()) {
|
||||
for (Destination destination :
|
||||
destinationServices.getDestinations()) {
|
||||
var pos = destination.getLoc();
|
||||
if (Objects.equals(pos.getWorldName(), player.getWorldName())
|
||||
&& pos.distanceTo(player.getLoc()) < config.getVisibleRange()) {
|
||||
Debug.addMarker(
|
||||
player,
|
||||
pos.toBlockPos(),
|
||||
if (Objects.equals(pos.getWorldName(),
|
||||
player.getWorldName())
|
||||
&& pos.distanceTo(player.getLoc())
|
||||
< config.getVisibleRange()) {
|
||||
Debug.addMarker(player, pos.toBlockPos(),
|
||||
destination.getArgValues("name")[0],
|
||||
new Color(100, 100, 100, 100),
|
||||
1300);
|
||||
new Color(100, 100, 100, 100), 1300);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
1,
|
||||
20);
|
||||
}, 1, 20);
|
||||
}
|
||||
}
|
||||
|
@ -6,18 +6,17 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContain
|
||||
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
|
||||
import com.sekwah.advancedportals.core.services.DestinationServices;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class TeleportDestiSubCommand implements SubCommand {
|
||||
|
||||
@Inject DestinationServices destinationServices;
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
if (args.length > 1) {
|
||||
if (destinationServices.teleportToDestination(args[1], sender.getPlayerContainer())) {
|
||||
if (destinationServices.teleportToDestination(
|
||||
args[1], sender.getPlayerContainer())) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
+ Lang.translate("command.destination.teleport.success")
|
||||
@ -39,7 +38,8 @@ public class TeleportDestiSubCommand implements SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
if (args.length > 2) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -16,13 +16,11 @@ import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
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;
|
||||
|
||||
public class CreatePortalSubCommand extends CreateTaggedSubCommand {
|
||||
|
||||
@Inject PortalServices portalServices;
|
||||
|
||||
@Inject TagRegistry tagRegistry;
|
||||
@ -36,8 +34,7 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand {
|
||||
if (args.length > 1) {
|
||||
PlayerContainer player = sender.getPlayerContainer();
|
||||
if (player == null) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("command.create.console"));
|
||||
return;
|
||||
}
|
||||
@ -47,8 +44,7 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand {
|
||||
// Find the tag with the "name" NAME
|
||||
DataTag nameTag =
|
||||
portalTags.stream()
|
||||
.filter(
|
||||
tag -> {
|
||||
.filter(tag -> {
|
||||
this.infoLogger.info("Tag: " + tag.NAME);
|
||||
this.infoLogger.info(
|
||||
"Equals: " + tag.NAME.equals(NameTag.TAG_NAME));
|
||||
@ -57,20 +53,21 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand {
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
// If the tag is null, check if arg[1] has a : to check it's not a tag.
|
||||
// If the tag is null, check if arg[1] has a : to check it's not a
|
||||
// tag.
|
||||
if (nameTag == null && !args[1].contains(":")) {
|
||||
nameTag = new DataTag("name", args[1]);
|
||||
portalTags.add(nameTag);
|
||||
}
|
||||
|
||||
if (nameTag == null) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("command.error.noname"));
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(Lang.centeredTitle(Lang.translate("command.create.portal.prep")));
|
||||
sender.sendMessage(Lang.centeredTitle(
|
||||
Lang.translate("command.create.portal.prep")));
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(Lang.translate("command.create.tags"));
|
||||
|
||||
@ -87,32 +84,31 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand {
|
||||
.orElse(null);
|
||||
|
||||
if (triggerBlockTag == null) {
|
||||
portalTags.add(
|
||||
new DataTag(TriggerBlockTag.TAG_NAME, config.getDefaultTriggerBlock()));
|
||||
portalTags.add(new DataTag(TriggerBlockTag.TAG_NAME,
|
||||
config.getDefaultTriggerBlock()));
|
||||
}
|
||||
|
||||
AdvancedPortal portal = portalServices.createPortal(player, portalTags);
|
||||
AdvancedPortal portal =
|
||||
portalServices.createPortal(player, portalTags);
|
||||
if (portal != null) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
sender.sendMessage(Lang.translate("messageprefix.positive")
|
||||
+ Lang.translate("command.create.complete"));
|
||||
sender.sendMessage(Lang.translate("command.create.tags"));
|
||||
this.printTags(sender, portal.getArgs());
|
||||
} else {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("command.create.error"));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("command.error.notags"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSenderContainer sender) {
|
||||
return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender);
|
||||
return sender.isOp()
|
||||
|| PortalPermissions.CREATE_PORTAL.hasPermission(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -120,7 +116,9 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand {
|
||||
var tags = tagRegistry.getTags();
|
||||
// Filter tags that support Destination
|
||||
return tags.stream()
|
||||
.filter(tag -> Arrays.asList(tag.getTagTypes()).contains(Tag.TagType.PORTAL))
|
||||
.filter(tag
|
||||
-> Arrays.asList(tag.getTagTypes())
|
||||
.contains(Tag.TagType.PORTAL))
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
@ -7,39 +7,36 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContain
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EndGatewayBlockSubCommand implements SubCommand {
|
||||
|
||||
@Inject private AdvancedPortalsCore portalsCore;
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
PlayerContainer player = sender.getPlayerContainer();
|
||||
if (player == null) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("command.playeronly"));
|
||||
} else {
|
||||
player.giveItem(
|
||||
"BLACK_WOOL",
|
||||
"\u00A78Gateway Block Placer",
|
||||
"BLACK_WOOL", "\u00A78Gateway Block Placer",
|
||||
"\u00A7r\u00A77This wool is made of a magical substance",
|
||||
"\u00A7r\u00A7eRight Click\u00A77: Place portal block");
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
sender.sendMessage(Lang.translate("messageprefix.positive")
|
||||
+ Lang.translate("command.gatewayblock"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSenderContainer sender) {
|
||||
return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender);
|
||||
return sender.isOp()
|
||||
|| PortalPermissions.CREATE_PORTAL.hasPermission(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -7,39 +7,36 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContain
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EndPortalBlockSubCommand implements SubCommand {
|
||||
|
||||
@Inject private AdvancedPortalsCore portalsCore;
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
PlayerContainer player = sender.getPlayerContainer();
|
||||
if (player == null) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("command.playeronly"));
|
||||
} else {
|
||||
player.giveItem(
|
||||
"BLACK_WOOL",
|
||||
"\u00A78End Portal Block Placer",
|
||||
"BLACK_WOOL", "\u00A78End Portal Block Placer",
|
||||
"\u00A7r\u00A77This wool is made of a magical substance",
|
||||
"\u00A7r\u00A7eRight Click\u00A77: Place portal block");
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
sender.sendMessage(Lang.translate("messageprefix.positive")
|
||||
+ Lang.translate("command.endportalblock"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSenderContainer sender) {
|
||||
return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender);
|
||||
return sender.isOp()
|
||||
|| PortalPermissions.CREATE_PORTAL.hasPermission(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContain
|
||||
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
@ -18,25 +17,23 @@ import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class LangUpdateSubCommand implements SubCommand {
|
||||
|
||||
@Inject private AdvancedPortalsCore portalsCore;
|
||||
@Inject private ConfigRepository configRepository;
|
||||
|
||||
public LangUpdateSubCommand() {}
|
||||
public LangUpdateSubCommand() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
if (args.length > 1 && args[1].equalsIgnoreCase("overwrite")) {
|
||||
this.portalsCore
|
||||
.getDataStorage()
|
||||
.copyDefaultFile("lang/" + configRepository.getTranslation() + ".lang", true);
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
this.portalsCore.getDataStorage().copyDefaultFile(
|
||||
"lang/" + configRepository.getTranslation() + ".lang", true);
|
||||
sender.sendMessage(Lang.translate("messageprefix.positive")
|
||||
+ Lang.translate("translatedata.replaced"));
|
||||
Lang.loadLanguage(configRepository.getTranslation());
|
||||
} else {
|
||||
// TODO check what keys are missing and append them to the end of the file, check the
|
||||
// translation first then GB
|
||||
// TODO check what keys are missing and append them to the end of
|
||||
// the file, check the translation first then GB
|
||||
Lang lang = Lang.instance;
|
||||
Map<String, String> internalTranslation =
|
||||
lang.getInternalLanguageMap(Lang.DEFAULT_LANG);
|
||||
@ -46,48 +43,50 @@ public class LangUpdateSubCommand implements SubCommand {
|
||||
Map<String, String> currentTranslation =
|
||||
lang.getLanguageMap(configRepository.getTranslation());
|
||||
// Remove everything to leave just the missing keys
|
||||
for (Map.Entry<String, String> entry : currentTranslation.entrySet()) {
|
||||
for (Map.Entry<String, String> entry :
|
||||
currentTranslation.entrySet()) {
|
||||
internalTranslation.remove(entry.getKey());
|
||||
}
|
||||
|
||||
List<String> newTranslations = new ArrayList<>();
|
||||
for (Map.Entry<String, String> entry : internalTranslation.entrySet()) {
|
||||
for (Map.Entry<String, String> entry :
|
||||
internalTranslation.entrySet()) {
|
||||
newTranslations.add(entry.getKey() + "=" + entry.getValue());
|
||||
}
|
||||
|
||||
String appendText = String.join("\n", newTranslations);
|
||||
|
||||
InputStream translationFile =
|
||||
this.portalsCore
|
||||
.getDataStorage()
|
||||
.loadResource("lang/" + configRepository.getTranslation() + ".lang");
|
||||
this.portalsCore.getDataStorage().loadResource(
|
||||
"lang/" + configRepository.getTranslation() + ".lang");
|
||||
String result =
|
||||
new BufferedReader(new InputStreamReader(translationFile))
|
||||
.lines()
|
||||
.collect(Collectors.joining("\n"));
|
||||
InputStream withExtras =
|
||||
new ByteArrayInputStream(result.concat("\n").concat(appendText).getBytes());
|
||||
this.portalsCore
|
||||
.getDataStorage()
|
||||
.writeResource(
|
||||
withExtras, "lang/" + configRepository.getTranslation() + ".lang");
|
||||
InputStream withExtras = new ByteArrayInputStream(
|
||||
result.concat("\n").concat(appendText).getBytes());
|
||||
this.portalsCore.getDataStorage().writeResource(
|
||||
withExtras,
|
||||
"lang/" + configRepository.getTranslation() + ".lang");
|
||||
|
||||
Lang.loadLanguage(configRepository.getTranslation());
|
||||
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
+ Lang.translateInsertVariables(
|
||||
"translatedata.updated", newTranslations.size()));
|
||||
+ Lang.translateInsertVariables("translatedata.updated",
|
||||
newTranslations.size()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSenderContainer sender) {
|
||||
return sender.isOp() || PortalPermissions.LANG_UPDATE.hasPermission(sender);
|
||||
return sender.isOp()
|
||||
|| PortalPermissions.LANG_UPDATE.hasPermission(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -5,23 +5,19 @@ import com.sekwah.advancedportals.core.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
|
||||
import com.sekwah.advancedportals.core.services.PortalServices;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ListPortalsSubCommand implements SubCommand {
|
||||
|
||||
@Inject PortalServices portalServices;
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
+ Lang.translate("command.portal.list")
|
||||
+ " "
|
||||
+ portalServices.getPortalNames().stream()
|
||||
.sorted()
|
||||
.collect(Collectors.joining(", ")));
|
||||
+ Lang.translate("command.portal.list") + " "
|
||||
+ portalServices.getPortalNames().stream().sorted().collect(
|
||||
Collectors.joining(", ")));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -30,7 +26,8 @@ public class ListPortalsSubCommand implements SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -7,44 +7,39 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContain
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PortalBlockSubCommand implements SubCommand {
|
||||
|
||||
@Inject private AdvancedPortalsCore portalsCore;
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
PlayerContainer player = sender.getPlayerContainer();
|
||||
if (player == null) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("command.playeronly"));
|
||||
} else {
|
||||
player.giveItem(
|
||||
"PURPLE_WOOL",
|
||||
"\u00A75Portal Block Placer",
|
||||
"PURPLE_WOOL", "\u00A75Portal Block Placer",
|
||||
"\u00A7r\u00A77This wool is made of a magical substance",
|
||||
"\u00A7r\u00A7e"
|
||||
+ Lang.translate("items.interact.left")
|
||||
"\u00A7r\u00A7e" + Lang.translate("items.interact.left")
|
||||
+ "\u00A77: Rotate portal block",
|
||||
"\u00A7r\u00A7e"
|
||||
+ Lang.translate("items.interact.right")
|
||||
"\u00A7r\u00A7e" + Lang.translate("items.interact.right")
|
||||
+ "\u00A77: Place portal block");
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
sender.sendMessage(Lang.translate("messageprefix.positive")
|
||||
+ Lang.translate("command.portalblock"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSenderContainer sender) {
|
||||
return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender);
|
||||
return sender.isOp()
|
||||
|| PortalPermissions.CREATE_PORTAL.hasPermission(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -9,11 +9,9 @@ import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.services.DestinationServices;
|
||||
import com.sekwah.advancedportals.core.services.PortalServices;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ReloadPortalSubCommand implements SubCommand {
|
||||
|
||||
@Inject private AdvancedPortalsCore portalsCore;
|
||||
|
||||
@Inject PortalServices portalServices;
|
||||
@ -28,8 +26,7 @@ public class ReloadPortalSubCommand implements SubCommand {
|
||||
portalServices.loadPortals();
|
||||
destinationServices.loadDestinations();
|
||||
Lang.loadLanguage(configRepository.getTranslation());
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
sender.sendMessage(Lang.translate("messageprefix.positive")
|
||||
+ Lang.translate("command.reload.reloaded"));
|
||||
}
|
||||
|
||||
@ -39,7 +36,8 @@ public class ReloadPortalSubCommand implements SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -6,17 +6,16 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContain
|
||||
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
|
||||
import com.sekwah.advancedportals.core.services.PortalServices;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RemovePortalSubCommand implements SubCommand {
|
||||
|
||||
@Inject PortalServices portalServices;
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
if (args.length > 1) {
|
||||
if (portalServices.removePortal(args[1], sender.getPlayerContainer())) {
|
||||
if (portalServices.removePortal(args[1],
|
||||
sender.getPlayerContainer())) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
+ Lang.translate("command.portal.remove.complete"));
|
||||
@ -32,11 +31,13 @@ public class RemovePortalSubCommand implements SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSenderContainer sender) {
|
||||
return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender);
|
||||
return sender.isOp()
|
||||
|| PortalPermissions.CREATE_PORTAL.hasPermission(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
return portalServices.getPortalNames();
|
||||
}
|
||||
|
||||
|
@ -8,11 +8,9 @@ import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SelectorSubCommand implements SubCommand {
|
||||
|
||||
@Inject private ConfigRepository configRepo;
|
||||
|
||||
@Inject private AdvancedPortalsCore portalsCore;
|
||||
@ -21,36 +19,34 @@ public class SelectorSubCommand implements SubCommand {
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
PlayerContainer player = sender.getPlayerContainer();
|
||||
if (player == null) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("command.playeronly"));
|
||||
} else {
|
||||
player.giveItem(
|
||||
configRepo.getSelectorMaterial(),
|
||||
"\u00A7e" + Lang.translate("items.selector.name"),
|
||||
"\u00A7r\u00A77This wand with has the power to help",
|
||||
"\u00A7r\u00A77 create portals bistowed upon it!",
|
||||
"",
|
||||
"\u00A7r\u00A7e"
|
||||
+ Lang.translate("items.interact.left")
|
||||
"\u00A7r\u00A77 create portals bistowed upon it!", "",
|
||||
"\u00A7r\u00A7e" + Lang.translate("items.interact.left")
|
||||
+ "\u00A77: "
|
||||
+ Lang.translateInsertVariables("items.selector.pos", "1"),
|
||||
"\u00A7r\u00A7e"
|
||||
+ Lang.translate("items.interact.right")
|
||||
"\u00A7r\u00A7e" + Lang.translate("items.interact.right")
|
||||
+ "\u00A77: "
|
||||
+ Lang.translateInsertVariables("items.selector.pos", "2"));
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive") + Lang.translate("command.selector"));
|
||||
sender.sendMessage(Lang.translate("messageprefix.positive")
|
||||
+ Lang.translate("command.selector"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSenderContainer sender) {
|
||||
return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender);
|
||||
return sender.isOp()
|
||||
|| PortalPermissions.CREATE_PORTAL.hasPermission(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -15,17 +15,16 @@ import com.sekwah.advancedportals.core.tags.activation.NameTag;
|
||||
import com.sekwah.advancedportals.core.util.Debug;
|
||||
import com.sekwah.advancedportals.core.util.GameScheduler;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* This will be different from the old show command and I believe it is 1.16+ till the latest
|
||||
* version as of writing this.
|
||||
* This will be different from the old show command and I believe it is 1.16+
|
||||
* till the latest version as of writing this.
|
||||
*/
|
||||
public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOnInit {
|
||||
|
||||
public class ShowPortalSubCommand
|
||||
implements SubCommand, SubCommand.SubCommandOnInit {
|
||||
static final int SHOW_TICKS = 1010;
|
||||
|
||||
boolean alternate_show_trigger = true;
|
||||
@ -62,14 +61,14 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
|
||||
return;
|
||||
}
|
||||
|
||||
var tempData = playerDataServices.getPlayerData(sender.getPlayerContainer());
|
||||
var tempData =
|
||||
playerDataServices.getPlayerData(sender.getPlayerContainer());
|
||||
if (tempData.isPortalVisible()) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("command.portal.show.disabled"));
|
||||
} else {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
sender.sendMessage(Lang.translate("messageprefix.positive")
|
||||
+ Lang.translate("command.portal.show.enabled"));
|
||||
}
|
||||
tempData.setPortalVisible(!tempData.isPortalVisible());
|
||||
@ -81,7 +80,8 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -97,9 +97,7 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
|
||||
|
||||
@Override
|
||||
public void registered() {
|
||||
gameScheduler.intervalTickEvent(
|
||||
"show_portal",
|
||||
() -> {
|
||||
gameScheduler.intervalTickEvent("show_portal", () -> {
|
||||
alternate_show_trigger = !alternate_show_trigger;
|
||||
for (PlayerContainer player : serverContainer.getPlayers()) {
|
||||
var tempData = playerDataServices.getPlayerData(player);
|
||||
@ -107,39 +105,31 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tempData.getPos1() != null
|
||||
&& tempData.getPos2() != null
|
||||
&& tempData.getPos1().getWorldName().equals(player.getWorldName())
|
||||
&& tempData.getPos2()
|
||||
.getWorldName()
|
||||
.equals(player.getWorldName())) {
|
||||
debugVisuals(
|
||||
player,
|
||||
tempData.getPos1(),
|
||||
tempData.getPos2(),
|
||||
SELECTION_COLOR,
|
||||
SHOW_TICKS);
|
||||
if (tempData.getPos1() != null && tempData.getPos2() != null
|
||||
&& tempData.getPos1().getWorldName().equals(
|
||||
player.getWorldName())
|
||||
&& tempData.getPos2().getWorldName().equals(
|
||||
player.getWorldName())) {
|
||||
debugVisuals(player, tempData.getPos1(), tempData.getPos2(),
|
||||
SELECTION_COLOR, SHOW_TICKS);
|
||||
}
|
||||
|
||||
if (tempData.getPos1() != null
|
||||
&& tempData.getPos1()
|
||||
.getWorldName()
|
||||
.equals(player.getWorldName())) {
|
||||
Debug.addMarker(
|
||||
player, tempData.getPos1(), "Pos1", POS1_COLOR, SHOW_TICKS);
|
||||
&& tempData.getPos1().getWorldName().equals(
|
||||
player.getWorldName())) {
|
||||
Debug.addMarker(player, tempData.getPos1(), "Pos1",
|
||||
POS1_COLOR, SHOW_TICKS);
|
||||
}
|
||||
if (tempData.getPos2() != null
|
||||
&& tempData.getPos2()
|
||||
.getWorldName()
|
||||
.equals(player.getWorldName())) {
|
||||
Debug.addMarker(
|
||||
player, tempData.getPos2(), "Pos2", POS2_COLOR, SHOW_TICKS);
|
||||
&& tempData.getPos2().getWorldName().equals(
|
||||
player.getWorldName())) {
|
||||
Debug.addMarker(player, tempData.getPos2(), "Pos2",
|
||||
POS2_COLOR, SHOW_TICKS);
|
||||
}
|
||||
|
||||
var world = player.getWorld();
|
||||
for (var portal : portalServices.getPortals()) {
|
||||
if (Objects.equals(
|
||||
portal.getMinLoc().getWorldName(),
|
||||
if (Objects.equals(portal.getMinLoc().getWorldName(),
|
||||
player.getWorldName())
|
||||
&& portal.isLocationInPortal(
|
||||
player.getLoc(), config.getVisibleRange())) {
|
||||
@ -148,11 +138,8 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
|
||||
int midX = (minLoc.getPosX() + maxLoc.getPosX()) / 2;
|
||||
int midZ = (minLoc.getPosZ() + maxLoc.getPosZ()) / 2;
|
||||
BlockLocation midPoint =
|
||||
new BlockLocation(
|
||||
minLoc.getWorldName(),
|
||||
midX,
|
||||
maxLoc.getPosY(),
|
||||
midZ);
|
||||
new BlockLocation(minLoc.getWorldName(), midX,
|
||||
maxLoc.getPosY(), midZ);
|
||||
Color color;
|
||||
if (portal.isTriggerBlock(world.getBlock(midPoint))) {
|
||||
color = TRIGGER_OUTLINE_COLOR;
|
||||
@ -162,45 +149,36 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
|
||||
|| midPoint.getPosZ() == minLoc.getPosZ()
|
||||
|| midPoint.getPosZ() == maxLoc.getPosZ())
|
||||
color = OUTLINE_COLOR;
|
||||
else color = new Color(0, 0, 0, 0);
|
||||
else
|
||||
color = new Color(0, 0, 0, 0);
|
||||
}
|
||||
debugVisuals(
|
||||
player, portal, OUTLINE_COLOR, SHOW_TICKS, TRIGGER_COLOR);
|
||||
debugVisuals(player, portal, OUTLINE_COLOR, SHOW_TICKS,
|
||||
TRIGGER_COLOR);
|
||||
var name = portal.getArgValues(NameTag.TAG_NAME);
|
||||
if (name != null && name.length > 0) {
|
||||
Debug.addMarker(player, midPoint, name[0], color, SHOW_TICKS);
|
||||
Debug.addMarker(player, midPoint, name[0], color,
|
||||
SHOW_TICKS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
1,
|
||||
20);
|
||||
}, 1, 20);
|
||||
}
|
||||
|
||||
private void debugVisuals(
|
||||
PlayerContainer player, BlockLocation pos1, BlockLocation pos2, Color color, int time) {
|
||||
private void debugVisuals(PlayerContainer player, BlockLocation pos1,
|
||||
BlockLocation pos2, Color color, int time) {
|
||||
debugVisuals(player, pos1, pos2, color, time, null, null);
|
||||
}
|
||||
|
||||
private void debugVisuals(
|
||||
PlayerContainer player,
|
||||
AdvancedPortal portal,
|
||||
Color color,
|
||||
int time,
|
||||
Color triggerColor) {
|
||||
debugVisuals(
|
||||
player, portal.getMinLoc(), portal.getMaxLoc(), color, time, triggerColor, portal);
|
||||
private void debugVisuals(PlayerContainer player, AdvancedPortal portal,
|
||||
Color color, int time, Color triggerColor) {
|
||||
debugVisuals(player, portal.getMinLoc(), portal.getMaxLoc(), color,
|
||||
time, triggerColor, portal);
|
||||
}
|
||||
|
||||
private void debugVisuals(
|
||||
PlayerContainer player,
|
||||
BlockLocation pos1,
|
||||
BlockLocation pos2,
|
||||
Color color,
|
||||
int time,
|
||||
Color triggerColor,
|
||||
AdvancedPortal portal) {
|
||||
private void debugVisuals(PlayerContainer player, BlockLocation pos1,
|
||||
BlockLocation pos2, Color color, int time,
|
||||
Color triggerColor, AdvancedPortal portal) {
|
||||
int minX = Math.min(pos1.getPosX(), pos2.getPosX());
|
||||
int minY = Math.min(pos1.getPosY(), pos2.getPosY());
|
||||
int minZ = Math.min(pos1.getPosZ(), pos2.getPosZ());
|
||||
@ -221,105 +199,83 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
var pos = new BlockLocation(pos1.getWorldName(), x, y, z);
|
||||
boolean isTrigger =
|
||||
portal != null && portal.isTriggerBlock(world.getBlock(pos));
|
||||
boolean isOutline =
|
||||
(y == minY || y == maxY)
|
||||
var pos =
|
||||
new BlockLocation(pos1.getWorldName(), x, y, z);
|
||||
boolean isTrigger = portal != null
|
||||
&& portal.isTriggerBlock(world.getBlock(pos));
|
||||
boolean isOutline = (y == minY || y == maxY)
|
||||
&& (x == minX || x == maxX || z == minZ
|
||||
|| z == maxZ)
|
||||
|| (z == minZ || z == maxZ) && (x == minX || x == maxX);
|
||||
|| (z == minZ || z == maxZ)
|
||||
&& (x == minX || x == maxX);
|
||||
if (isTrigger && isOutline && alternate_show_trigger) {
|
||||
Debug.addMarker(player, pos, "", TRIGGER_OUTLINE_COLOR, time);
|
||||
Debug.addMarker(player, pos, "",
|
||||
TRIGGER_OUTLINE_COLOR, time);
|
||||
} else if (isOutline) {
|
||||
Debug.addMarker(player, pos, "", color, time);
|
||||
} else if (isTrigger) {
|
||||
if (alternate_show_trigger)
|
||||
Debug.addMarker(player, pos, "", triggerColor, time);
|
||||
Debug.addMarker(player, pos, "", triggerColor,
|
||||
time);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
Debug.addMarker(
|
||||
player,
|
||||
new BlockLocation(pos1.getWorldName(), x, minY, minZ),
|
||||
"",
|
||||
color,
|
||||
time);
|
||||
new BlockLocation(pos1.getWorldName(), x, minY, minZ), "",
|
||||
color, time);
|
||||
Debug.addMarker(
|
||||
player,
|
||||
new BlockLocation(pos1.getWorldName(), x, minY, maxZ),
|
||||
"",
|
||||
color,
|
||||
time);
|
||||
new BlockLocation(pos1.getWorldName(), x, minY, maxZ), "",
|
||||
color, time);
|
||||
Debug.addMarker(
|
||||
player,
|
||||
new BlockLocation(pos1.getWorldName(), x, maxY, minZ),
|
||||
"",
|
||||
color,
|
||||
time);
|
||||
new BlockLocation(pos1.getWorldName(), x, maxY, minZ), "",
|
||||
color, time);
|
||||
Debug.addMarker(
|
||||
player,
|
||||
new BlockLocation(pos1.getWorldName(), x, maxY, maxZ),
|
||||
"",
|
||||
color,
|
||||
time);
|
||||
new BlockLocation(pos1.getWorldName(), x, maxY, maxZ), "",
|
||||
color, time);
|
||||
}
|
||||
for (int z = minZ + 1; z < maxZ; z++) {
|
||||
Debug.addMarker(
|
||||
player,
|
||||
new BlockLocation(pos1.getWorldName(), minX, minY, z),
|
||||
"",
|
||||
color,
|
||||
time);
|
||||
new BlockLocation(pos1.getWorldName(), minX, minY, z), "",
|
||||
color, time);
|
||||
Debug.addMarker(
|
||||
player,
|
||||
new BlockLocation(pos1.getWorldName(), maxX, minY, z),
|
||||
"",
|
||||
color,
|
||||
time);
|
||||
new BlockLocation(pos1.getWorldName(), maxX, minY, z), "",
|
||||
color, time);
|
||||
Debug.addMarker(
|
||||
player,
|
||||
new BlockLocation(pos1.getWorldName(), minX, maxY, z),
|
||||
"",
|
||||
color,
|
||||
time);
|
||||
new BlockLocation(pos1.getWorldName(), minX, maxY, z), "",
|
||||
color, time);
|
||||
Debug.addMarker(
|
||||
player,
|
||||
new BlockLocation(pos1.getWorldName(), maxX, maxY, z),
|
||||
"",
|
||||
color,
|
||||
time);
|
||||
new BlockLocation(pos1.getWorldName(), maxX, maxY, z), "",
|
||||
color, time);
|
||||
}
|
||||
|
||||
for (int y = minY + 1; y < maxY; y++) {
|
||||
Debug.addMarker(
|
||||
player,
|
||||
new BlockLocation(pos1.getWorldName(), minX, y, minZ),
|
||||
"",
|
||||
color,
|
||||
time);
|
||||
new BlockLocation(pos1.getWorldName(), minX, y, minZ), "",
|
||||
color, time);
|
||||
Debug.addMarker(
|
||||
player,
|
||||
new BlockLocation(pos1.getWorldName(), maxX, y, minZ),
|
||||
"",
|
||||
color,
|
||||
time);
|
||||
new BlockLocation(pos1.getWorldName(), maxX, y, minZ), "",
|
||||
color, time);
|
||||
Debug.addMarker(
|
||||
player,
|
||||
new BlockLocation(pos1.getWorldName(), minX, y, maxZ),
|
||||
"",
|
||||
color,
|
||||
time);
|
||||
new BlockLocation(pos1.getWorldName(), minX, y, maxZ), "",
|
||||
color, time);
|
||||
Debug.addMarker(
|
||||
player,
|
||||
new BlockLocation(pos1.getWorldName(), maxX, y, maxZ),
|
||||
"",
|
||||
color,
|
||||
time);
|
||||
new BlockLocation(pos1.getWorldName(), maxX, y, maxZ), "",
|
||||
color, time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,15 +4,12 @@ import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class VersionSubCommand implements SubCommand {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
sender.sendMessage(Lang.translate("messageprefix.positive")
|
||||
+ " Advanced Portals v"
|
||||
+ AdvancedPortalsCore.version);
|
||||
}
|
||||
@ -23,7 +20,8 @@ public class VersionSubCommand implements SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@ package com.sekwah.advancedportals.core.connector.commands;
|
||||
import com.sekwah.advancedportals.core.commands.CommandTemplate;
|
||||
|
||||
public abstract class CommandHandler {
|
||||
|
||||
private final CommandTemplate commandExecutor;
|
||||
|
||||
public CommandHandler(CommandTemplate commandExecutor) {
|
||||
|
@ -3,7 +3,6 @@ package com.sekwah.advancedportals.core.connector.commands;
|
||||
import com.sekwah.advancedportals.core.commands.CommandTemplate;
|
||||
|
||||
public interface CommandRegister {
|
||||
|
||||
/**
|
||||
* Registers the command to the appropriate system
|
||||
*
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.sekwah.advancedportals.core.connector.containers;
|
||||
|
||||
public interface CommandSenderContainer {
|
||||
|
||||
void sendMessage(String message);
|
||||
|
||||
boolean isOp();
|
||||
|
@ -5,7 +5,6 @@ import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.serializeddata.Vector;
|
||||
|
||||
public interface EntityContainer {
|
||||
|
||||
PlayerLocation getLoc();
|
||||
|
||||
double getHeight();
|
||||
|
@ -1,12 +1,13 @@
|
||||
package com.sekwah.advancedportals.core.connector.containers;
|
||||
|
||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/** Just a temporary container for whenever advanced portals needs to get data from a player */
|
||||
/**
|
||||
* Just a temporary container for whenever advanced portals needs to get data
|
||||
* from a player
|
||||
*/
|
||||
public interface PlayerContainer extends EntityContainer {
|
||||
|
||||
UUID getUUID();
|
||||
|
||||
void sendMessage(String message);
|
||||
@ -28,7 +29,8 @@ public interface PlayerContainer extends EntityContainer {
|
||||
* @param material
|
||||
* @param data
|
||||
*/
|
||||
void sendFakeBlockWithData(BlockLocation blockPos, String material, byte data);
|
||||
void sendFakeBlockWithData(BlockLocation blockPos, String material,
|
||||
byte data);
|
||||
|
||||
void giveItem(String material, String itemName, String... itemDescription);
|
||||
|
||||
|
@ -4,7 +4,6 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface ServerContainer {
|
||||
|
||||
WorldContainer getWorld(String name);
|
||||
|
||||
PlayerContainer getPlayer(String name);
|
||||
|
@ -4,7 +4,6 @@ import com.sekwah.advancedportals.core.data.BlockAxis;
|
||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
|
||||
public interface WorldContainer {
|
||||
|
||||
void setBlock(BlockLocation location, String material);
|
||||
|
||||
String getBlock(BlockLocation location);
|
||||
|
@ -1,7 +1,3 @@
|
||||
package com.sekwah.advancedportals.core.data;
|
||||
|
||||
public enum BlockAxis {
|
||||
X,
|
||||
Y,
|
||||
Z
|
||||
}
|
||||
public enum BlockAxis { X, Y, Z }
|
||||
|
@ -8,24 +8,23 @@ import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Possibly look at adding the ability to add some tags to destinations such as permissions. Would
|
||||
* make it easier to add permissions to block access to certain areas and such. Could be a different
|
||||
* permission system or just it takes the tags on the destination and automatically applies them
|
||||
* when a portal wants to warp to there. (Of course it would not work cross server unless the data
|
||||
* was communicated and checked first however that could affect performance and would definitely
|
||||
* affect speed)
|
||||
* Possibly look at adding the ability to add some tags to destinations such as
|
||||
* permissions. Would make it easier to add permissions to block access to
|
||||
* certain areas and such. Could be a different permission system or just it
|
||||
* takes the tags on the destination and automatically applies them when a
|
||||
* portal wants to warp to there. (Of course it would not work cross server
|
||||
* unless the data was communicated and checked first however that could affect
|
||||
* performance and would definitely affect speed)
|
||||
*
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class Destination implements TagTarget {
|
||||
|
||||
@Inject transient TagRegistry tagRegistry;
|
||||
|
||||
private PlayerLocation loc;
|
||||
@ -53,7 +52,8 @@ public class Destination implements TagTarget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addArg(String argName, String argValues) {}
|
||||
public void addArg(String argName, String argValues) {
|
||||
}
|
||||
|
||||
public void setArgValues(DataTag portalTag) {
|
||||
this.setArgValues(portalTag.NAME, portalTag.VALUES);
|
||||
@ -77,16 +77,19 @@ public class Destination implements TagTarget {
|
||||
destiTags[i++] = new DataTag(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for (DataTag destiTag : destiTags) {
|
||||
Tag.Activation activationHandler = tagRegistry.getActivationHandler(destiTag.NAME);
|
||||
Tag.Activation activationHandler =
|
||||
tagRegistry.getActivationHandler(destiTag.NAME);
|
||||
if (activationHandler != null) {
|
||||
activationHandler.preActivated(
|
||||
this, player, data, this.getArgValues(destiTag.NAME));
|
||||
}
|
||||
}
|
||||
for (DataTag destiTag : destiTags) {
|
||||
Tag.Activation activationHandler = tagRegistry.getActivationHandler(destiTag.NAME);
|
||||
Tag.Activation activationHandler =
|
||||
tagRegistry.getActivationHandler(destiTag.NAME);
|
||||
if (activationHandler != null) {
|
||||
activationHandler.activated(this, player, data, this.getArgValues(destiTag.NAME));
|
||||
activationHandler.activated(this, player, data,
|
||||
this.getArgValues(destiTag.NAME));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -99,7 +102,8 @@ public class Destination implements TagTarget {
|
||||
destiTags[i++] = new DataTag(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for (DataTag destiTag : destiTags) {
|
||||
Tag.Activation activationHandler = tagRegistry.getActivationHandler(destiTag.NAME);
|
||||
Tag.Activation activationHandler =
|
||||
tagRegistry.getActivationHandler(destiTag.NAME);
|
||||
if (activationHandler != null) {
|
||||
activationHandler.postActivated(
|
||||
this, player, data, this.getArgValues(destiTag.NAME));
|
||||
|
@ -3,19 +3,16 @@ package com.sekwah.advancedportals.core.effect;
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
|
||||
public interface WarpEffect {
|
||||
|
||||
enum Action {
|
||||
ENTER,
|
||||
EXIT;
|
||||
}
|
||||
|
||||
interface Sound extends WarpEffect {
|
||||
|
||||
void onWarpSound(PlayerContainer player, Action action);
|
||||
}
|
||||
|
||||
interface Visual extends WarpEffect {
|
||||
|
||||
void onWarpVisual(PlayerContainer player, Action action);
|
||||
}
|
||||
}
|
||||
|
@ -17,14 +17,11 @@ import com.sekwah.advancedportals.core.serializeddata.DataStorage;
|
||||
import com.sekwah.advancedportals.core.serializeddata.config.Config;
|
||||
import com.sekwah.advancedportals.core.serializeddata.config.ConfigProvider;
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class AdvancedPortalsModule extends AbstractModule {
|
||||
|
||||
private Injector injector;
|
||||
private AdvancedPortalsCore advancedPortalsCore;
|
||||
private DataStorage dataStorage;
|
||||
@ -35,19 +32,31 @@ public class AdvancedPortalsModule extends AbstractModule {
|
||||
this.advancedPortalsCore = advancedPortalsCore;
|
||||
}
|
||||
|
||||
/** https://github.com/google/guice/wiki/Bindings */
|
||||
/**
|
||||
* https://github.com/google/guice/wiki/Bindings
|
||||
*/
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(IPortalRepository.class).to(PortalRepositoryImpl.class).in(Scopes.SINGLETON);
|
||||
bind(IDestinationRepository.class).to(DestinationRepositoryImpl.class).in(Scopes.SINGLETON);
|
||||
bind(IPlayerDataRepository.class).to(PlayerDataRepositoryImpl.class).in(Scopes.SINGLETON);
|
||||
bind(ConfigRepository.class).to(ConfigRepositoryImpl.class).in(Scopes.SINGLETON);
|
||||
bind(IPortalRepository.class)
|
||||
.to(PortalRepositoryImpl.class)
|
||||
.in(Scopes.SINGLETON);
|
||||
bind(IDestinationRepository.class)
|
||||
.to(DestinationRepositoryImpl.class)
|
||||
.in(Scopes.SINGLETON);
|
||||
bind(IPlayerDataRepository.class)
|
||||
.to(PlayerDataRepositoryImpl.class)
|
||||
.in(Scopes.SINGLETON);
|
||||
bind(ConfigRepository.class)
|
||||
.to(ConfigRepositoryImpl.class)
|
||||
.in(Scopes.SINGLETON);
|
||||
|
||||
// Instances
|
||||
bind(AdvancedPortalsCore.class).toInstance(advancedPortalsCore);
|
||||
bind(InfoLogger.class).toInstance(advancedPortalsCore.getInfoLogger());
|
||||
bind(DataStorage.class).toInstance(advancedPortalsCore.getDataStorage());
|
||||
bind(ServerContainer.class).toInstance(advancedPortalsCore.getServerContainer());
|
||||
bind(DataStorage.class)
|
||||
.toInstance(advancedPortalsCore.getDataStorage());
|
||||
bind(ServerContainer.class)
|
||||
.toInstance(advancedPortalsCore.getServerContainer());
|
||||
|
||||
// Providers
|
||||
bind(Config.class).toProvider(ConfigProvider.class);
|
||||
|
@ -2,22 +2,26 @@ package com.sekwah.advancedportals.core.permissions;
|
||||
|
||||
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PortalPermissions {
|
||||
private static final PermissionBuilder PERMISSIONS =
|
||||
new PermissionBuilder("advancedportals");
|
||||
|
||||
private static final PermissionBuilder PERMISSIONS = new PermissionBuilder("advancedportals");
|
||||
|
||||
public static final PermissionBuilder BUILD = PERMISSIONS.createChild("build");
|
||||
public static final PermissionBuilder DESTI = PERMISSIONS.createChild("desti");
|
||||
public static final PermissionBuilder CREATE_PORTAL = PERMISSIONS.createChild("createportal");
|
||||
public static final PermissionBuilder LANG_UPDATE = PERMISSIONS.createChild("langupdate");
|
||||
public static final PermissionBuilder RELOAD = PERMISSIONS.createChild("reload");
|
||||
public static final PermissionBuilder BUILD =
|
||||
PERMISSIONS.createChild("build");
|
||||
public static final PermissionBuilder DESTI =
|
||||
PERMISSIONS.createChild("desti");
|
||||
public static final PermissionBuilder CREATE_PORTAL =
|
||||
PERMISSIONS.createChild("createportal");
|
||||
public static final PermissionBuilder LANG_UPDATE =
|
||||
PERMISSIONS.createChild("langupdate");
|
||||
public static final PermissionBuilder RELOAD =
|
||||
PERMISSIONS.createChild("reload");
|
||||
|
||||
/**
|
||||
* this will not currently build the permissions for the files, but maybe at some point. It'll
|
||||
* just make it easier though.
|
||||
* this will not currently build the permissions for the files, but maybe at
|
||||
* some point. It'll just make it easier though.
|
||||
*/
|
||||
public static class PermissionBuilder {
|
||||
private final String permissionTag;
|
||||
|
@ -13,14 +13,12 @@ import com.sekwah.advancedportals.core.tags.activation.TriggerBlockTag;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class AdvancedPortal implements TagTarget {
|
||||
|
||||
@Inject private transient TagRegistry tagRegistry;
|
||||
|
||||
private BlockLocation maxLoc;
|
||||
@ -38,9 +36,7 @@ public class AdvancedPortal implements TagTarget {
|
||||
this.maxLoc = new BlockLocation();
|
||||
}
|
||||
|
||||
public AdvancedPortal(
|
||||
BlockLocation minLoc,
|
||||
BlockLocation maxLoc,
|
||||
public AdvancedPortal(BlockLocation minLoc, BlockLocation maxLoc,
|
||||
TagRegistry tagRegistry,
|
||||
PlayerDataServices playerDataServices) {
|
||||
this.tagRegistry = tagRegistry;
|
||||
@ -105,24 +101,28 @@ public class AdvancedPortal implements TagTarget {
|
||||
}*/
|
||||
|
||||
/**
|
||||
* @param player The player on the server attempting to use an advanced portal
|
||||
* @param moveActivated if the portal was activated by a move event (won't trigger knockback)
|
||||
* @param player The player on the server attempting to use an advanced
|
||||
* portal
|
||||
* @param moveActivated if the portal was activated by a move event (won't
|
||||
* trigger knockback)
|
||||
* @return
|
||||
*/
|
||||
public boolean activate(PlayerContainer player, boolean moveActivated) {
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
if (playerData.isInPortal()) return false;
|
||||
if (playerData.isInPortal())
|
||||
return false;
|
||||
playerData.setInPortal(true);
|
||||
if (playerData.hasJoinCooldown()) {
|
||||
var cooldown = (int) Math.ceil(playerData.getJoinCooldownLeft() / 1000D);
|
||||
player.sendMessage(
|
||||
Lang.translateInsertVariables(
|
||||
"portal.cooldown.join",
|
||||
cooldown,
|
||||
Lang.translate(cooldown == 1 ? "time.second" : "time.seconds")));
|
||||
var 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();
|
||||
player.playSound("block.portal.travel", 0.05f, rand.nextFloat() * 0.4F + 0.8F);
|
||||
player.playSound("block.portal.travel", 0.05f,
|
||||
rand.nextFloat() * 0.4F + 0.8F);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -135,25 +135,30 @@ public class AdvancedPortal implements TagTarget {
|
||||
}
|
||||
|
||||
for (DataTag portalTag : portalTags) {
|
||||
Tag.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
Tag.Activation activationHandler =
|
||||
tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
if (activationHandler != null) {
|
||||
if (!activationHandler.preActivated(
|
||||
this, player, data, this.getArgValues(portalTag.NAME))) {
|
||||
this, player, data,
|
||||
this.getArgValues(portalTag.NAME))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (DataTag portalTag : portalTags) {
|
||||
Tag.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
Tag.Activation activationHandler =
|
||||
tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
if (activationHandler != null) {
|
||||
if (!activationHandler.activated(
|
||||
this, player, data, this.getArgValues(portalTag.NAME))) {
|
||||
this, player, data,
|
||||
this.getArgValues(portalTag.NAME))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (DataTag portalTag : portalTags) {
|
||||
Tag.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
Tag.Activation activationHandler =
|
||||
tagRegistry.getActivationHandler(portalTag.NAME);
|
||||
if (activationHandler != null) {
|
||||
activationHandler.postActivated(
|
||||
this, player, data, this.getArgValues(portalTag.NAME));
|
||||
|
@ -4,5 +4,6 @@ public enum CommandErrorCode {
|
||||
INSUFFICIENT_ARGUMENTS(""),
|
||||
NO_PERMISSION("");
|
||||
|
||||
CommandErrorCode(String message) {}
|
||||
CommandErrorCode(String message) {
|
||||
}
|
||||
}
|
||||
|
@ -4,14 +4,10 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
|
||||
|
||||
public interface CommandHandler {
|
||||
void onExecute(
|
||||
String commandName,
|
||||
String parentCommand,
|
||||
CommandSenderContainer sender,
|
||||
ImmutableList<String> args);
|
||||
void onExecute(String commandName, String parentCommand,
|
||||
CommandSenderContainer sender, ImmutableList<String> args);
|
||||
|
||||
default void onCommandFailure(
|
||||
String[] command,
|
||||
default void onCommandFailure(String[] command,
|
||||
CommandSenderContainer sender,
|
||||
CommandException exception,
|
||||
ImmutableList<String> args) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.sekwah.advancedportals.core.registry;
|
||||
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
|
||||
public class RegisterBuilder<T extends CommandHandler> {
|
||||
@ -8,13 +7,13 @@ public class RegisterBuilder<T extends CommandHandler> {
|
||||
return new RegisterBuilder();
|
||||
}
|
||||
|
||||
private RegisterBuilder() {}
|
||||
private RegisterBuilder() {
|
||||
}
|
||||
|
||||
private boolean allowPermissionInheritance;
|
||||
private String scanDirectory;
|
||||
private final Class<T> genericType =
|
||||
(Class<T>)
|
||||
((ParameterizedType) getClass().getGenericSuperclass())
|
||||
(Class<T>) ((ParameterizedType) getClass().getGenericSuperclass())
|
||||
.getActualTypeArguments()[0];
|
||||
|
||||
public RegisterBuilder<T> inheritPermissions(boolean allowInheritance) {
|
||||
|
@ -3,24 +3,26 @@ package com.sekwah.advancedportals.core.registry;
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Do not register to here. Register to the sprcific subcommand registry classes.
|
||||
* Do not register to here. Register to the sprcific subcommand registry
|
||||
* classes.
|
||||
*
|
||||
* <p>Designed to let addons add new command sections to access, edit or add new functonality.
|
||||
* <p>Designed to let addons add new command sections to access, edit or add
|
||||
* new functonality.
|
||||
*
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class SubCommandRegistry {
|
||||
|
||||
protected Map<String, SubCommand> subCommandMap = new HashMap<>();
|
||||
|
||||
/** List of subcommand names which should be in order alphabetically */
|
||||
/**
|
||||
* List of subcommand names which should be in order alphabetically
|
||||
*/
|
||||
protected ArrayList<String> subCommands = new ArrayList<>();
|
||||
|
||||
@Inject private InfoLogger infoLogger;
|
||||
@ -31,14 +33,15 @@ public class SubCommandRegistry {
|
||||
* @return if the subcommand is registered or not
|
||||
*/
|
||||
public boolean registerSubCommand(String arg, SubCommand subCommand) {
|
||||
|
||||
if (subCommand == null) {
|
||||
this.infoLogger.warning("The subcommand '" + arg + "' cannot be null.");
|
||||
this.infoLogger.warning("The subcommand '" + arg
|
||||
+ "' cannot be null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.subCommandMap.containsKey(arg)) {
|
||||
this.infoLogger.warning("The subcommand '" + arg + "' already exists.");
|
||||
this.infoLogger.warning("The subcommand '" + arg
|
||||
+ "' already exists.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -59,7 +62,8 @@ public class SubCommandRegistry {
|
||||
}
|
||||
|
||||
/**
|
||||
* I may be wrong but for larger lists containsKey is faster with a hashmap than arraylist.
|
||||
* I may be wrong but for larger lists containsKey is faster with a hashmap
|
||||
* than arraylist.
|
||||
*
|
||||
* <p>Though im not sure at what size it becomes more efficient.
|
||||
*
|
||||
|
@ -3,19 +3,16 @@ package com.sekwah.advancedportals.core.registry;
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Allows a portal to register a tag and add a handler. If a plugin wants to add functionality
|
||||
* to someone elses tag then they should use the events.
|
||||
* Allows a portal to register a tag and add a handler. If a plugin wants to
|
||||
* add functionality to someone elses tag then they should use the events.
|
||||
*
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class TagRegistry {
|
||||
|
||||
@Inject
|
||||
AdvancedPortalsCore portalsCore;
|
||||
@Inject AdvancedPortalsCore portalsCore;
|
||||
|
||||
private final ArrayList<String> literalTags = new ArrayList<>();
|
||||
|
||||
@ -25,8 +22,7 @@ public class TagRegistry {
|
||||
private final Map<String, Tag.Creation> creationTags = new HashMap<>();
|
||||
private final Map<String, Tag.TagStatus> statusTags = new HashMap<>();
|
||||
|
||||
@Inject
|
||||
private AdvancedPortalsCore pluginCore;
|
||||
@Inject private AdvancedPortalsCore pluginCore;
|
||||
|
||||
/**
|
||||
* Portals to trigger when a portal is activated
|
||||
@ -68,17 +64,19 @@ public class TagRegistry {
|
||||
this.tags.add(tag);
|
||||
|
||||
// Check literal tags for clashes
|
||||
if(this.literalTags.contains(tagName)) {
|
||||
this.portalsCore.getInfoLogger().warning("A tag with the name " + tagName + " already exists.");
|
||||
if (this.literalTags.contains(tagName)) {
|
||||
this.portalsCore.getInfoLogger().warning(
|
||||
"A tag with the name " + tagName + " already exists.");
|
||||
return false;
|
||||
}
|
||||
|
||||
var aliases = tag.getAliases();
|
||||
this.literalTags.add(tagName);
|
||||
if(aliases != null) {
|
||||
if (aliases != null) {
|
||||
for (String alias : aliases) {
|
||||
if(this.literalTags.contains(alias)) {
|
||||
this.portalsCore.getInfoLogger().warning("A tag with the alias " + alias + " already exists.");
|
||||
if (this.literalTags.contains(alias)) {
|
||||
this.portalsCore.getInfoLogger().warning(
|
||||
"A tag with the alias " + alias + " already exists.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -103,7 +101,6 @@ public class TagRegistry {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public List<Tag> getTags() {
|
||||
// TODO Make a copy of the list to prevent issues with modification
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
package com.sekwah.advancedportals.core.registry;
|
||||
|
||||
/** Something that a tag can be executed on. */
|
||||
/**
|
||||
* Something that a tag can be executed on.
|
||||
*/
|
||||
public interface TagTarget {
|
||||
|
||||
/**
|
||||
* Get the values for the arg
|
||||
*
|
||||
|
@ -4,7 +4,6 @@ import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.effect.WarpEffect;
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -12,15 +11,11 @@ import java.util.Map;
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class WarpEffectRegistry {
|
||||
|
||||
|
||||
private Map<String, WarpEffect> warpEffects = new HashMap();
|
||||
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
@Inject private AdvancedPortalsCore portalsCore;
|
||||
|
||||
@Inject
|
||||
private InfoLogger infoLogger;
|
||||
@Inject private InfoLogger infoLogger;
|
||||
|
||||
/**
|
||||
* Register a new warp effect.
|
||||
@ -30,50 +25,49 @@ public class WarpEffectRegistry {
|
||||
* @return if the effect was registered
|
||||
*/
|
||||
public void registerEffect(String name, WarpEffect effect) {
|
||||
|
||||
if(name == null){
|
||||
if (name == null) {
|
||||
this.infoLogger.warning("Effect name cannot be null");
|
||||
return;
|
||||
}
|
||||
if(this.warpEffects.containsKey(name)){
|
||||
this.infoLogger.warning("Effect with the name: " + name + " already exists");
|
||||
if (this.warpEffects.containsKey(name)) {
|
||||
this.infoLogger.warning("Effect with the name: " + name
|
||||
+ " already exists");
|
||||
return;
|
||||
}
|
||||
this.warpEffects.put(name, effect);
|
||||
}
|
||||
|
||||
public WarpEffect.Visual getVisualEffect(String name){
|
||||
if(this.warpEffects.containsKey(name)) {
|
||||
public WarpEffect.Visual getVisualEffect(String name) {
|
||||
if (this.warpEffects.containsKey(name)) {
|
||||
var effect = this.warpEffects.get(name);
|
||||
if(effect instanceof WarpEffect.Visual visual){
|
||||
if (effect instanceof WarpEffect.Visual visual) {
|
||||
return visual;
|
||||
}
|
||||
else{
|
||||
this.infoLogger.warning("Effect called " + name + " is not a visual effect");
|
||||
} else {
|
||||
this.infoLogger.warning("Effect called " + name
|
||||
+ " is not a visual effect");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else{
|
||||
this.infoLogger.warning("No effect called " + name + " was registered");
|
||||
} else {
|
||||
this.infoLogger.warning("No effect called " + name
|
||||
+ " was registered");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public WarpEffect.Sound getSoundEffect(String name){
|
||||
if(this.warpEffects.containsKey(name)) {
|
||||
public WarpEffect.Sound getSoundEffect(String name) {
|
||||
if (this.warpEffects.containsKey(name)) {
|
||||
var effect = this.warpEffects.get(name);
|
||||
if(effect instanceof WarpEffect.Sound sound){
|
||||
if (effect instanceof WarpEffect.Sound sound) {
|
||||
return sound;
|
||||
} else {
|
||||
this.infoLogger.warning("Effect called " + name
|
||||
+ " is not a sound effect");
|
||||
return null;
|
||||
}
|
||||
else{
|
||||
this.infoLogger.warning("Effect called " + name + " is not a sound effect");
|
||||
} else {
|
||||
this.infoLogger.warning("No effect called " + name
|
||||
+ " was registered");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else{
|
||||
this.infoLogger.warning("No effect called " + name + " was registered");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.sekwah.advancedportals.core.repository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
|
||||
|
||||
public interface ConfigRepository {
|
||||
|
||||
boolean getUseOnlySpecialAxe();
|
||||
|
||||
String getTranslation();
|
||||
|
@ -3,7 +3,6 @@ package com.sekwah.advancedportals.core.repository;
|
||||
import java.util.List;
|
||||
|
||||
public interface IJsonRepository<T> {
|
||||
|
||||
boolean save(String name, T t);
|
||||
|
||||
boolean containsKey(String name);
|
||||
|
@ -4,12 +4,10 @@ import com.google.inject.Singleton;
|
||||
import com.sekwah.advancedportals.core.repository.ConfigRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
|
||||
import com.sekwah.advancedportals.core.serializeddata.config.Config;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Singleton
|
||||
public class ConfigRepositoryImpl implements ConfigRepository {
|
||||
|
||||
private HashMap<String, Config> configs;
|
||||
private Config config;
|
||||
private DataStorage dataStorage;
|
||||
@ -19,11 +17,9 @@ public class ConfigRepositoryImpl implements ConfigRepository {
|
||||
}
|
||||
|
||||
public <T> T getValue(String output) {
|
||||
|
||||
try {
|
||||
return (T) configs.get(output);
|
||||
} catch (ClassCastException ignored) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -5,10 +5,8 @@ import com.sekwah.advancedportals.core.destination.Destination;
|
||||
import com.sekwah.advancedportals.core.repository.IDestinationRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
|
||||
import com.sekwah.advancedportals.core.tags.activation.NameTag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
@ -19,7 +17,8 @@ public class DestinationRepositoryImpl implements IDestinationRepository {
|
||||
|
||||
@Override
|
||||
public boolean save(String name, Destination destination) {
|
||||
return dataStorage.storeFile(destination, fileLocation + name + ".yaml");
|
||||
return dataStorage.storeFile(destination,
|
||||
fileLocation + name + ".yaml");
|
||||
}
|
||||
|
||||
public boolean containsKey(String name) {
|
||||
@ -32,7 +31,8 @@ public class DestinationRepositoryImpl implements IDestinationRepository {
|
||||
}
|
||||
|
||||
public Destination get(String name) {
|
||||
return dataStorage.loadFile(Destination.class, fileLocation + name + ".yaml");
|
||||
return dataStorage.loadFile(Destination.class,
|
||||
fileLocation + name + ".yaml");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,7 +49,8 @@ public class DestinationRepositoryImpl implements IDestinationRepository {
|
||||
// Forces the name tag to be up-to-date on load
|
||||
String[] name = destination.getArgValues(NameTag.TAG_NAME);
|
||||
if (name != null && name.length > 0) {
|
||||
destination.setArgValues(NameTag.TAG_NAME, new String[] {fileName});
|
||||
destination.setArgValues(NameTag.TAG_NAME,
|
||||
new String[] {fileName});
|
||||
}
|
||||
destinations.add(destination);
|
||||
}
|
||||
|
@ -4,11 +4,9 @@ import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.repository.IPlayerDataRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerDataRepositoryImpl implements IPlayerDataRepository {
|
||||
|
||||
private final String fileLocation = "playerData/";
|
||||
|
||||
@Inject DataStorage dataStorage;
|
||||
@ -30,7 +28,8 @@ public class PlayerDataRepositoryImpl implements IPlayerDataRepository {
|
||||
|
||||
@Override
|
||||
public PlayerData get(String name) {
|
||||
return dataStorage.loadFile(PlayerData.class, fileLocation + name + ".yaml");
|
||||
return dataStorage.loadFile(PlayerData.class,
|
||||
fileLocation + name + ".yaml");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,21 +7,20 @@ import com.sekwah.advancedportals.core.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.repository.IPortalRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
|
||||
import com.sekwah.advancedportals.core.tags.activation.NameTag;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Singleton
|
||||
public class PortalRepositoryImpl implements IPortalRepository {
|
||||
|
||||
private final String fileLocation = "portals/";
|
||||
|
||||
@Inject DataStorage dataStorage;
|
||||
|
||||
/**
|
||||
* In memory copy of the portal files as they will be accessed every movement tick.
|
||||
* In memory copy of the portal files as they will be accessed every
|
||||
* movement tick.
|
||||
*
|
||||
* <p>If we need to get it by name we can just load it from the file, but this is good for
|
||||
* looping fast for the player move events.
|
||||
* <p>If we need to get it by name we can just load it from the file, but
|
||||
* this is good for looping fast for the player move events.
|
||||
*/
|
||||
private List<AdvancedPortal> portals = new ArrayList<>();
|
||||
|
||||
@ -42,9 +41,13 @@ public class PortalRepositoryImpl implements IPortalRepository {
|
||||
|
||||
@Override
|
||||
public AdvancedPortal get(String name) {
|
||||
var portal = dataStorage.loadFile(AdvancedPortal.class, fileLocation + name + ".yaml");
|
||||
var portal = dataStorage.loadFile(AdvancedPortal.class,
|
||||
fileLocation + name + ".yaml");
|
||||
if (portal != null) {
|
||||
AdvancedPortalsCore.getInstance().getModule().getInjector().injectMembers(portal);
|
||||
AdvancedPortalsCore.getInstance()
|
||||
.getModule()
|
||||
.getInjector()
|
||||
.injectMembers(portal);
|
||||
}
|
||||
return portal;
|
||||
}
|
||||
@ -59,12 +62,14 @@ public class PortalRepositoryImpl implements IPortalRepository {
|
||||
List<AdvancedPortal> portals = new ArrayList<>();
|
||||
List<String> allFiles = dataStorage.listAllFiles(fileLocation, false);
|
||||
for (String fileName : allFiles) {
|
||||
AdvancedPortal portal =
|
||||
dataStorage.loadFile(AdvancedPortal.class, fileLocation + fileName);
|
||||
AdvancedPortal portal = dataStorage.loadFile(
|
||||
AdvancedPortal.class, fileLocation + fileName);
|
||||
// Forces the name tag to be up-to-date on load
|
||||
String[] name = portal.getArgValues(NameTag.TAG_NAME);
|
||||
if (name != null && name.length > 0) {
|
||||
portal.setArgValues(NameTag.TAG_NAME, new String[] {fileName.replace(".yaml", "")});
|
||||
portal.setArgValues(
|
||||
NameTag.TAG_NAME,
|
||||
new String[] {fileName.replace(".yaml", "")});
|
||||
}
|
||||
portals.add(portal);
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package com.sekwah.advancedportals.core.serializeddata;
|
||||
import com.sekwah.advancedportals.core.data.Direction;
|
||||
|
||||
public class BlockLocation {
|
||||
|
||||
// These should be treated as final, they only are not for serialization purposes
|
||||
// These should be treated as final, they only are not for serialization
|
||||
// purposes
|
||||
private final int posX;
|
||||
|
||||
private final int posY;
|
||||
@ -51,8 +51,7 @@ public class BlockLocation {
|
||||
}
|
||||
|
||||
public boolean equals(BlockLocation location) {
|
||||
return location.posX == this.posX
|
||||
&& location.posY == this.posY
|
||||
return location.posX == this.posX && location.posY == this.posY
|
||||
&& location.posZ == this.posZ
|
||||
&& location.worldName.equals(this.worldName);
|
||||
}
|
||||
@ -73,6 +72,7 @@ public class BlockLocation {
|
||||
}
|
||||
|
||||
public BlockLocation addY(int offsetY) {
|
||||
return new BlockLocation(this.worldName, this.posX, (this.posY + offsetY), this.posZ);
|
||||
return new BlockLocation(this.worldName, this.posX,
|
||||
(this.posY + offsetY), this.posZ);
|
||||
}
|
||||
}
|
||||
|
@ -3,22 +3,19 @@ package com.sekwah.advancedportals.core.serializeddata;
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.LoaderOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.inspector.TagInspector;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.LoaderOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.inspector.TagInspector;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
|
||||
public class DataStorage {
|
||||
|
||||
private final File dataFolder;
|
||||
|
||||
@Inject private AdvancedPortalsCore portalsCore;
|
||||
@ -30,10 +27,10 @@ public class DataStorage {
|
||||
}
|
||||
|
||||
private Yaml getYaml(Class<? extends Object> clazz) {
|
||||
|
||||
LoaderOptions loaderOptions = new LoaderOptions();
|
||||
|
||||
TagInspector tagInspector = tag -> tag.getClassName().equals(clazz.getName());
|
||||
TagInspector tagInspector =
|
||||
tag -> tag.getClassName().equals(clazz.getName());
|
||||
|
||||
loaderOptions.setTagInspector(tagInspector);
|
||||
|
||||
@ -44,7 +41,10 @@ public class DataStorage {
|
||||
representer.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
var constructor = new ReflectiveConstructor(clazz, loaderOptions);
|
||||
|
||||
AdvancedPortalsCore.getInstance().getModule().getInjector().injectMembers(constructor);
|
||||
AdvancedPortalsCore.getInstance()
|
||||
.getModule()
|
||||
.getInjector()
|
||||
.injectMembers(constructor);
|
||||
|
||||
return new Yaml(constructor, representer);
|
||||
}
|
||||
@ -64,16 +64,15 @@ public class DataStorage {
|
||||
if (yamlResource == null) {
|
||||
try {
|
||||
return dataHolder.getDeclaredConstructor().newInstance();
|
||||
} catch (InstantiationException
|
||||
| IllegalAccessException
|
||||
| NoSuchMethodException
|
||||
| InvocationTargetException e) {
|
||||
} catch (InstantiationException | IllegalAccessException
|
||||
| NoSuchMethodException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Yaml yaml = getYaml(dataHolder);
|
||||
try (BufferedReader bufReader = new BufferedReader(new InputStreamReader(yamlResource))) {
|
||||
try (BufferedReader bufReader =
|
||||
new BufferedReader(new InputStreamReader(yamlResource))) {
|
||||
return yaml.loadAs(bufReader, dataHolder);
|
||||
} catch (Exception e) {
|
||||
infoLogger.warning("Failed to load file: " + location);
|
||||
@ -85,7 +84,8 @@ public class DataStorage {
|
||||
public boolean storeFile(Object dataHolder, String location) {
|
||||
Yaml yaml = getYaml(dataHolder.getClass());
|
||||
File outFile = new File(this.dataFolder, location);
|
||||
if (!outFile.getParentFile().exists() && !outFile.getParentFile().mkdirs()) {
|
||||
if (!outFile.getParentFile().exists()
|
||||
&& !outFile.getParentFile().mkdirs()) {
|
||||
infoLogger.warning("Failed to create folder for file: " + location);
|
||||
}
|
||||
|
||||
@ -103,8 +103,8 @@ public class DataStorage {
|
||||
* Copies the specified file out of the plugin and into the plugins folder.
|
||||
*
|
||||
* @param fileLoc
|
||||
* @return if the file is copied, will be false if override is false and the file already
|
||||
* existed.
|
||||
* @return if the file is copied, will be false if override is false and the
|
||||
* file already existed.
|
||||
*/
|
||||
public boolean copyDefaultFile(String fileLoc, boolean overwrite) {
|
||||
return this.copyDefaultFile(fileLoc, fileLoc, overwrite);
|
||||
@ -115,10 +115,11 @@ public class DataStorage {
|
||||
*
|
||||
* @param sourceLoc - location of the file in the jar
|
||||
* @param fileLoc - location to save the file
|
||||
* @return if the file is copied, will be false if override is false and the file already
|
||||
* existed.
|
||||
* @return if the file is copied, will be false if override is false and the
|
||||
* file already existed.
|
||||
*/
|
||||
public boolean copyDefaultFile(String sourceLoc, String fileLoc, boolean overwrite) {
|
||||
public boolean copyDefaultFile(String sourceLoc, String fileLoc,
|
||||
boolean overwrite) {
|
||||
File outFile = new File(this.dataFolder, fileLoc);
|
||||
if (!outFile.exists()) {
|
||||
outFile.getParentFile().mkdirs();
|
||||
@ -126,7 +127,8 @@ public class DataStorage {
|
||||
if (!outFile.exists() || overwrite) {
|
||||
try {
|
||||
InputStream inputStream =
|
||||
this.getClass().getClassLoader().getResourceAsStream(sourceLoc);
|
||||
this.getClass().getClassLoader().getResourceAsStream(
|
||||
sourceLoc);
|
||||
if (inputStream == null) {
|
||||
return false;
|
||||
}
|
||||
@ -134,11 +136,10 @@ public class DataStorage {
|
||||
writeToFile(inputStream, outFile);
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
this.infoLogger.warning(
|
||||
"Could not load "
|
||||
+ sourceLoc
|
||||
this.infoLogger.warning("Could not load " + sourceLoc
|
||||
+ ". The file does"
|
||||
+ "not exist or there has been an error reading the file.");
|
||||
+ ("not exist or there has been an "
|
||||
+ "error reading the file."));
|
||||
return false;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
@ -152,8 +153,8 @@ public class DataStorage {
|
||||
}
|
||||
|
||||
/**
|
||||
* A method to try to grab the files from the plugin and if its in the plugin folder load from
|
||||
* there instead.
|
||||
* A method to try to grab the files from the plugin and if its in the
|
||||
* plugin folder load from there instead.
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
@ -172,14 +173,14 @@ public class DataStorage {
|
||||
} else {
|
||||
try {
|
||||
copyDefaultFile(location, false);
|
||||
return this.getClass().getClassLoader().getResourceAsStream(location);
|
||||
return this.getClass().getClassLoader().getResourceAsStream(
|
||||
location);
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
this.infoLogger.warning(
|
||||
"Could not load "
|
||||
+ location
|
||||
this.infoLogger.warning("Could not load " + location
|
||||
+ ". The file does"
|
||||
+ "not exist or there has been an error reading the file.");
|
||||
+ ("not exist or there has been an "
|
||||
+ "error reading the file."));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -194,7 +195,8 @@ public class DataStorage {
|
||||
}
|
||||
}
|
||||
|
||||
private void writeToFile(InputStream inputStream, File outFile) throws IOException {
|
||||
private void writeToFile(InputStream inputStream, File outFile)
|
||||
throws IOException {
|
||||
try (FileOutputStream outStream = new FileOutputStream(outFile)) {
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
@ -209,7 +211,8 @@ public class DataStorage {
|
||||
return new File(this.dataFolder, name).exists();
|
||||
}
|
||||
|
||||
public List<String> listAllFiles(String fileLocation, boolean trimExtension) {
|
||||
public List<String> listAllFiles(String fileLocation,
|
||||
boolean trimExtension) {
|
||||
return listAllFiles(fileLocation, trimExtension, null);
|
||||
}
|
||||
|
||||
@ -219,7 +222,8 @@ public class DataStorage {
|
||||
* @param extension - if null will not filter by extension
|
||||
* @return
|
||||
*/
|
||||
public List<String> listAllFiles(String fileLocation, boolean trimExtension, String extension) {
|
||||
public List<String> listAllFiles(String fileLocation, boolean trimExtension,
|
||||
String extension) {
|
||||
File directory = new File(dataFolder, fileLocation);
|
||||
List<String> list = new ArrayList<>();
|
||||
|
||||
@ -230,7 +234,8 @@ public class DataStorage {
|
||||
if (file.isFile()) {
|
||||
String fileName = file.getName();
|
||||
boolean extensionMatches =
|
||||
(extension == null || fileName.endsWith("." + extension));
|
||||
(extension == null
|
||||
|| fileName.endsWith("." + extension));
|
||||
|
||||
if (extensionMatches) {
|
||||
if (trimExtension) {
|
||||
@ -245,7 +250,9 @@ public class DataStorage {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
infoLogger.warning("Directory does not exist or is not a directory: " + fileLocation);
|
||||
infoLogger.warning(
|
||||
"Directory does not exist or is not a directory: "
|
||||
+ fileLocation);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.sekwah.advancedportals.core.serializeddata;
|
||||
|
||||
public class DataTag {
|
||||
|
||||
public final String NAME;
|
||||
public final String[] VALUES;
|
||||
|
||||
|
@ -3,32 +3,44 @@ package com.sekwah.advancedportals.core.serializeddata;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Possibly one of the only files in this package not designed to be serialised.
|
||||
* Possibly one of the only files in this package not designed to be
|
||||
* serialised.
|
||||
*
|
||||
* <p>Any temporary data about players will be stored here and cleaned up when the player leaves the
|
||||
* server.
|
||||
* <p>Any temporary data about players will be stored here and cleaned up when
|
||||
* the player leaves the server.
|
||||
*
|
||||
* <p>This is not a place to store long term data e.g. if you want to make a player unable to use a
|
||||
* portal over hours/days.
|
||||
* <p>This is not a place to store long term data e.g. if you want to make a
|
||||
* player unable to use a portal over hours/days.
|
||||
*/
|
||||
public class PlayerData {
|
||||
|
||||
/** Portal selection position 1 */
|
||||
/**
|
||||
* Portal selection position 1
|
||||
*/
|
||||
private BlockLocation pos1;
|
||||
|
||||
/** Portal selection position 2 */
|
||||
/**
|
||||
* Portal selection position 2
|
||||
*/
|
||||
private BlockLocation pos2;
|
||||
|
||||
/** If to show portals near the player */
|
||||
/**
|
||||
* If to show portals near the player
|
||||
*/
|
||||
private boolean portalVisible = false;
|
||||
|
||||
/** If to show destination blocks near the player */
|
||||
/**
|
||||
* If to show destination blocks near the player
|
||||
*/
|
||||
private boolean destiVisible;
|
||||
|
||||
/** If the player is in a portal. Stops re-triggering. */
|
||||
/**
|
||||
* If the player is in a portal. Stops re-triggering.
|
||||
*/
|
||||
private transient boolean isInPortal = false;
|
||||
|
||||
/** The next time System.currentTimeMillis() a player can use a portal. */
|
||||
/**
|
||||
* The next time System.currentTimeMillis() a player can use a portal.
|
||||
*/
|
||||
private transient long joinCooldown;
|
||||
|
||||
private transient long netherPortalCooldown;
|
||||
@ -94,7 +106,8 @@ public class PlayerData {
|
||||
}
|
||||
|
||||
public void setNetherPortalCooldown(long netherPortalCooldown) {
|
||||
this.netherPortalCooldown = System.currentTimeMillis() + netherPortalCooldown;
|
||||
this.netherPortalCooldown =
|
||||
System.currentTimeMillis() + netherPortalCooldown;
|
||||
}
|
||||
|
||||
public boolean hasJoinCooldown() {
|
||||
@ -106,7 +119,8 @@ public class PlayerData {
|
||||
}
|
||||
|
||||
public void setPortalCooldown(String portalName, long cooldown) {
|
||||
perPortalCooldowns.put(portalName, System.currentTimeMillis() + cooldown);
|
||||
perPortalCooldowns.put(portalName,
|
||||
System.currentTimeMillis() + cooldown);
|
||||
}
|
||||
|
||||
public boolean hasPortalCooldown(String portalName) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.sekwah.advancedportals.core.serializeddata;
|
||||
|
||||
public class PlayerLocation extends WorldLocation {
|
||||
|
||||
private final float yaw;
|
||||
|
||||
private final float pitch;
|
||||
@ -12,14 +11,15 @@ public class PlayerLocation extends WorldLocation {
|
||||
this.pitch = 0;
|
||||
}
|
||||
|
||||
public PlayerLocation(String worldName, double posX, double posY, double posZ) {
|
||||
public PlayerLocation(String worldName, double posX, double posY,
|
||||
double posZ) {
|
||||
super(worldName, posX, posY, posZ);
|
||||
this.yaw = 0;
|
||||
this.pitch = 0;
|
||||
}
|
||||
|
||||
public PlayerLocation(
|
||||
String worldName, double posX, double posY, double posZ, float yaw, float pitch) {
|
||||
public PlayerLocation(String worldName, double posX, double posY,
|
||||
double posZ, float yaw, float pitch) {
|
||||
super(worldName, posX, posY, posZ);
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
|
@ -1,23 +1,21 @@
|
||||
package com.sekwah.advancedportals.core.serializeddata;
|
||||
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
import org.yaml.snakeyaml.LoaderOptions;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
import org.yaml.snakeyaml.nodes.*;
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ReflectiveConstructor<T> extends Constructor {
|
||||
private static final Unsafe unsafe = getUnsafe();
|
||||
private final Class<T> clazz;
|
||||
|
||||
@Inject
|
||||
private InfoLogger infoLogger;
|
||||
@Inject private InfoLogger infoLogger;
|
||||
|
||||
public ReflectiveConstructor(Class<T> clazz, LoaderOptions loadingConfig) {
|
||||
super(clazz, loadingConfig);
|
||||
@ -34,10 +32,11 @@ public class ReflectiveConstructor<T> extends Constructor {
|
||||
return constructFromMappingNode(currentClass, (MappingNode) node);
|
||||
} else if (node instanceof ScalarNode scalarNode) {
|
||||
return constructFromScalarNode(scalarNode);
|
||||
} else if(node instanceof SequenceNode sequenceNode) {
|
||||
} else if (node instanceof SequenceNode sequenceNode) {
|
||||
return constructFromSequenceNode(sequenceNode);
|
||||
} else {
|
||||
infoLogger.warning("Unexpected node type encountered: " + node.getClass().getSimpleName());
|
||||
infoLogger.warning("Unexpected node type encountered: "
|
||||
+ node.getClass().getSimpleName());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -58,9 +57,10 @@ public class ReflectiveConstructor<T> extends Constructor {
|
||||
return array;
|
||||
}
|
||||
|
||||
private <U> Object constructFromMappingNode(Class<U> currentClass, MappingNode mappingNode) {
|
||||
|
||||
// if the class is a hashmap, loop over the values and construct the objects
|
||||
private <U> Object constructFromMappingNode(Class<U> currentClass,
|
||||
MappingNode mappingNode) {
|
||||
// if the class is a hashmap, loop over the values and construct the
|
||||
// objects
|
||||
if (currentClass.equals(HashMap.class)) {
|
||||
Map<String, Object> values = new HashMap<>();
|
||||
for (NodeTuple tuple : mappingNode.getValue()) {
|
||||
@ -71,18 +71,23 @@ public class ReflectiveConstructor<T> extends Constructor {
|
||||
if (node instanceof ScalarNode scalarNode) {
|
||||
var constructedItem = constructFromScalarNode(scalarNode);
|
||||
values.put(key, constructedItem);
|
||||
} else if(node instanceof SequenceNode sequenceNode) {
|
||||
var constructedItem = constructFromSequenceNode(sequenceNode);
|
||||
} else if (node instanceof SequenceNode sequenceNode) {
|
||||
var constructedItem =
|
||||
constructFromSequenceNode(sequenceNode);
|
||||
values.put(key, constructedItem);
|
||||
} else if (node instanceof MappingNode mappingNodeChild) {
|
||||
try {
|
||||
Object value = constructFromMappingNode(Object.class, mappingNodeChild);
|
||||
Object value = constructFromMappingNode(
|
||||
Object.class, mappingNodeChild);
|
||||
values.put(key, value);
|
||||
} catch (Exception e) {
|
||||
infoLogger.warning("Failed to construct object from mapping node: " + e.getMessage());
|
||||
infoLogger.warning(
|
||||
"Failed to construct object from mapping node: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
} else {
|
||||
infoLogger.warning("Unexpected node type encountered: " + node.getClass().getSimpleName());
|
||||
infoLogger.warning("Unexpected node type encountered: "
|
||||
+ node.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
return values;
|
||||
@ -93,11 +98,14 @@ public class ReflectiveConstructor<T> extends Constructor {
|
||||
try {
|
||||
instance = currentClass.getDeclaredConstructor().newInstance();
|
||||
} catch (NoSuchMethodException e) {
|
||||
infoLogger.info("No default constructor found for " + currentClass.getName() + ", using unsafe allocation.");
|
||||
infoLogger.info("No default constructor found for "
|
||||
+ currentClass.getName()
|
||||
+ ", using unsafe allocation.");
|
||||
instance = unsafe.allocateInstance(currentClass);
|
||||
}
|
||||
|
||||
Map<String, Object> mappedValues = mapMappingNode(currentClass, mappingNode);
|
||||
Map<String, Object> mappedValues =
|
||||
mapMappingNode(currentClass, mappingNode);
|
||||
|
||||
Field[] fields = getAllFields(currentClass);
|
||||
for (Field field : fields) {
|
||||
@ -111,19 +119,28 @@ public class ReflectiveConstructor<T> extends Constructor {
|
||||
|
||||
setField(instance, field, value);
|
||||
} else {
|
||||
infoLogger.warning("Field " + field.getName() + " not found in mapping node " + instance.getClass().getName() + " will use default value.");
|
||||
infoLogger.warning("Field " + field.getName()
|
||||
+ " not found in mapping node "
|
||||
+ instance.getClass().getName()
|
||||
+ " will use default value.");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
infoLogger.warning("Failed to set field " + field.getName() + " in " + currentClass.getName() + ": " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
infoLogger.warning("Failed to set field " + field.getName()
|
||||
+ " in " + currentClass.getName()
|
||||
+ ": " + e.getMessage());
|
||||
infoLogger.error(e);
|
||||
throw new RuntimeException("Failed to set field " + field.getName() + " in " + currentClass.getName(), e);
|
||||
throw new RuntimeException("Failed to set field "
|
||||
+ field.getName() + " in "
|
||||
+ currentClass.getName(),
|
||||
e);
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
} catch (Exception e) {
|
||||
infoLogger.warning("Failed to instantiate " + currentClass.getName() + ": " + e.getMessage());
|
||||
throw new RuntimeException("Failed to instantiate " + currentClass.getName(), e);
|
||||
infoLogger.warning("Failed to instantiate " + currentClass.getName()
|
||||
+ ": " + e.getMessage());
|
||||
throw new RuntimeException(
|
||||
"Failed to instantiate " + currentClass.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,7 +159,8 @@ public class ReflectiveConstructor<T> extends Constructor {
|
||||
return super.constructObject(scalarNode);
|
||||
}
|
||||
|
||||
private Map<String, Object> mapMappingNode(Class<?> currentClass, MappingNode mappingNode) {
|
||||
private Map<String, Object> mapMappingNode(Class<?> currentClass,
|
||||
MappingNode mappingNode) {
|
||||
Map<String, Object> values = new HashMap<>();
|
||||
for (NodeTuple tuple : mappingNode.getValue()) {
|
||||
var key = (String) super.constructObject(tuple.getKeyNode());
|
||||
@ -154,13 +172,16 @@ public class ReflectiveConstructor<T> extends Constructor {
|
||||
} else if (node instanceof MappingNode mappingNodeChild) {
|
||||
try {
|
||||
var field = currentClass.getDeclaredField(key);
|
||||
Object value = constructFromMappingNode(field.getType(), mappingNodeChild);
|
||||
Object value = constructFromMappingNode(field.getType(),
|
||||
mappingNodeChild);
|
||||
values.put(key, value);
|
||||
} catch (NoSuchFieldException e) {
|
||||
infoLogger.warning("Field " + key + " not found on " + currentClass.getName());
|
||||
infoLogger.warning("Field " + key + " not found on "
|
||||
+ currentClass.getName());
|
||||
}
|
||||
} else {
|
||||
infoLogger.warning("Expected mapping node: " + node.getClass().getSimpleName());
|
||||
infoLogger.warning("Expected mapping node: "
|
||||
+ node.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
return values;
|
||||
@ -169,14 +190,14 @@ public class ReflectiveConstructor<T> extends Constructor {
|
||||
/**
|
||||
* Check and convert value types e.g. double to float
|
||||
*/
|
||||
private void setField(Object instance, Field field, Object value) throws IllegalAccessException {
|
||||
|
||||
private void setField(Object instance, Field field, Object value)
|
||||
throws IllegalAccessException {
|
||||
// Check for numeric type compatibility and cast if necessary
|
||||
if (field.getType() == float.class && value instanceof Double) {
|
||||
if (field.getType() == float.class &&value instanceof Double) {
|
||||
value = ((Double) value).floatValue();
|
||||
} else if (field.getType() == int.class && value instanceof Long) {
|
||||
} else if (field.getType() == int.class &&value instanceof Long) {
|
||||
value = ((Long) value).intValue();
|
||||
} else if (field.getType() == short.class && value instanceof Integer) {
|
||||
} else if (field.getType() == short.class &&value instanceof Integer) {
|
||||
value = ((Integer) value).shortValue();
|
||||
} else if (field.getType() == byte.class && value instanceof Integer) {
|
||||
value = ((Integer) value).byteValue();
|
||||
@ -186,7 +207,6 @@ public class ReflectiveConstructor<T> extends Constructor {
|
||||
field.set(instance, value);
|
||||
}
|
||||
|
||||
|
||||
private static Unsafe getUnsafe() {
|
||||
try {
|
||||
Field f = Unsafe.class.getDeclaredField("theUnsafe");
|
||||
|
@ -5,7 +5,6 @@ import org.yaml.snakeyaml.introspector.BeanAccess;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
public class ReflectiveRepresenter extends Representer {
|
||||
|
||||
public ReflectiveRepresenter(DumperOptions options) {
|
||||
super(options);
|
||||
this.getPropertyUtils().setBeanAccess(BeanAccess.FIELD);
|
||||
|
@ -1,18 +1,16 @@
|
||||
package com.sekwah.advancedportals.core.serializeddata;
|
||||
|
||||
public class WorldLocation extends Vector {
|
||||
|
||||
public final String worldName;
|
||||
|
||||
public WorldLocation(String worldName, double posX, double posY, double posZ) {
|
||||
public WorldLocation(String worldName, double posX, double posY,
|
||||
double posZ) {
|
||||
super(posX, posY, posZ);
|
||||
this.worldName = worldName;
|
||||
}
|
||||
|
||||
public BlockLocation toBlockPos() {
|
||||
return new BlockLocation(
|
||||
this.worldName,
|
||||
(int) Math.floor(this.x),
|
||||
return new BlockLocation(this.worldName, (int) Math.floor(this.x),
|
||||
(int) Math.floor(this.y),
|
||||
(int) Math.floor(this.z));
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
package com.sekwah.advancedportals.core.serializeddata.config;
|
||||
|
||||
/** To store the data for config */
|
||||
/**
|
||||
* To store the data for config
|
||||
*/
|
||||
public class Config {
|
||||
|
||||
public boolean useOnlySpecialAxe = true;
|
||||
|
||||
public String selectorMaterial = "IRON_AXE";
|
||||
|
@ -1,7 +1,3 @@
|
||||
package com.sekwah.advancedportals.core.services;
|
||||
|
||||
public enum Creation {
|
||||
SUCCESS,
|
||||
NAME_IN_USE,
|
||||
TAG_REJECTED
|
||||
}
|
||||
public enum Creation { SUCCESS, NAME_IN_USE, TAG_REJECTED }
|
||||
|
@ -9,17 +9,14 @@ import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class DestinationServices {
|
||||
|
||||
@Inject private IDestinationRepository destinationRepository;
|
||||
|
||||
@Inject TagRegistry tagRegistry;
|
||||
@ -43,38 +40,40 @@ public class DestinationServices {
|
||||
}
|
||||
}
|
||||
|
||||
public Destination createDesti(PlayerLocation playerLocation, List<DataTag> tags) {
|
||||
public Destination createDesti(PlayerLocation playerLocation,
|
||||
List<DataTag> tags) {
|
||||
return createDesti(null, playerLocation, tags);
|
||||
}
|
||||
|
||||
public Destination createDesti(
|
||||
PlayerContainer player, PlayerLocation playerLocation, List<DataTag> tags) {
|
||||
public Destination createDesti(PlayerContainer player,
|
||||
PlayerLocation playerLocation,
|
||||
List<DataTag> tags) {
|
||||
// Find the tag with the "name" NAME
|
||||
DataTag nameTag =
|
||||
tags.stream().filter(tag -> tag.NAME.equals("name")).findFirst().orElse(null);
|
||||
DataTag nameTag = tags.stream()
|
||||
.filter(tag -> tag.NAME.equals("name"))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
String name = nameTag == null ? null : nameTag.VALUES[0];
|
||||
|
||||
// If the name is null, send an error saying that the name is required.
|
||||
if (nameTag == null) {
|
||||
if (player != null)
|
||||
player.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
player.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("desti.error.noname"));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (name == null || name.equals("")) {
|
||||
if (player != null)
|
||||
player.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
player.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("command.error.noname"));
|
||||
return null;
|
||||
} else if (this.destinationRepository.containsKey(name)) {
|
||||
if (player != null)
|
||||
player.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
+ Lang.translateInsertVariables("command.error.nametaken", name));
|
||||
player.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translateInsertVariables(
|
||||
"command.error.nametaken", name));
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -83,7 +82,8 @@ public class DestinationServices {
|
||||
desti.setArgValues(portalTag);
|
||||
}
|
||||
for (DataTag destiTag : tags) {
|
||||
Tag.Creation creation = tagRegistry.getCreationHandler(destiTag.NAME);
|
||||
Tag.Creation creation =
|
||||
tagRegistry.getCreationHandler(destiTag.NAME);
|
||||
if (creation != null) {
|
||||
if (!creation.created(desti, player, destiTag.VALUES)) {
|
||||
return null;
|
||||
@ -98,13 +98,14 @@ public class DestinationServices {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
player.sendMessage(
|
||||
Lang.translate("messageprefix.negative") + Lang.translate("desti.error.save"));
|
||||
player.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("desti.error.save"));
|
||||
}
|
||||
return desti;
|
||||
}
|
||||
|
||||
public boolean removeDestination(String name, PlayerContainer playerContainer) {
|
||||
public boolean removeDestination(String name,
|
||||
PlayerContainer playerContainer) {
|
||||
this.destinationCache.remove(name);
|
||||
if (this.destinationRepository.containsKey(name)) {
|
||||
this.destinationRepository.delete(name);
|
||||
@ -117,9 +118,11 @@ public class DestinationServices {
|
||||
return destinationCache.get(name);
|
||||
}
|
||||
|
||||
public boolean teleportToDestination(String name, PlayerContainer playerContainer) {
|
||||
public boolean teleportToDestination(String name,
|
||||
PlayerContainer playerContainer) {
|
||||
if (this.destinationRepository.containsKey(name)) {
|
||||
playerContainer.teleport(this.destinationRepository.get(name).getLoc());
|
||||
playerContainer.teleport(
|
||||
this.destinationRepository.get(name).getLoc());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -7,17 +7,16 @@ import com.sekwah.advancedportals.core.repository.IPlayerDataRepository;
|
||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerData;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public final class PlayerDataServices {
|
||||
|
||||
/** Possibly change to the cache map Aztec was talking about */
|
||||
/**
|
||||
* Possibly change to the cache map Aztec was talking about
|
||||
*/
|
||||
private Map<UUID, PlayerData> tempDataMap = new HashMap<>();
|
||||
|
||||
@Inject private IPlayerDataRepository tempDataRepository;
|
||||
@ -25,9 +24,7 @@ public final class PlayerDataServices {
|
||||
@Inject private ConfigRepository configRepository;
|
||||
|
||||
public PlayerData getPlayerData(PlayerContainer player) {
|
||||
return tempDataMap.computeIfAbsent(
|
||||
player.getUUID(),
|
||||
uuid -> {
|
||||
return tempDataMap.computeIfAbsent(player.getUUID(), uuid -> {
|
||||
var tempData = tempDataRepository.get(player.getUUID().toString());
|
||||
|
||||
if (tempData == null) {
|
||||
@ -43,24 +40,22 @@ public final class PlayerDataServices {
|
||||
}
|
||||
|
||||
public void playerLeave(PlayerContainer player) {
|
||||
tempDataRepository.save(player.getUUID().toString(), getPlayerData(player));
|
||||
tempDataRepository.save(player.getUUID().toString(),
|
||||
getPlayerData(player));
|
||||
tempDataMap.remove(player.getUUID());
|
||||
}
|
||||
|
||||
public void playerSelectorActivate(
|
||||
PlayerContainer player, BlockLocation blockLoc, boolean leftClick) {
|
||||
public void playerSelectorActivate(PlayerContainer player,
|
||||
BlockLocation blockLoc,
|
||||
boolean leftClick) {
|
||||
var tempData = getPlayerData(player);
|
||||
if (leftClick) {
|
||||
tempData.setPos1(blockLoc);
|
||||
} else {
|
||||
tempData.setPos2(blockLoc);
|
||||
}
|
||||
player.sendMessage(
|
||||
Lang.translateInsertVariables(
|
||||
"portal.selector.poschange",
|
||||
leftClick ? "1" : "2",
|
||||
blockLoc.getPosX(),
|
||||
blockLoc.getPosY(),
|
||||
blockLoc.getPosZ()));
|
||||
player.sendMessage(Lang.translateInsertVariables(
|
||||
"portal.selector.poschange", leftClick ? "1" : "2",
|
||||
blockLoc.getPosX(), blockLoc.getPosY(), blockLoc.getPosZ()));
|
||||
}
|
||||
}
|
||||
|
@ -14,14 +14,11 @@ import com.sekwah.advancedportals.core.tags.activation.NameTag;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.util.PlayerUtils;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class PortalServices {
|
||||
|
||||
@Inject private IPortalRepository portalRepository;
|
||||
|
||||
@Inject private transient PlayerDataServices playerDataServices;
|
||||
@ -47,7 +44,8 @@ public class PortalServices {
|
||||
|
||||
public boolean inPortalRegionProtected(BlockLocation loc) {
|
||||
for (AdvancedPortal portal : portalCache.values()) {
|
||||
if (portal.isLocationInPortal(loc, configRepository.getProtectionRadius())) {
|
||||
if (portal.isLocationInPortal(
|
||||
loc, configRepository.getProtectionRadius())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -56,7 +54,8 @@ public class PortalServices {
|
||||
|
||||
public boolean inPortalRegionProtected(PlayerLocation loc) {
|
||||
for (AdvancedPortal portal : portalCache.values()) {
|
||||
if (portal.isLocationInPortal(loc, configRepository.getProtectionRadius())) {
|
||||
if (portal.isLocationInPortal(
|
||||
loc, configRepository.getProtectionRadius())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -73,7 +72,6 @@ public class PortalServices {
|
||||
}
|
||||
|
||||
public void playerMove(PlayerContainer player, PlayerLocation toLoc) {
|
||||
|
||||
var blockLoc = toLoc.toBlockPos();
|
||||
var blockEntityTopLoc = blockLoc.addY(player.getHeight());
|
||||
var world = player.getWorld();
|
||||
@ -82,7 +80,8 @@ public class PortalServices {
|
||||
|
||||
var notInPortal = true;
|
||||
for (AdvancedPortal portal : portalCache.values()) {
|
||||
if ((portal.isLocationInPortal(toLoc) && portal.isTriggerBlock(blockMaterial))
|
||||
if ((portal.isLocationInPortal(toLoc)
|
||||
&& portal.isTriggerBlock(blockMaterial))
|
||||
|| (portal.isLocationInPortal(blockEntityTopLoc)
|
||||
&& portal.isTriggerBlock(blockEntityTopMaterial))) {
|
||||
notInPortal = false;
|
||||
@ -118,11 +117,13 @@ public class PortalServices {
|
||||
return false;
|
||||
}
|
||||
|
||||
public AdvancedPortal createPortal(BlockLocation pos1, BlockLocation pos2, List<DataTag> tags) {
|
||||
public AdvancedPortal createPortal(BlockLocation pos1, BlockLocation pos2,
|
||||
List<DataTag> tags) {
|
||||
return createPortal(null, pos1, pos2, tags);
|
||||
}
|
||||
|
||||
public AdvancedPortal createPortal(PlayerContainer player, ArrayList<DataTag> tags) {
|
||||
public AdvancedPortal createPortal(PlayerContainer player,
|
||||
ArrayList<DataTag> tags) {
|
||||
PlayerData tempData = playerDataServices.getPlayerData(player);
|
||||
|
||||
if (tempData.getPos1() == null || tempData.getPos2() == null) {
|
||||
@ -132,21 +133,23 @@ public class PortalServices {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!tempData.getPos1().getWorldName().equals(tempData.getPos2().getWorldName())) {
|
||||
if (!tempData.getPos1().getWorldName().equals(
|
||||
tempData.getPos2().getWorldName())) {
|
||||
player.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("portal.error.selection.differentworlds"));
|
||||
return null;
|
||||
}
|
||||
|
||||
return createPortal(player, tempData.getPos1(), tempData.getPos2(), tags);
|
||||
return createPortal(player, tempData.getPos1(), tempData.getPos2(),
|
||||
tags);
|
||||
}
|
||||
|
||||
public AdvancedPortal createPortal(
|
||||
PlayerContainer player, BlockLocation pos1, BlockLocation pos2, List<DataTag> tags) {
|
||||
public AdvancedPortal createPortal(PlayerContainer player,
|
||||
BlockLocation pos1, BlockLocation pos2,
|
||||
List<DataTag> tags) {
|
||||
// Find the tag with the "name" NAME
|
||||
DataTag nameTag =
|
||||
tags.stream()
|
||||
DataTag nameTag = tags.stream()
|
||||
.filter(tag -> tag.NAME.equals(NameTag.TAG_NAME))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
@ -154,26 +157,27 @@ public class PortalServices {
|
||||
String name = nameTag == null ? null : nameTag.VALUES[0];
|
||||
if (nameTag == null || name == null || name.isEmpty()) {
|
||||
if (player != null)
|
||||
player.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
player.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("command.error.noname"));
|
||||
return null;
|
||||
} else if (this.portalRepository.containsKey(name)) {
|
||||
if (player != null)
|
||||
player.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
+ Lang.translateInsertVariables("command.error.nametaken", name));
|
||||
player.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translateInsertVariables(
|
||||
"command.error.nametaken", name));
|
||||
return null;
|
||||
}
|
||||
|
||||
AdvancedPortal portal = new AdvancedPortal(pos1, pos2, tagRegistry, playerDataServices);
|
||||
AdvancedPortal portal =
|
||||
new AdvancedPortal(pos1, pos2, tagRegistry, playerDataServices);
|
||||
|
||||
for (DataTag portalTag : tags) {
|
||||
portal.setArgValues(portalTag);
|
||||
}
|
||||
|
||||
for (DataTag portalTag : tags) {
|
||||
Tag.Creation creation = tagRegistry.getCreationHandler(portalTag.NAME);
|
||||
Tag.Creation creation =
|
||||
tagRegistry.getCreationHandler(portalTag.NAME);
|
||||
if (creation != null) {
|
||||
if (!creation.created(portal, player, portalTag.VALUES)) {
|
||||
return null;
|
||||
@ -190,8 +194,7 @@ public class PortalServices {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (player != null)
|
||||
player.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
player.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("portal.error.save"));
|
||||
}
|
||||
|
||||
|
@ -13,26 +13,20 @@ import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.util.PlayerUtils;
|
||||
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class CooldownTag implements Tag.Activation, Tag.Creation {
|
||||
@Inject transient PlayerDataServices playerDataServices;
|
||||
|
||||
@Inject
|
||||
transient PlayerDataServices playerDataServices;
|
||||
@Inject transient ConfigRepository configRepository;
|
||||
|
||||
@Inject
|
||||
transient ConfigRepository configRepository;
|
||||
|
||||
|
||||
@Inject
|
||||
private InfoLogger infoLogger;
|
||||
@Inject private InfoLogger infoLogger;
|
||||
|
||||
public static String TAG_NAME = "cooldown";
|
||||
|
||||
private final TagType[] tagTypes = new TagType[]{ TagType.PORTAL };
|
||||
private final TagType[] tagTypes = new TagType[] {TagType.PORTAL};
|
||||
|
||||
@Override
|
||||
public TagType[] getTagTypes() {
|
||||
@ -56,16 +50,22 @@ public class CooldownTag implements Tag.Activation, Tag.Creation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preActivated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) {
|
||||
public boolean preActivated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activationData,
|
||||
String[] argData) {
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
if(target instanceof AdvancedPortal portal) {
|
||||
if (target instanceof AdvancedPortal portal) {
|
||||
var portalName = portal.getName();
|
||||
if(playerData.hasPortalCooldown(portalName)) {
|
||||
var cooldown = (int) Math.ceil(playerData.getPortalCooldownLeft(portalName) / 1000D);
|
||||
player.sendMessage(Lang.translateInsertVariables("portal.cooldown.individual", cooldown,
|
||||
Lang.translate(cooldown == 1 ? "time.second" : "time.seconds")));
|
||||
if(configRepository.playFailSound()) {
|
||||
player.playSound("block.portal.travel", 0.05f, new Random().nextFloat() * 0.4F + 0.8F);
|
||||
if (playerData.hasPortalCooldown(portalName)) {
|
||||
var cooldown = (int) Math.ceil(
|
||||
playerData.getPortalCooldownLeft(portalName) / 1000D);
|
||||
player.sendMessage(Lang.translateInsertVariables(
|
||||
"portal.cooldown.individual", cooldown,
|
||||
Lang.translate(cooldown == 1 ? "time.second"
|
||||
: "time.seconds")));
|
||||
if (configRepository.playFailSound()) {
|
||||
player.playSound("block.portal.travel", 0.05f,
|
||||
new Random().nextFloat() * 0.4F + 0.8F);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -75,37 +75,44 @@ public class CooldownTag implements Tag.Activation, Tag.Creation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postActivated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) {
|
||||
if(activationData.hasActivated()) {
|
||||
if(target instanceof AdvancedPortal portal) {
|
||||
public void postActivated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activationData, String[] argData) {
|
||||
if (activationData.hasActivated()) {
|
||||
if (target instanceof AdvancedPortal portal) {
|
||||
var playerData = playerDataServices.getPlayerData(player);
|
||||
try {
|
||||
playerData.setPortalCooldown(portal.getName(), Integer.parseInt(argData[0]) * 1000);
|
||||
playerData.setPortalCooldown(
|
||||
portal.getName(), Integer.parseInt(argData[0]) * 1000);
|
||||
} catch (NumberFormatException e) {
|
||||
infoLogger.warning("Cooldown tag failed to set cooldown for portal: " + portal.getName() + " with value: " + argData[0]);
|
||||
infoLogger.warning(
|
||||
"Cooldown tag failed to set cooldown for portal: "
|
||||
+ portal.getName() + " with value: " + argData[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) {
|
||||
public boolean activated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activationData, String[] argData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean created(TagTarget target, PlayerContainer player, String[] argData) {
|
||||
public boolean created(TagTarget target, PlayerContainer player,
|
||||
String[] argData) {
|
||||
try {
|
||||
Integer.parseInt(argData[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("tag.cooldown.fail"));
|
||||
player.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("tag.cooldown.fail"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyed(TagTarget target, PlayerContainer player, String[] argData) {
|
||||
|
||||
public void destroyed(TagTarget target, PlayerContainer player,
|
||||
String[] argData) {
|
||||
}
|
||||
}
|
||||
|
@ -10,13 +10,10 @@ import com.sekwah.advancedportals.core.services.DestinationServices;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
||||
|
||||
public static String TAG_NAME = "destination";
|
||||
@Inject DestinationServices destinationServices;
|
||||
|
||||
@ -45,8 +42,8 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preActivated(
|
||||
TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) {
|
||||
public boolean preActivated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activeData, String[] argData) {
|
||||
// Check that the destination exists.
|
||||
for (String destiName : destinationServices.getDestinationNames()) {
|
||||
if (destiName.equalsIgnoreCase(argData[0])) {
|
||||
@ -57,19 +54,15 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postActivated(
|
||||
TagTarget target,
|
||||
PlayerContainer player,
|
||||
ActivationData activationData,
|
||||
String[] argData) {}
|
||||
public void postActivated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activationData, String[] argData) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activated(
|
||||
TagTarget target,
|
||||
PlayerContainer player,
|
||||
ActivationData activationData,
|
||||
String[] argData) {
|
||||
Destination destination = destinationServices.getDestination(argData[0]);
|
||||
public boolean activated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activationData, String[] argData) {
|
||||
Destination destination =
|
||||
destinationServices.getDestination(argData[0]);
|
||||
if (destination != null) {
|
||||
var warpEffectVisual = warpEffectRegistry.getVisualEffect("ender");
|
||||
if (warpEffectVisual != null) {
|
||||
|
@ -4,24 +4,23 @@ import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
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 javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* The name of the destination or portal.
|
||||
*
|
||||
* <p>Most of the implementation of this tag is external, this is just to allow for the tag to be
|
||||
* used.
|
||||
* <p>Most of the implementation of this tag is external, this is just to allow
|
||||
* for the tag to be used.
|
||||
*
|
||||
* <p>Most tags shouldn't be like this unless they are to be paired with another tag.
|
||||
* <p>Most tags shouldn't be like this unless they are to be paired with
|
||||
* another tag.
|
||||
*/
|
||||
public class NameTag implements Tag.AutoComplete, Tag.Creation {
|
||||
|
||||
public static String TAG_NAME = "name";
|
||||
|
||||
private final TagType[] tagTypes = new TagType[] {TagType.PORTAL, TagType.DESTINATION};
|
||||
private final TagType[] tagTypes =
|
||||
new TagType[] {TagType.PORTAL, TagType.DESTINATION};
|
||||
|
||||
@Override
|
||||
public TagType[] getTagTypes() {
|
||||
@ -55,12 +54,12 @@ public class NameTag implements Tag.AutoComplete, Tag.Creation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean created(TagTarget target, PlayerContainer player, String[] argData) {
|
||||
public boolean created(TagTarget target, PlayerContainer player,
|
||||
String[] argData) {
|
||||
if (argData.length > 0) {
|
||||
String name = argData[0];
|
||||
if (name.contains(" ")) {
|
||||
player.sendMessage(
|
||||
Lang.translate("messageprefix.negative")
|
||||
player.sendMessage(Lang.translate("messageprefix.negative")
|
||||
+ Lang.translate("tag.name.error.nospaces"));
|
||||
return false;
|
||||
}
|
||||
@ -69,5 +68,7 @@ public class NameTag implements Tag.AutoComplete, Tag.Creation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyed(TagTarget target, PlayerContainer player, String[] argData) {}
|
||||
public void destroyed(TagTarget target, PlayerContainer player,
|
||||
String[] argData) {
|
||||
}
|
||||
}
|
||||
|
@ -8,12 +8,10 @@ import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.warphandler.ActivationData;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class PermissionTag implements Tag.Activation {
|
||||
|
||||
@Inject transient PlayerDataServices playerDataServices;
|
||||
|
||||
@Inject transient ConfigRepository configRepository;
|
||||
@ -48,8 +46,8 @@ public class PermissionTag implements Tag.Activation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preActivated(
|
||||
TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) {
|
||||
public boolean preActivated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activeData, String[] argData) {
|
||||
if (!player.hasPermission(argData[1])) {
|
||||
player.sendMessage(Lang.translate("portal.error.nopermission"));
|
||||
return false;
|
||||
@ -58,18 +56,13 @@ public class PermissionTag implements Tag.Activation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postActivated(
|
||||
TagTarget target,
|
||||
PlayerContainer player,
|
||||
ActivationData activationData,
|
||||
String[] argData) {}
|
||||
public void postActivated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activationData, String[] argData) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activated(
|
||||
TagTarget target,
|
||||
PlayerContainer player,
|
||||
ActivationData activationData,
|
||||
String[] argData) {
|
||||
public boolean activated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activationData, String[] argData) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,10 @@ import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class TriggerBlockTag implements Tag.AutoComplete, Tag.Split {
|
||||
|
||||
@Inject private ServerContainer serverContainer;
|
||||
|
||||
public static String TAG_NAME = "triggerblock";
|
||||
|
@ -2,31 +2,30 @@ package com.sekwah.advancedportals.core.util;
|
||||
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class Debug {
|
||||
public static boolean addMarker(
|
||||
PlayerContainer player,
|
||||
BlockLocation blockPos,
|
||||
String name,
|
||||
Color color,
|
||||
int milliseconds) {
|
||||
public static boolean addMarker(PlayerContainer player,
|
||||
BlockLocation blockPos, String name,
|
||||
Color color, int milliseconds) {
|
||||
FriendlyDataOutput out = new FriendlyDataOutput();
|
||||
out.writeBlock(blockPos);
|
||||
out.writeInt(color(color));
|
||||
out.writeUtf(name);
|
||||
out.writeInt(milliseconds);
|
||||
return player.sendPacket("minecraft:debug/game_test_add_marker", out.toByteArray());
|
||||
return player.sendPacket("minecraft:debug/game_test_add_marker",
|
||||
out.toByteArray());
|
||||
}
|
||||
|
||||
public static boolean clear(PlayerContainer player) {
|
||||
FriendlyDataOutput out = new FriendlyDataOutput();
|
||||
return player.sendPacket("minecraft:debug/game_test_clear", out.toByteArray());
|
||||
return player.sendPacket("minecraft:debug/game_test_clear",
|
||||
out.toByteArray());
|
||||
}
|
||||
|
||||
public static int color(Color color) {
|
||||
return color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
|
||||
return color(color.getRed(), color.getGreen(), color.getBlue(),
|
||||
color.getAlpha());
|
||||
}
|
||||
|
||||
public static int color(int r, int g, int b) {
|
||||
|
@ -1,16 +1,15 @@
|
||||
package com.sekwah.advancedportals.core.util;
|
||||
|
||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.handler.codec.EncoderException;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/** Meant to be similar to FriendlyByteBuf if you have used that before. */
|
||||
/**
|
||||
* Meant to be similar to FriendlyByteBuf if you have used that before.
|
||||
*/
|
||||
public class FriendlyDataOutput {
|
||||
|
||||
private final ByteBuf dataOutput;
|
||||
|
||||
public FriendlyDataOutput() {
|
||||
@ -51,14 +50,16 @@ public class FriendlyDataOutput {
|
||||
|
||||
public void writeUtf(String text, int maxLength) {
|
||||
if (text.length() > maxLength) {
|
||||
throw new EncoderException(
|
||||
"String too big (was " + text.length() + " characters, max " + maxLength + ")");
|
||||
throw new EncoderException("String too big (was " + text.length()
|
||||
+ " characters, max " + maxLength
|
||||
+ ")");
|
||||
} else {
|
||||
byte[] abyte = text.getBytes(StandardCharsets.UTF_8);
|
||||
int i = getMaxEncodedUtfLength(maxLength);
|
||||
if (abyte.length > i) {
|
||||
throw new EncoderException(
|
||||
"String too big (was " + abyte.length + " bytes encoded, max " + i + ")");
|
||||
throw new EncoderException("String too big (was " + abyte.length
|
||||
+ " bytes encoded, max " + i
|
||||
+ ")");
|
||||
} else {
|
||||
this.writeVarInt(abyte.length);
|
||||
this.writeBytes(abyte);
|
||||
@ -99,10 +100,11 @@ public class FriendlyDataOutput {
|
||||
|
||||
// Only for block serialising and such
|
||||
private static final int PACKED_X_LENGTH =
|
||||
26; // 1 + Mth.log2(Mth.smallestEncompassingPowerOfTwo(30000000)) (im not gonna add all
|
||||
// the mojang math stuff to calculate this.
|
||||
26; // 1 + Mth.log2(Mth.smallestEncompassingPowerOfTwo(30000000)) (im
|
||||
// not gonna add all the mojang math stuff to calculate this.
|
||||
private static final int PACKED_Z_LENGTH = PACKED_X_LENGTH;
|
||||
public static final int PACKED_Y_LENGTH = 64 - PACKED_X_LENGTH - PACKED_Z_LENGTH;
|
||||
public static final int PACKED_Y_LENGTH =
|
||||
64 - PACKED_X_LENGTH - PACKED_Z_LENGTH;
|
||||
private static final long PACKED_X_MASK = (1L << PACKED_X_LENGTH) - 1L;
|
||||
private static final long PACKED_Y_MASK = (1L << PACKED_Y_LENGTH) - 1L;
|
||||
private static final long PACKED_Z_MASK = (1L << PACKED_Z_LENGTH) - 1L;
|
||||
@ -114,7 +116,6 @@ public class FriendlyDataOutput {
|
||||
}
|
||||
|
||||
private long blockAsLong(BlockLocation blockLoc) {
|
||||
|
||||
long i = 0L;
|
||||
i |= ((long) blockLoc.getPosX() & PACKED_X_MASK) << X_OFFSET;
|
||||
i |= ((long) blockLoc.getPosY() & PACKED_Y_MASK) << 0;
|
||||
|
@ -2,36 +2,44 @@ package com.sekwah.advancedportals.core.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/** For all delayed and repeating tasks. */
|
||||
/**
|
||||
* For all delayed and repeating tasks.
|
||||
*/
|
||||
@Singleton
|
||||
public final class GameScheduler {
|
||||
|
||||
private final ArrayList<DelayedGameTickEvent> newTickEvents = new ArrayList<>();
|
||||
private final ArrayList<DelayedGameTickEvent> delayedTickEvents = new ArrayList<>();
|
||||
private final ArrayList<DelayedGameTickEvent> newTickEvents =
|
||||
new ArrayList<>();
|
||||
private final ArrayList<DelayedGameTickEvent> delayedTickEvents =
|
||||
new ArrayList<>();
|
||||
|
||||
public void tick() {
|
||||
this.delayedTickEvents.addAll(this.newTickEvents);
|
||||
this.newTickEvents.clear();
|
||||
Iterator<DelayedGameTickEvent> tickEventIterator = this.delayedTickEvents.iterator();
|
||||
Iterator<DelayedGameTickEvent> tickEventIterator =
|
||||
this.delayedTickEvents.iterator();
|
||||
while (tickEventIterator.hasNext()) {
|
||||
DelayedGameTickEvent event = tickEventIterator.next();
|
||||
event.tick();
|
||||
if (event.shouldRun()) {
|
||||
event.run();
|
||||
if (!(event instanceof DelayedGameIntervalEvent)) tickEventIterator.remove();
|
||||
if (!(event instanceof DelayedGameIntervalEvent))
|
||||
tickEventIterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void delayedTickEvent(String name, Runnable consumer, int tickDelay) {
|
||||
this.newTickEvents.add(new DelayedGameTickEvent(name, consumer, tickDelay));
|
||||
public void delayedTickEvent(String name, Runnable consumer,
|
||||
int tickDelay) {
|
||||
this.newTickEvents.add(
|
||||
new DelayedGameTickEvent(name, consumer, tickDelay));
|
||||
}
|
||||
|
||||
public void intervalTickEvent(String name, Runnable consumer, int tickDelay, int interval) {
|
||||
this.newTickEvents.add(new DelayedGameIntervalEvent(name, consumer, tickDelay, interval));
|
||||
public void intervalTickEvent(String name, Runnable consumer, int tickDelay,
|
||||
int interval) {
|
||||
this.newTickEvents.add(
|
||||
new DelayedGameIntervalEvent(name, consumer, tickDelay, interval));
|
||||
}
|
||||
|
||||
public void clearAllEvents() {
|
||||
@ -40,7 +48,6 @@ public final class GameScheduler {
|
||||
}
|
||||
|
||||
public static class DelayedGameTickEvent {
|
||||
|
||||
// So we can find it later and remove it if needed
|
||||
public final String name;
|
||||
public final Runnable consumer;
|
||||
@ -66,10 +73,10 @@ public final class GameScheduler {
|
||||
}
|
||||
|
||||
public static class DelayedGameIntervalEvent extends DelayedGameTickEvent {
|
||||
|
||||
public int interval;
|
||||
|
||||
public DelayedGameIntervalEvent(String name, Runnable consumer, int ticks, int interval) {
|
||||
public DelayedGameIntervalEvent(String name, Runnable consumer,
|
||||
int ticks, int interval) {
|
||||
super(name, consumer, ticks);
|
||||
this.interval = interval;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.sekwah.advancedportals.core.util;
|
||||
|
||||
public abstract class InfoLogger {
|
||||
|
||||
/**
|
||||
* Problematic messages
|
||||
*
|
||||
|
@ -2,7 +2,6 @@ package com.sekwah.advancedportals.core.util;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
@ -13,13 +12,12 @@ import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* @author sekwah41
|
||||
* <p>The language translation file for the game. Will always load english first so that if the
|
||||
* translations are missing any then they are still readable and can then be translated. (It's
|
||||
* better than a raw translate string)
|
||||
* <p>
|
||||
* <p>The language translation file for the game. Will always load english
|
||||
* first so that if the translations are missing any then they are still
|
||||
* readable and can then be translated. (It's better than a raw translate
|
||||
* string) <p>
|
||||
*/
|
||||
public class Lang {
|
||||
|
||||
public static final Lang instance = new Lang();
|
||||
private final HashMap<String, String> languageMap = new HashMap<>();
|
||||
|
||||
@ -39,8 +37,10 @@ public class Lang {
|
||||
public static String translate(String s) {
|
||||
if (instance.languageMap.containsKey(s)) {
|
||||
String translation = instance.languageMap.get(s);
|
||||
// noinspection ALL (not sure what the specific warning is for escaped unicode)
|
||||
translation = translation.replaceAll("&([0-9a-frk-ox])", "\u00A7$1");
|
||||
// noinspection ALL (not sure what the specific warning is for
|
||||
// escaped unicode)
|
||||
translation =
|
||||
translation.replaceAll("&([0-9a-frk-ox])", "\u00A7$1");
|
||||
return translation;
|
||||
} else {
|
||||
return s;
|
||||
@ -50,13 +50,15 @@ public class Lang {
|
||||
public static String translateInsertVariables(String s, Object... args) {
|
||||
String translation = translate(s);
|
||||
for (int i = 1; i <= args.length; i++) {
|
||||
translation = translation.replaceAll("%" + i + "\\$s", args[i - 1].toString());
|
||||
translation = translation.replaceAll("%" + i + "\\$s",
|
||||
args[i - 1].toString());
|
||||
}
|
||||
return translation;
|
||||
}
|
||||
|
||||
public Map<String, String> getLanguageMap(String fileName) {
|
||||
InputStream stream = this.dataStorage.loadResource("lang/" + fileName + ".lang");
|
||||
InputStream stream =
|
||||
this.dataStorage.loadResource("lang/" + fileName + ".lang");
|
||||
if (stream != null) {
|
||||
return Lang.parseLang(stream);
|
||||
}
|
||||
@ -65,7 +67,8 @@ public class Lang {
|
||||
|
||||
public Map<String, String> getInternalLanguageMap(String fileName) {
|
||||
InputStream stream =
|
||||
this.getClass().getClassLoader().getResourceAsStream("lang/" + fileName + ".lang");
|
||||
this.getClass().getClassLoader().getResourceAsStream(
|
||||
"lang/" + fileName + ".lang");
|
||||
if (stream != null) {
|
||||
return Lang.parseLang(stream);
|
||||
}
|
||||
@ -92,8 +95,8 @@ public class Lang {
|
||||
}
|
||||
|
||||
/**
|
||||
* The default font is not monospaced, so this will likely be a little thinner to be on the safe
|
||||
* side
|
||||
* The default font is not monospaced, so this will likely be a little
|
||||
* thinner to be on the safe side
|
||||
*
|
||||
* @param title
|
||||
* @return
|
||||
@ -103,29 +106,28 @@ public class Lang {
|
||||
|
||||
int eachSide = titleLength / 2;
|
||||
|
||||
return "\u00A7e" + "=".repeat(eachSide) + " " + title + " \u00A7e" + "=".repeat(eachSide);
|
||||
return "\u00A7e"
|
||||
+ "=".repeat(eachSide) + " " + title + " \u00A7e"
|
||||
+ "=".repeat(eachSide);
|
||||
}
|
||||
|
||||
private void injectTranslations(String fileName) {
|
||||
try {
|
||||
URL url =
|
||||
Lang.instance
|
||||
.getClass()
|
||||
.getClassLoader()
|
||||
.getResource("lang/" + fileName + ".lang");
|
||||
URL url = Lang.instance.getClass().getClassLoader().getResource(
|
||||
"lang/" + fileName + ".lang");
|
||||
if (url != null) {
|
||||
Map<String, String> initialMap = Lang.parseLang(url.openStream());
|
||||
Map<String, String> initialMap =
|
||||
Lang.parseLang(url.openStream());
|
||||
Lang.instance.languageMap.putAll(initialMap);
|
||||
} else {
|
||||
this.infoLogger.warning(
|
||||
"Could not load "
|
||||
+ fileName
|
||||
+ ".lang from within Advanced Portals as it doesn't exist.");
|
||||
this.infoLogger.warning("Could not load " + fileName
|
||||
+ (".lang from within Advanced Portals "
|
||||
+ "as it doesn't exist."));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
this.infoLogger.warning(
|
||||
"Could not load " + fileName + ".lang from within Advanced Portals.");
|
||||
this.infoLogger.warning("Could not load " + fileName
|
||||
+ ".lang from within Advanced Portals.");
|
||||
}
|
||||
|
||||
Map<String, String> newLangMap = this.getLanguageMap(fileName);
|
||||
|
@ -3,9 +3,11 @@ package com.sekwah.advancedportals.core.util;
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
|
||||
public class PlayerUtils {
|
||||
|
||||
public static void throwPlayerBack(PlayerContainer player, double strength) {
|
||||
public static void throwPlayerBack(PlayerContainer player,
|
||||
double strength) {
|
||||
var playerLoc = player.getLoc().getDirection();
|
||||
player.setVelocity(playerLoc.setY(0).normalize().multiply(-1).setY(0.5).multiply(strength));
|
||||
player.setVelocity(
|
||||
playerLoc.setY(0).normalize().multiply(-1).setY(0.5).multiply(
|
||||
strength));
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,10 @@
|
||||
package com.sekwah.advancedportals.core.util;
|
||||
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class TagReader {
|
||||
|
||||
public static boolean isClosedString(String[] args) {
|
||||
StringBuilder currentValue = new StringBuilder();
|
||||
boolean inQuotes = false;
|
||||
|
@ -8,7 +8,6 @@ import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class ActivationData {
|
||||
|
||||
private boolean warpAllowed = true;
|
||||
|
||||
public final boolean moveActivated;
|
||||
@ -28,15 +27,16 @@ public class ActivationData {
|
||||
public void setWarpStatus(WarpedStatus warped) {
|
||||
if (this.warpStatus == WarpedStatus.WARPED) {
|
||||
return;
|
||||
} else if (this.warpStatus == WarpedStatus.ACTIVATED && warped != WarpedStatus.WARPED) {
|
||||
} else if (this.warpStatus == WarpedStatus.ACTIVATED
|
||||
&& warped != WarpedStatus.WARPED) {
|
||||
return;
|
||||
}
|
||||
this.warpStatus = warped;
|
||||
}
|
||||
|
||||
/**
|
||||
* In case you need to set the status back down a step for whatever reason. However it is not
|
||||
* recommended.
|
||||
* In case you need to set the status back down a step for whatever reason.
|
||||
* However it is not recommended.
|
||||
*
|
||||
* @param warped
|
||||
*/
|
||||
@ -57,11 +57,20 @@ public class ActivationData {
|
||||
}
|
||||
|
||||
public enum WarpedStatus {
|
||||
/** Player has moved or something major has happened. (only one of these should activate) */
|
||||
/**
|
||||
* Player has moved or something major has happened. (only one of these
|
||||
* should activate)
|
||||
*/
|
||||
WARPED,
|
||||
/** Shows that the portal has been activated even if a major function is not performed. */
|
||||
/**
|
||||
* Shows that the portal has been activated even if a major function is
|
||||
* not performed.
|
||||
*/
|
||||
ACTIVATED,
|
||||
/** Nothing has activated on the portal (may need to come up with a new name) */
|
||||
/**
|
||||
* Nothing has activated on the portal (may need to come up with a new
|
||||
* name)
|
||||
*/
|
||||
NOTACTIVATED;
|
||||
}
|
||||
}
|
||||
|
@ -2,34 +2,32 @@ package com.sekwah.advancedportals.core.warphandler;
|
||||
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.registry.TagTarget;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* If a tag can be used for any of them then either make it cast the target or if it doesn't need a
|
||||
* target then the exact same tag can be registered into both and ignore the portal info.
|
||||
* If a tag can be used for any of them then either make it cast the target or
|
||||
* if it doesn't need a target then the exact same tag can be registered into
|
||||
* both and ignore the portal info.
|
||||
*
|
||||
* <p>Will probably make better documentation on how to do so or some tutorial videos though take a
|
||||
* look at the source code on GitHub for how the current tags are added.
|
||||
* <p>Will probably make better documentation on how to do so or some tutorial
|
||||
* videos though take a look at the source code on GitHub for how the current
|
||||
* tags are added.
|
||||
*
|
||||
* <p>Also, not sure if its good practice or not in java however these all extend TagHandler, so
|
||||
* they can be accepted in 1 method nicer than if they didn't
|
||||
* <p>Also, not sure if its good practice or not in java however these all
|
||||
* extend TagHandler, so they can be accepted in 1 method nicer than if they
|
||||
* didn't
|
||||
*
|
||||
* @author sekwah41
|
||||
*/
|
||||
public interface Tag {
|
||||
|
||||
/**
|
||||
* By default, all tags should be able to use either.
|
||||
*
|
||||
* <p>Though you may have use cases where you want to limit it to one or the other.
|
||||
* <p>Though you may have use cases where you want to limit it to one or the
|
||||
* other.
|
||||
*/
|
||||
enum TagType {
|
||||
PORTAL,
|
||||
DESTINATION
|
||||
}
|
||||
enum TagType { PORTAL, DESTINATION }
|
||||
|
||||
/**
|
||||
* Used to flag where the auto complete should show more or less info.
|
||||
@ -40,41 +38,37 @@ public interface Tag {
|
||||
|
||||
String getName();
|
||||
|
||||
@Nullable
|
||||
String[] getAliases();
|
||||
@Nullable String[] getAliases();
|
||||
|
||||
String description();
|
||||
|
||||
interface AutoComplete extends Tag {
|
||||
|
||||
/**
|
||||
* This is used to get the auto complete for the tag. This is called when the player is
|
||||
* typing the tag.
|
||||
* This is used to get the auto complete for the tag. This is called
|
||||
* when the player is typing the tag.
|
||||
*
|
||||
* @param argData
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
List<String> autoComplete(String argData);
|
||||
@Nullable List<String> autoComplete(String argData);
|
||||
|
||||
@Nullable
|
||||
String splitString();
|
||||
@Nullable String splitString();
|
||||
}
|
||||
|
||||
interface Split extends Tag {
|
||||
|
||||
/**
|
||||
* This is used to split the tag into the arguments if multiple are supported
|
||||
* This is used to split the tag into the arguments if multiple are
|
||||
* supported
|
||||
*
|
||||
* @return null if the tag does not support splitting
|
||||
*/
|
||||
@Nullable
|
||||
String splitString();
|
||||
@Nullable String splitString();
|
||||
}
|
||||
|
||||
/** The events for portal creation and destroying */
|
||||
/**
|
||||
* The events for portal creation and destroying
|
||||
*/
|
||||
interface Creation extends Tag {
|
||||
|
||||
/**
|
||||
* Example if the player does not have access to use the tag.
|
||||
*
|
||||
@ -82,45 +76,46 @@ public interface Tag {
|
||||
* @param argData
|
||||
* @return If the tag is valid or allowed creation
|
||||
*/
|
||||
boolean created(TagTarget target, PlayerContainer player, String[] argData);
|
||||
boolean created(TagTarget target, PlayerContainer player,
|
||||
String[] argData);
|
||||
|
||||
/**
|
||||
* Example if the player does not have access to remove the portal or destination.
|
||||
* Example if the player does not have access to remove the portal or
|
||||
* destination.
|
||||
*
|
||||
* @param player if null then removed by the server or a plugin
|
||||
* @param argData
|
||||
*/
|
||||
void destroyed(TagTarget target, PlayerContainer player, String[] argData);
|
||||
void destroyed(TagTarget target, PlayerContainer player,
|
||||
String[] argData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Order of activation Portal and Desti: preActivated activated postActivated
|
||||
* Order of activation Portal and Desti: preActivated activated
|
||||
* postActivated
|
||||
*
|
||||
* <p>Order of them combined: Portal.preActivated Portal.activated - when desti tag is hit (if
|
||||
* listed) then next two actions are activated - Desti.preActivate - Desti.activate
|
||||
* Portal.postActivate - when desti tag is hit (if listed) then the next action is activated -
|
||||
* Desti.postActivate
|
||||
* <p>Order of them combined: Portal.preActivated Portal.activated - when
|
||||
* desti tag is hit (if listed) then next two actions are activated -
|
||||
* Desti.preActivate - Desti.activate Portal.postActivate - when desti tag
|
||||
* is hit (if listed) then the next action is activated - Desti.postActivate
|
||||
*/
|
||||
interface Activation extends Tag {
|
||||
|
||||
/**
|
||||
* Activates before the main part of activation. This should be for prechecks e.g. if the
|
||||
* player has enough money before then taking the money in postActivated.
|
||||
* Activates before the main part of activation. This should be for
|
||||
* prechecks e.g. if the player has enough money before then taking the
|
||||
* money in postActivated.
|
||||
*
|
||||
* @param player
|
||||
* @param activeData
|
||||
* @param argData
|
||||
* @return If the tag has allowed the warp
|
||||
*/
|
||||
boolean preActivated(
|
||||
TagTarget target,
|
||||
PlayerContainer player,
|
||||
ActivationData activeData,
|
||||
String[] argData);
|
||||
boolean preActivated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activeData, String[] argData);
|
||||
|
||||
/**
|
||||
* Activates after activation, should be used for actions such as removing money for a
|
||||
* teleport.
|
||||
* Activates after activation, should be used for actions such as
|
||||
* removing money for a teleport.
|
||||
*
|
||||
* <p>Any actions to do with player location should be done in activate
|
||||
*
|
||||
@ -128,55 +123,57 @@ public interface Tag {
|
||||
* @param activationData
|
||||
* @param argData
|
||||
*/
|
||||
void postActivated(
|
||||
TagTarget target,
|
||||
PlayerContainer player,
|
||||
ActivationData activationData,
|
||||
String[] argData);
|
||||
void postActivated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activationData, String[] argData);
|
||||
|
||||
/**
|
||||
* Activates if the portal is allowed from preActivating. Should be used to set the intended
|
||||
* warp location
|
||||
* Activates if the portal is allowed from preActivating. Should be used
|
||||
* to set the intended warp location
|
||||
*
|
||||
* <p>You should do some second checks if it can be dependent on the preActivate, the
|
||||
* destination tags will also be triggered here if a desti is listed.
|
||||
* <p>You should do some second checks if it can be dependent on the
|
||||
* preActivate, the destination tags will also be triggered here if a
|
||||
* desti is listed.
|
||||
*
|
||||
* @param player
|
||||
* @param activationData
|
||||
* @param argData
|
||||
* @return Action performed (only return false if the tag failed to do anything)
|
||||
* @return Action performed (only return false if the tag failed to do
|
||||
* anything)
|
||||
*/
|
||||
boolean activated(
|
||||
TagTarget target,
|
||||
PlayerContainer player,
|
||||
ActivationData activationData,
|
||||
String[] argData);
|
||||
boolean activated(TagTarget target, PlayerContainer player,
|
||||
ActivationData activationData, String[] argData);
|
||||
}
|
||||
|
||||
/** Triggers when a tag is added or removed from a portal or destination */
|
||||
interface TagStatus extends Tag {
|
||||
|
||||
/**
|
||||
* If the user has access to add the tag (this does not include being added on creation)
|
||||
* Triggers when a tag is added or removed from a portal or destination
|
||||
*/
|
||||
interface TagStatus extends Tag {
|
||||
/**
|
||||
* If the user has access to add the tag (this does not include being
|
||||
* added on creation)
|
||||
*
|
||||
* @param target the target of the tag
|
||||
* @param player if null then removed by the server or a plugin
|
||||
* @param argData the data for the tag
|
||||
* @param index the index of the tag in the list (if it is the only tag it will be 0)
|
||||
* @param index the index of the tag in the list (if it is the only tag
|
||||
* it will be 0)
|
||||
* @return if the tag will be added.
|
||||
*/
|
||||
boolean tagAdded(TagTarget target, PlayerContainer player, int index, String argData);
|
||||
boolean tagAdded(TagTarget target, PlayerContainer player, int index,
|
||||
String argData);
|
||||
|
||||
/**
|
||||
* If the user has access to remove the tag (this does not include being added on
|
||||
* destruction)
|
||||
* If the user has access to remove the tag (this does not include being
|
||||
* added on destruction)
|
||||
*
|
||||
* @param target the target of the tag
|
||||
* @param player if null then removed by the server or a plugin
|
||||
* @param argData the data of the tag to be removed
|
||||
* @param index the index of the tag in the list (if it is the only tag it will be 0)
|
||||
* @param index the index of the tag in the list (if it is the only tag
|
||||
* it will be 0)
|
||||
* @return if the tag will be removed.
|
||||
*/
|
||||
boolean tagRemoved(TagTarget target, PlayerContainer player, int index, String argData);
|
||||
boolean tagRemoved(TagTarget target, PlayerContainer player, int index,
|
||||
String argData);
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,9 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class AdvancedPortalsPlugin extends JavaPlugin {
|
||||
|
||||
private AdvancedPortalsCore portalsCore;
|
||||
|
||||
/**
|
||||
|
@ -17,11 +17,9 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.event.player.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Some of these will be passed to the core listener to handle the events, others it's easier to
|
||||
* just check directly.
|
||||
* Some of these will be passed to the core listener to handle the events,
|
||||
* others it's easier to just check directly.
|
||||
*/
|
||||
public class Listeners implements Listener {
|
||||
|
||||
@ -76,7 +74,8 @@ public class Listeners implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void spawnMobEvent(CreatureSpawnEvent event) {
|
||||
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NETHER_PORTAL
|
||||
if (event.getSpawnReason()
|
||||
== CreatureSpawnEvent.SpawnReason.NETHER_PORTAL
|
||||
&& portalServices.inPortalRegionProtected(
|
||||
ContainerHelpers.toPlayerLocation(event.getLocation()))) {
|
||||
event.setCancelled(true);
|
||||
@ -90,18 +89,16 @@ public class Listeners implements Listener {
|
||||
if (!configRepository.getStopWaterFlow()) {
|
||||
return;
|
||||
}
|
||||
if (!coreListeners.blockPlace(
|
||||
null,
|
||||
ContainerHelpers.toBlockLocation(event.getBlock().getLocation()),
|
||||
if (!coreListeners.blockPlace(null,
|
||||
ContainerHelpers.toBlockLocation(
|
||||
event.getBlock().getLocation()),
|
||||
event.getBlock().getType().toString(),
|
||||
null,
|
||||
null)
|
||||
|| !coreListeners.blockPlace(
|
||||
null,
|
||||
ContainerHelpers.toBlockLocation(event.getToBlock().getLocation()),
|
||||
null, null)
|
||||
|| !coreListeners.blockPlace(null,
|
||||
ContainerHelpers.toBlockLocation(
|
||||
event.getToBlock().getLocation()),
|
||||
event.getBlock().getType().toString(),
|
||||
null,
|
||||
null)) {
|
||||
null, null)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -111,7 +108,8 @@ public class Listeners implements Listener {
|
||||
var itemInHand = event.getPlayer().getItemInHand();
|
||||
if (!coreListeners.blockBreak(
|
||||
new SpigotPlayerContainer(event.getPlayer()),
|
||||
ContainerHelpers.toBlockLocation(event.getBlock().getLocation()),
|
||||
ContainerHelpers.toBlockLocation(
|
||||
event.getBlock().getLocation()),
|
||||
event.getBlock().getType().toString(),
|
||||
itemInHand == null ? null : itemInHand.getType().toString(),
|
||||
itemInHand == null || itemInHand.getItemMeta() == null
|
||||
@ -123,7 +121,8 @@ public class Listeners implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onExplosion(EntityExplodeEvent event) {
|
||||
if (!configRepository.getPortalProtection()) return;
|
||||
if (!configRepository.getPortalProtection())
|
||||
return;
|
||||
|
||||
List<Block> blockList = event.blockList();
|
||||
for (int i = 0; i < blockList.size(); i++) {
|
||||
|
@ -1,11 +1,9 @@
|
||||
package com.sekwah.advancedportals.spigot;
|
||||
|
||||
import com.sekwah.advancedportals.core.util.InfoLogger;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class SpigotInfoLogger extends InfoLogger {
|
||||
|
||||
private final AdvancedPortalsPlugin plugin;
|
||||
|
||||
public SpigotInfoLogger(AdvancedPortalsPlugin plugin) {
|
||||
|
@ -11,15 +11,12 @@ import com.sekwah.advancedportals.core.services.PortalServices;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin;
|
||||
import com.sekwah.advancedportals.spigot.commands.subcommands.portal.update.ConfigAccessor;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public class UpdatePortalSubCommand implements SubCommand {
|
||||
|
||||
@Inject PortalServices portalServices;
|
||||
|
||||
@Inject DestinationServices destinationServices;
|
||||
@ -29,9 +26,9 @@ public class UpdatePortalSubCommand implements SubCommand {
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
if (args.length > 1 && "confirm".equals(args[1])) {
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
+ Lang.translateInsertVariables("command.portal.update.confirm"));
|
||||
sender.sendMessage(Lang.translate("messageprefix.positive")
|
||||
+ Lang.translateInsertVariables(
|
||||
"command.portal.update.confirm"));
|
||||
int destinations = importDestinations();
|
||||
int portals = importPortals();
|
||||
sender.sendMessage(
|
||||
@ -40,29 +37,27 @@ public class UpdatePortalSubCommand implements SubCommand {
|
||||
"command.portal.update.complete", portals, destinations));
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(
|
||||
Lang.translate("messageprefix.positive")
|
||||
sender.sendMessage(Lang.translate("messageprefix.positive")
|
||||
+ Lang.translateInsertVariables(
|
||||
"command.portal.update", getPortalCount(), getDestinationCount()));
|
||||
"command.portal.update", getPortalCount(),
|
||||
getDestinationCount()));
|
||||
}
|
||||
|
||||
private int importPortals() {
|
||||
ConfigAccessor portalConfig =
|
||||
new ConfigAccessor(AdvancedPortalsPlugin.getInstance(), "portals.yaml");
|
||||
ConfigAccessor portalConfig = new ConfigAccessor(
|
||||
AdvancedPortalsPlugin.getInstance(), "portals.yaml");
|
||||
var config = portalConfig.getConfig();
|
||||
Set<String> portalSet = config.getKeys(false);
|
||||
|
||||
int count = 0;
|
||||
for (String portalName : portalSet) {
|
||||
BlockLocation pos1 =
|
||||
new BlockLocation(
|
||||
config.getString(portalName + ".world"),
|
||||
new BlockLocation(config.getString(portalName + ".world"),
|
||||
config.getInt(portalName + ".pos1.X"),
|
||||
config.getInt(portalName + ".pos1.Y"),
|
||||
config.getInt(portalName + ".pos1.Z"));
|
||||
BlockLocation pos2 =
|
||||
new BlockLocation(
|
||||
config.getString(portalName + ".world"),
|
||||
new BlockLocation(config.getString(portalName + ".world"),
|
||||
config.getInt(portalName + ".pos2.X"),
|
||||
config.getInt(portalName + ".pos2.Y"),
|
||||
config.getInt(portalName + ".pos2.Z"));
|
||||
@ -73,12 +68,15 @@ public class UpdatePortalSubCommand implements SubCommand {
|
||||
args.add(new DataTag("triggerblock", triggerblock.split(",")));
|
||||
// It's called bungee as that's the implementation behind it
|
||||
var bungee = config.getString(portalName + ".bungee");
|
||||
if (bungee != null) args.add(new DataTag("bungee", bungee.split(",")));
|
||||
if (bungee != null)
|
||||
args.add(new DataTag("bungee", bungee.split(",")));
|
||||
|
||||
var destination = config.getString(portalName + ".destination");
|
||||
if (destination != null) args.add(new DataTag("destination", destination.split(",")));
|
||||
if (destination != null)
|
||||
args.add(new DataTag("destination", destination.split(",")));
|
||||
|
||||
ConfigurationSection portalConfigSection = config.getConfigurationSection(portalName);
|
||||
ConfigurationSection portalConfigSection =
|
||||
config.getConfigurationSection(portalName);
|
||||
ConfigurationSection portalArgsConf =
|
||||
portalConfigSection.getConfigurationSection("portalArgs");
|
||||
|
||||
@ -87,8 +85,7 @@ public class UpdatePortalSubCommand implements SubCommand {
|
||||
for (Object argName : argsSet.toArray()) {
|
||||
// skip if it argName starts with command.
|
||||
if (portalArgsConf.isString(argName.toString())) {
|
||||
args.add(
|
||||
new DataTag(
|
||||
args.add(new DataTag(
|
||||
argName.toString(),
|
||||
portalArgsConf.getString(argName.toString())));
|
||||
}
|
||||
@ -104,7 +101,8 @@ public class UpdatePortalSubCommand implements SubCommand {
|
||||
}
|
||||
}
|
||||
if (!commands.isEmpty()) {
|
||||
args.add(new DataTag("commands", commands.toArray(new String[0])));
|
||||
args.add(
|
||||
new DataTag("commands", commands.toArray(new String[0])));
|
||||
}
|
||||
args.stream()
|
||||
.filter(dataTag -> dataTag.NAME.startsWith("command."))
|
||||
@ -113,7 +111,8 @@ public class UpdatePortalSubCommand implements SubCommand {
|
||||
|
||||
var portal = portalService.createPortal(pos1, pos2, args);
|
||||
|
||||
if (portal != null) count++;
|
||||
if (portal != null)
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
@ -129,16 +128,15 @@ public class UpdatePortalSubCommand implements SubCommand {
|
||||
}
|
||||
|
||||
public int importDestinations() {
|
||||
ConfigAccessor destiConfig =
|
||||
new ConfigAccessor(AdvancedPortalsPlugin.getInstance(), "destinations.yaml");
|
||||
ConfigAccessor destiConfig = new ConfigAccessor(
|
||||
AdvancedPortalsPlugin.getInstance(), "destinations.yaml");
|
||||
var config = destiConfig.getConfig();
|
||||
Set<String> destiSet = config.getKeys(false);
|
||||
|
||||
int count = 0;
|
||||
for (String destiName : destiSet) {
|
||||
var destiPos = destiName + ".pos";
|
||||
var desti =
|
||||
destinationServices.createDesti(
|
||||
var desti = destinationServices.createDesti(
|
||||
new PlayerLocation(
|
||||
config.getString(destiName + ".world"),
|
||||
config.getDouble(destiPos + ".X"),
|
||||
@ -147,14 +145,15 @@ public class UpdatePortalSubCommand implements SubCommand {
|
||||
(float) config.getDouble(destiPos + ".yaw"),
|
||||
(float) config.getDouble(destiPos + ".pitch")),
|
||||
List.of(new DataTag("name", destiName)));
|
||||
if (desti != null) count++;
|
||||
if (desti != null)
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public int getDestinationCount() {
|
||||
ConfigAccessor destiConfig =
|
||||
new ConfigAccessor(AdvancedPortalsPlugin.getInstance(), "destinations.yaml");
|
||||
ConfigAccessor destiConfig = new ConfigAccessor(
|
||||
AdvancedPortalsPlugin.getInstance(), "destinations.yaml");
|
||||
var config = destiConfig.getConfig();
|
||||
Set<String> destiSet = config.getKeys(false);
|
||||
|
||||
@ -162,8 +161,8 @@ public class UpdatePortalSubCommand implements SubCommand {
|
||||
}
|
||||
|
||||
public int getPortalCount() {
|
||||
ConfigAccessor portalConfig =
|
||||
new ConfigAccessor(AdvancedPortalsPlugin.getInstance(), "portals.yaml");
|
||||
ConfigAccessor portalConfig = new ConfigAccessor(
|
||||
AdvancedPortalsPlugin.getInstance(), "portals.yaml");
|
||||
var config = portalConfig.getConfig();
|
||||
Set<String> portalSet = config.getKeys(false);
|
||||
|
||||
@ -176,7 +175,8 @@ public class UpdatePortalSubCommand implements SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
|
||||
public List<String> onTabComplete(CommandSenderContainer sender,
|
||||
String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,13 @@
|
||||
package com.sekwah.advancedportals.spigot.commands.subcommands.portal.update;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class ConfigAccessor {
|
||||
|
||||
private final String fileName;
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
@ -25,7 +23,8 @@ public class ConfigAccessor {
|
||||
public void reloadConfig() {
|
||||
if (configFile == null) {
|
||||
File dataFolder = plugin.getDataFolder();
|
||||
if (dataFolder == null) throw new IllegalStateException();
|
||||
if (dataFolder == null)
|
||||
throw new IllegalStateException();
|
||||
configFile = new File(dataFolder, fileName);
|
||||
}
|
||||
fileConfiguration = YamlConfiguration.loadConfiguration(configFile);
|
||||
@ -46,7 +45,8 @@ public class ConfigAccessor {
|
||||
try {
|
||||
getConfig().save(configFile);
|
||||
} catch (IOException ex) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Could not save config to " + configFile, ex);
|
||||
plugin.getLogger().log(
|
||||
Level.SEVERE, "Could not save config to " + configFile, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -58,8 +58,8 @@ public class ConfigAccessor {
|
||||
* this.plugin.saveResource(fileName, false); } }
|
||||
*/
|
||||
|
||||
// New save default config saving code, it checks if the needed config is in the jar file before
|
||||
// overriding it.
|
||||
// New save default config saving code, it checks if the needed config is in
|
||||
// the jar file before overriding it.
|
||||
public void saveDefaultConfig() {
|
||||
if (configFile == null) {
|
||||
configFile = new File(plugin.getDataFolder(), fileName);
|
||||
|
@ -2,16 +2,13 @@ package com.sekwah.advancedportals.spigot.connector.command;
|
||||
|
||||
import com.sekwah.advancedportals.core.commands.CommandTemplate;
|
||||
import com.sekwah.advancedportals.spigot.connector.container.SpigotCommandSenderContainer;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SpigotCommandHandler implements CommandExecutor, TabCompleter {
|
||||
|
||||
private final CommandTemplate commandExecutor;
|
||||
|
||||
public SpigotCommandHandler(CommandTemplate commandExecutor) {
|
||||
@ -19,16 +16,18 @@ public class SpigotCommandHandler implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(
|
||||
CommandSender commandSender, Command command, String s, String[] args) {
|
||||
public boolean onCommand(CommandSender commandSender, Command command,
|
||||
String s, String[] args) {
|
||||
this.commandExecutor.onCommand(
|
||||
new SpigotCommandSenderContainer(commandSender), command.getName(), args);
|
||||
new SpigotCommandSenderContainer(commandSender), command.getName(),
|
||||
args);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(
|
||||
CommandSender commandSender, Command command, String s, String[] args) {
|
||||
public List<String> onTabComplete(CommandSender commandSender,
|
||||
Command command, String s,
|
||||
String[] args) {
|
||||
return this.commandExecutor.onTabComplete(
|
||||
new SpigotCommandSenderContainer(commandSender), args);
|
||||
}
|
||||
|
@ -4,9 +4,10 @@ import com.sekwah.advancedportals.core.commands.CommandTemplate;
|
||||
import com.sekwah.advancedportals.core.connector.commands.CommandRegister;
|
||||
import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin;
|
||||
|
||||
/** Register the CommandTemplate files to the appropriate system */
|
||||
/**
|
||||
* Register the CommandTemplate files to the appropriate system
|
||||
*/
|
||||
public class SpigotCommandRegister implements CommandRegister {
|
||||
|
||||
private final AdvancedPortalsPlugin plugin;
|
||||
|
||||
public SpigotCommandRegister(AdvancedPortalsPlugin plugin) {
|
||||
@ -19,7 +20,9 @@ public class SpigotCommandRegister implements CommandRegister {
|
||||
* @param commandName
|
||||
* @param commandExecutor
|
||||
*/
|
||||
public void registerCommand(String commandName, CommandTemplate commandExecutor) {
|
||||
this.plugin.getCommand(commandName).setExecutor(new SpigotCommandHandler(commandExecutor));
|
||||
public void registerCommand(String commandName,
|
||||
CommandTemplate commandExecutor) {
|
||||
this.plugin.getCommand(commandName)
|
||||
.setExecutor(new SpigotCommandHandler(commandExecutor));
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,10 @@
|
||||
package com.sekwah.advancedportals.spigot.connector.container;
|
||||
|
||||
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SpigotCommandSenderContainer implements CommandSenderContainer {
|
||||
|
||||
private final CommandSender sender;
|
||||
|
||||
public SpigotCommandSenderContainer(CommandSender commandSender) {
|
||||
|
@ -7,14 +7,15 @@ import com.sekwah.advancedportals.core.connector.containers.WorldContainer;
|
||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.serializeddata.Vector;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
/** Just a temporary container for whenever advanced portals needs to get data from a player */
|
||||
/**
|
||||
* Just a temporary container for whenever advanced portals needs to get data
|
||||
* from a player
|
||||
*/
|
||||
public class SpigotEntityContainer implements EntityContainer {
|
||||
|
||||
@Inject private AdvancedPortalsCore portalsCore;
|
||||
|
||||
private final Entity entity;
|
||||
@ -26,20 +27,16 @@ public class SpigotEntityContainer implements EntityContainer {
|
||||
@Override
|
||||
public PlayerLocation getLoc() {
|
||||
Location loc = this.entity.getLocation();
|
||||
return new PlayerLocation(
|
||||
loc.getWorld().getName(),
|
||||
loc.getX(),
|
||||
loc.getY(),
|
||||
loc.getZ(),
|
||||
loc.getYaw(),
|
||||
return new PlayerLocation(loc.getWorld().getName(), loc.getX(),
|
||||
loc.getY(), loc.getZ(), loc.getYaw(),
|
||||
loc.getPitch());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockLocation getBlockLoc() {
|
||||
Location loc = this.entity.getLocation();
|
||||
return new BlockLocation(
|
||||
loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
return new BlockLocation(loc.getWorld().getName(), loc.getBlockX(),
|
||||
loc.getBlockY(), loc.getBlockZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,12 +46,9 @@ public class SpigotEntityContainer implements EntityContainer {
|
||||
|
||||
@Override
|
||||
public boolean teleport(PlayerLocation location) {
|
||||
return this.entity.teleport(
|
||||
new Location(
|
||||
Bukkit.getWorld(location.getWorldName()),
|
||||
location.getPosX(),
|
||||
location.getPosY(),
|
||||
location.getPosZ()));
|
||||
return this.entity.teleport(new Location(
|
||||
Bukkit.getWorld(location.getWorldName()), location.getPosX(),
|
||||
location.getPosY(), location.getPosZ()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,7 +68,7 @@ public class SpigotEntityContainer implements EntityContainer {
|
||||
|
||||
@Override
|
||||
public void setVelocity(Vector vector) {
|
||||
this.entity.setVelocity(
|
||||
new org.bukkit.util.Vector(vector.getX(), vector.getY(), vector.getZ()));
|
||||
this.entity.setVelocity(new org.bukkit.util.Vector(
|
||||
vector.getX(), vector.getY(), vector.getZ()));
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin;
|
||||
import com.sekwah.advancedportals.spigot.reflection.MinecraftCustomPayload;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -15,12 +16,12 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
/** Just a temporary container for whenever advanced portals needs to get data from a player */
|
||||
public class SpigotPlayerContainer extends SpigotEntityContainer implements PlayerContainer {
|
||||
|
||||
/**
|
||||
* Just a temporary container for whenever advanced portals needs to get data
|
||||
* from a player
|
||||
*/
|
||||
public class SpigotPlayerContainer
|
||||
extends SpigotEntityContainer implements PlayerContainer {
|
||||
@Inject private AdvancedPortalsCore portalsCore;
|
||||
|
||||
private final Player player;
|
||||
@ -47,12 +48,9 @@ public class SpigotPlayerContainer extends SpigotEntityContainer implements Play
|
||||
|
||||
@Override
|
||||
public boolean teleport(PlayerLocation location) {
|
||||
return this.player.teleport(
|
||||
new Location(
|
||||
Bukkit.getWorld(location.getWorldName()),
|
||||
location.getPosX(),
|
||||
location.getPosY(),
|
||||
location.getPosZ()));
|
||||
return this.player.teleport(new Location(
|
||||
Bukkit.getWorld(location.getWorldName()), location.getPosX(),
|
||||
location.getPosY(), location.getPosZ()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,7 +63,8 @@ public class SpigotPlayerContainer extends SpigotEntityContainer implements Play
|
||||
* @param material
|
||||
*/
|
||||
@Override
|
||||
public void sendFakeBlock(BlockLocation blockPos, String material) {}
|
||||
public void sendFakeBlock(BlockLocation blockPos, String material) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Only 1.12 and below supported
|
||||
@ -75,11 +74,15 @@ public class SpigotPlayerContainer extends SpigotEntityContainer implements Play
|
||||
* @param data
|
||||
*/
|
||||
@Override
|
||||
public void sendFakeBlockWithData(BlockLocation blockPos, String material, byte data) {}
|
||||
public void sendFakeBlockWithData(BlockLocation blockPos, String material,
|
||||
byte data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveItem(String material, String itemName, String... itemDescription) {
|
||||
ItemStack regionselector = new ItemStack(Material.getMaterial(material));
|
||||
public void giveItem(String material, String itemName,
|
||||
String... itemDescription) {
|
||||
ItemStack regionselector =
|
||||
new ItemStack(Material.getMaterial(material));
|
||||
ItemMeta selectorname = regionselector.getItemMeta();
|
||||
selectorname.setDisplayName(itemName);
|
||||
selectorname.setLore(Arrays.asList(itemDescription));
|
||||
@ -90,9 +93,11 @@ public class SpigotPlayerContainer extends SpigotEntityContainer implements Play
|
||||
@Override
|
||||
public boolean sendPacket(String channel, byte[] bytes) {
|
||||
if (channel.startsWith("minecraft:")) {
|
||||
return MinecraftCustomPayload.sendCustomPayload(player, channel, bytes);
|
||||
return MinecraftCustomPayload.sendCustomPayload(player, channel,
|
||||
bytes);
|
||||
} else {
|
||||
player.sendPluginMessage(AdvancedPortalsPlugin.getInstance(), channel, bytes);
|
||||
player.sendPluginMessage(AdvancedPortalsPlugin.getInstance(),
|
||||
channel, bytes);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -3,18 +3,19 @@ package com.sekwah.advancedportals.spigot.connector.container;
|
||||
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 java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SpigotServerContainer implements ServerContainer {
|
||||
|
||||
private final Server server;
|
||||
private final List<String> triggerBlockList = Arrays.stream(Material.values()).filter(this::isAdvancedPortalBlock).map(Enum::name)
|
||||
private final List<String> triggerBlockList =
|
||||
Arrays.stream(Material.values())
|
||||
.filter(this::isAdvancedPortalBlock)
|
||||
.map(Enum::name)
|
||||
.toList();
|
||||
|
||||
public SpigotServerContainer(Server server) {
|
||||
@ -24,7 +25,7 @@ public class SpigotServerContainer implements ServerContainer {
|
||||
@Override
|
||||
public WorldContainer getWorld(String name) {
|
||||
var world = server.getWorld(name);
|
||||
if(world != null) {
|
||||
if (world != null) {
|
||||
return new SpigotWorldContainer(world);
|
||||
} else {
|
||||
return null;
|
||||
@ -34,7 +35,7 @@ public class SpigotServerContainer implements ServerContainer {
|
||||
@Override
|
||||
public PlayerContainer getPlayer(String name) {
|
||||
var player = server.getPlayer(name);
|
||||
if(player != null) {
|
||||
if (player != null) {
|
||||
return new SpigotPlayerContainer(player);
|
||||
} else {
|
||||
return null;
|
||||
@ -44,7 +45,7 @@ public class SpigotServerContainer implements ServerContainer {
|
||||
@Override
|
||||
public PlayerContainer getPlayer(UUID name) {
|
||||
var player = server.getPlayer(name);
|
||||
if(player != null) {
|
||||
if (player != null) {
|
||||
return new SpigotPlayerContainer(player);
|
||||
} else {
|
||||
return null;
|
||||
@ -58,9 +59,10 @@ public class SpigotServerContainer implements ServerContainer {
|
||||
|
||||
@Override
|
||||
public PlayerContainer[] getPlayers() {
|
||||
return server.getOnlinePlayers().stream()
|
||||
return server.getOnlinePlayers()
|
||||
.stream()
|
||||
.map(SpigotPlayerContainer::new)
|
||||
.toArray(PlayerContainer[]::new);
|
||||
.toArray(PlayerContainer[] ::new);
|
||||
}
|
||||
|
||||
// Check if it's a material compatible with making portals
|
||||
|
@ -9,7 +9,6 @@ import org.bukkit.World;
|
||||
import org.bukkit.block.data.Orientable;
|
||||
|
||||
public class SpigotWorldContainer implements WorldContainer {
|
||||
|
||||
private final World world;
|
||||
|
||||
public SpigotWorldContainer(World world) {
|
||||
@ -18,18 +17,27 @@ public class SpigotWorldContainer implements WorldContainer {
|
||||
|
||||
public void setBlock(BlockLocation location, String material) {
|
||||
Material mat = Material.getMaterial(material, false);
|
||||
if(mat != null) this.world.getBlockAt(location.getPosX(), location.getPosY(), location.getPosZ()).setType(mat);
|
||||
if (mat != null)
|
||||
this.world
|
||||
.getBlockAt(location.getPosX(), location.getPosY(),
|
||||
location.getPosZ())
|
||||
.setType(mat);
|
||||
}
|
||||
|
||||
public String getBlock(BlockLocation location) {
|
||||
return this.world.getBlockAt(location.getPosX(), location.getPosY(), location.getPosZ()).getType().toString();
|
||||
return this.world
|
||||
.getBlockAt(location.getPosX(), location.getPosY(),
|
||||
location.getPosZ())
|
||||
.getType()
|
||||
.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockAxis getBlockAxis(BlockLocation location) {
|
||||
var block = world.getBlockAt(location.getPosX(), location.getPosY(), location.getPosZ());
|
||||
var block = world.getBlockAt(location.getPosX(), location.getPosY(),
|
||||
location.getPosZ());
|
||||
var matData = block.getState().getBlockData();
|
||||
if(matData instanceof Orientable rotatable) {
|
||||
if (matData instanceof Orientable rotatable) {
|
||||
try {
|
||||
return BlockAxis.valueOf(rotatable.getAxis().toString());
|
||||
} catch (IllegalArgumentException e) {
|
||||
@ -41,9 +49,10 @@ public class SpigotWorldContainer implements WorldContainer {
|
||||
|
||||
@Override
|
||||
public void setBlockAxis(BlockLocation location, BlockAxis axis) {
|
||||
var block = world.getBlockAt(location.getPosX(), location.getPosY(), location.getPosZ());
|
||||
var block = world.getBlockAt(location.getPosX(), location.getPosY(),
|
||||
location.getPosZ());
|
||||
var matData = block.getState().getBlockData();
|
||||
if(matData instanceof Orientable rotatable) {
|
||||
if (matData instanceof Orientable rotatable) {
|
||||
rotatable.setAxis(Axis.valueOf(axis.toString()));
|
||||
block.setBlockData(rotatable);
|
||||
}
|
||||
|
@ -3,14 +3,6 @@ package com.sekwah.advancedportals.spigot.metrics;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@ -20,8 +12,13 @@ import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
|
||||
/**
|
||||
* bStats collects some data for plugin authors.
|
||||
@ -30,28 +27,23 @@ import javax.net.ssl.HttpsURLConnection;
|
||||
*/
|
||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||
public class Metrics {
|
||||
|
||||
static {
|
||||
// You can use the property to disable the check in your test environment
|
||||
// You can use the property to disable the check in your test
|
||||
// environment
|
||||
if (System.getProperty("bstats.relocatecheck") == null
|
||||
|| !System.getProperty("bstats.relocatecheck").equals("false")) {
|
||||
// Maven's Relocate is clever and changes strings, too. So we have to use this little
|
||||
// "trick" ... :D
|
||||
final String defaultPackage =
|
||||
new String(
|
||||
new byte[] {
|
||||
'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u',
|
||||
'k', 'k', 'i', 't'
|
||||
});
|
||||
final String examplePackage =
|
||||
new String(
|
||||
new byte[] {
|
||||
'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'
|
||||
});
|
||||
// We want to make sure nobody just copy & pastes the example and use the wrong package
|
||||
// names
|
||||
// Maven's Relocate is clever and changes strings, too. So we have
|
||||
// to use this little "trick" ... :D
|
||||
final String defaultPackage = new String(
|
||||
new byte[] {'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's',
|
||||
'.', 'b', 'u', 'k', 'k', 'i', 't'});
|
||||
final String examplePackage = new String(new byte[] {
|
||||
'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
||||
// We want to make sure nobody just copy & pastes the example and
|
||||
// use the wrong package names
|
||||
if (Metrics.class.getPackage().getName().equals(defaultPackage)
|
||||
|| Metrics.class.getPackage().getName().equals(examplePackage)) {
|
||||
|| Metrics.class.getPackage().getName().equals(
|
||||
examplePackage)) {
|
||||
throw new IllegalStateException(
|
||||
"bStats Metrics class has not been relocated correctly!");
|
||||
}
|
||||
@ -97,13 +89,14 @@ public class Metrics {
|
||||
this.plugin = plugin;
|
||||
|
||||
// Get the config file
|
||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
||||
File bStatsFolder =
|
||||
new File(plugin.getDataFolder().getParentFile(), "bStats");
|
||||
File configFile = new File(bStatsFolder, "config.yaml");
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||
YamlConfiguration config =
|
||||
YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
// Check if the config file exists
|
||||
if (!config.isSet("serverUuid")) {
|
||||
|
||||
// Add default values
|
||||
config.addDefault("enabled", true);
|
||||
// Every server gets it's unique random id.
|
||||
@ -118,7 +111,8 @@ public class Metrics {
|
||||
// Inform the server owners about bStats
|
||||
config.options()
|
||||
.header(
|
||||
"bStats collects some data for plugin authors like how many servers are"
|
||||
"bStats collects some data for plugin authors like how "
|
||||
+ "many servers are"
|
||||
+ " using their plugins.\n"
|
||||
+ "To honor their work, you should not disable it.\n"
|
||||
+ "This has nearly no effect on the server performance!\n"
|
||||
@ -135,12 +129,15 @@ public class Metrics {
|
||||
serverUUID = config.getString("serverUuid");
|
||||
logFailedRequests = config.getBoolean("logFailedRequests", false);
|
||||
logSentData = config.getBoolean("logSentData", false);
|
||||
logResponseStatusText = config.getBoolean("logResponseStatusText", false);
|
||||
logResponseStatusText =
|
||||
config.getBoolean("logResponseStatusText", false);
|
||||
|
||||
if (enabled) {
|
||||
boolean found = false;
|
||||
// Search for all other bStats Metrics classes to see if we are the first one
|
||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
||||
// Search for all other bStats Metrics classes to see if we are the
|
||||
// first one
|
||||
for (Class<?> service :
|
||||
Bukkit.getServicesManager().getKnownServices()) {
|
||||
try {
|
||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||
found = true; // We aren't the first
|
||||
@ -149,8 +146,8 @@ public class Metrics {
|
||||
}
|
||||
}
|
||||
// Register our service
|
||||
Bukkit.getServicesManager()
|
||||
.register(Metrics.class, this, plugin, ServicePriority.Normal);
|
||||
Bukkit.getServicesManager().register(Metrics.class, this, plugin,
|
||||
ServicePriority.Normal);
|
||||
if (!found) {
|
||||
// We are the first!
|
||||
startSubmitting();
|
||||
@ -179,33 +176,31 @@ public class Metrics {
|
||||
charts.add(chart);
|
||||
}
|
||||
|
||||
/** Starts the Scheduler which submits our data every 30 minutes. */
|
||||
/**
|
||||
* Starts the Scheduler which submits our data every 30 minutes.
|
||||
*/
|
||||
private void startSubmitting() {
|
||||
final Timer timer =
|
||||
new Timer(
|
||||
true); // We use a timer cause the Bukkit scheduler is affected by server
|
||||
// lags
|
||||
timer.scheduleAtFixedRate(
|
||||
new TimerTask() {
|
||||
new Timer(true); // We use a timer cause the Bukkit
|
||||
// scheduler is affected by server lags
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!plugin.isEnabled()) { // Plugin was disabled
|
||||
timer.cancel();
|
||||
return;
|
||||
}
|
||||
// Nevertheless we want our code to run in the Bukkit main thread, so we
|
||||
// have to use the Bukkit scheduler
|
||||
// Don't be afraid! The connection to the bStats server is still async, only
|
||||
// the stats collection is sync ;)
|
||||
// Nevertheless we want our code to run in the Bukkit main
|
||||
// thread, so we have to use the Bukkit scheduler Don't be
|
||||
// afraid! The connection to the bStats server is still async,
|
||||
// only the stats collection is sync ;)
|
||||
Bukkit.getScheduler().runTask(plugin, () -> submitData());
|
||||
}
|
||||
},
|
||||
1000 * 60 * 5,
|
||||
1000 * 60 * 30);
|
||||
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough
|
||||
// time to start
|
||||
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
|
||||
// WARNING: Just don't do it!
|
||||
}, 1000 * 60 * 5, 1000 * 60 * 30);
|
||||
// Submit the data every 30 minutes, first time after 5 minutes to give
|
||||
// other plugins enough time to start WARNING: Changing the frequency
|
||||
// has no effect but your plugin WILL be blocked/deleted! WARNING: Just
|
||||
// don't do it!
|
||||
}
|
||||
|
||||
/**
|
||||
@ -219,8 +214,10 @@ public class Metrics {
|
||||
String pluginName = plugin.getDescription().getName();
|
||||
String pluginVersion = plugin.getDescription().getVersion();
|
||||
|
||||
data.addProperty("pluginName", pluginName); // Append the name of the plugin
|
||||
data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin
|
||||
data.addProperty("pluginName",
|
||||
pluginName); // Append the name of the plugin
|
||||
data.addProperty("pluginVersion",
|
||||
pluginVersion); // Append the version of the plugin
|
||||
JsonArray customCharts = new JsonArray();
|
||||
for (CustomChart customChart : charts) {
|
||||
// Add the data of the custom charts
|
||||
@ -244,16 +241,18 @@ public class Metrics {
|
||||
// Minecraft specific data
|
||||
int playerAmount;
|
||||
try {
|
||||
// Around MC 1.8 the return type was changed to a collection from an array,
|
||||
// This fixes java.lang.NoSuchMethodError:
|
||||
// Around MC 1.8 the return type was changed to a collection from an
|
||||
// array, This fixes java.lang.NoSuchMethodError:
|
||||
// org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
||||
Method onlinePlayersMethod =
|
||||
Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
||||
Method onlinePlayersMethod = Class.forName("org.bukkit.Server")
|
||||
.getMethod("getOnlinePlayers");
|
||||
playerAmount =
|
||||
onlinePlayersMethod.getReturnType().equals(Collection.class)
|
||||
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer()))
|
||||
? ((Collection<?>) onlinePlayersMethod.invoke(
|
||||
Bukkit.getServer()))
|
||||
.size()
|
||||
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
||||
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer()))
|
||||
.length;
|
||||
} catch (Exception e) {
|
||||
playerAmount =
|
||||
Bukkit.getOnlinePlayers()
|
||||
@ -288,21 +287,23 @@ public class Metrics {
|
||||
return data;
|
||||
}
|
||||
|
||||
/** Collects the data and sends it afterwards. */
|
||||
/**
|
||||
* Collects the data and sends it afterwards.
|
||||
*/
|
||||
private void submitData() {
|
||||
final JsonObject data = getServerData();
|
||||
|
||||
JsonArray pluginData = new JsonArray();
|
||||
// Search for all other bStats Metrics classes to get their plugin data
|
||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
||||
for (Class<?> service :
|
||||
Bukkit.getServicesManager().getKnownServices()) {
|
||||
try {
|
||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||
|
||||
for (RegisteredServiceProvider<?> provider :
|
||||
Bukkit.getServicesManager().getRegistrations(service)) {
|
||||
try {
|
||||
Object plugin =
|
||||
provider.getService()
|
||||
Object plugin = provider.getService()
|
||||
.getMethod("getPluginData")
|
||||
.invoke(provider.getProvider());
|
||||
if (plugin instanceof JsonObject) {
|
||||
@ -311,30 +312,32 @@ public class Metrics {
|
||||
try {
|
||||
Class<?> jsonObjectJsonSimple =
|
||||
Class.forName("org.json.simple.JSONObject");
|
||||
if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) {
|
||||
if (plugin.getClass().isAssignableFrom(
|
||||
jsonObjectJsonSimple)) {
|
||||
Method jsonStringGetter =
|
||||
jsonObjectJsonSimple.getDeclaredMethod("toJSONString");
|
||||
jsonObjectJsonSimple.getDeclaredMethod(
|
||||
"toJSONString");
|
||||
jsonStringGetter.setAccessible(true);
|
||||
String jsonString = (String) jsonStringGetter.invoke(plugin);
|
||||
JsonObject object =
|
||||
new JsonParser().parse(jsonString).getAsJsonObject();
|
||||
String jsonString =
|
||||
(String) jsonStringGetter.invoke(
|
||||
plugin);
|
||||
JsonObject object = new JsonParser()
|
||||
.parse(jsonString)
|
||||
.getAsJsonObject();
|
||||
pluginData.add(object);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
// minecraft version 1.14+
|
||||
if (logFailedRequests) {
|
||||
this.plugin
|
||||
.getLogger()
|
||||
.log(
|
||||
this.plugin.getLogger().log(
|
||||
Level.SEVERE,
|
||||
"Encountered unexpected exception",
|
||||
e);
|
||||
"Encountered unexpected exception", e);
|
||||
}
|
||||
continue; // continue looping since we cannot do any other thing.
|
||||
continue; // continue looping since we cannot do
|
||||
// any other thing.
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException
|
||||
| NoSuchMethodException
|
||||
} catch (NullPointerException | NoSuchMethodException
|
||||
| IllegalAccessException
|
||||
| InvocationTargetException ignored) {
|
||||
}
|
||||
@ -346,8 +349,7 @@ public class Metrics {
|
||||
data.add("plugins", pluginData);
|
||||
|
||||
// Create a new thread for the connection to the bStats server
|
||||
new Thread(
|
||||
new Runnable() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -356,8 +358,7 @@ public class Metrics {
|
||||
} catch (Exception e) {
|
||||
// Something went wrong! :(
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger()
|
||||
.log(
|
||||
plugin.getLogger().log(
|
||||
Level.WARNING,
|
||||
"Could not submit plugin stats of "
|
||||
+ plugin.getName(),
|
||||
@ -365,8 +366,7 @@ public class Metrics {
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.start();
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -376,7 +376,8 @@ public class Metrics {
|
||||
* @param data The data to send.
|
||||
* @throws Exception If the request failed.
|
||||
*/
|
||||
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
|
||||
private static void sendData(Plugin plugin, JsonObject data)
|
||||
throws Exception {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null!");
|
||||
}
|
||||
@ -385,9 +386,11 @@ public class Metrics {
|
||||
"This method must not be called from the main thread!");
|
||||
}
|
||||
if (logSentData) {
|
||||
plugin.getLogger().info("Sending data to bStats: " + data.toString());
|
||||
plugin.getLogger().info("Sending data to bStats: "
|
||||
+ data.toString());
|
||||
}
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||
HttpsURLConnection connection =
|
||||
(HttpsURLConnection) new URL(URL).openConnection();
|
||||
|
||||
// Compress the data to save bandwidth
|
||||
byte[] compressedData = compress(data.toString());
|
||||
@ -396,21 +399,27 @@ public class Metrics {
|
||||
connection.setRequestMethod("POST");
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||
connection.addRequestProperty("Content-Encoding",
|
||||
"gzip"); // We gzip our request
|
||||
connection.addRequestProperty("Content-Length",
|
||||
String.valueOf(compressedData.length));
|
||||
connection.setRequestProperty(
|
||||
"Content-Type", "application/json"); // We send our data in JSON format
|
||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
||||
"Content-Type",
|
||||
"application/json"); // We send our data in JSON format
|
||||
connection.setRequestProperty("User-Agent",
|
||||
"MC-Server/" + B_STATS_VERSION);
|
||||
|
||||
// Send data
|
||||
connection.setDoOutput(true);
|
||||
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
|
||||
DataOutputStream outputStream =
|
||||
new DataOutputStream(connection.getOutputStream());
|
||||
outputStream.write(compressedData);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
InputStream inputStream = connection.getInputStream();
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
BufferedReader bufferedReader =
|
||||
new BufferedReader(new InputStreamReader(inputStream));
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String line;
|
||||
@ -419,8 +428,9 @@ public class Metrics {
|
||||
}
|
||||
bufferedReader.close();
|
||||
if (logResponseStatusText) {
|
||||
plugin.getLogger()
|
||||
.info("Sent data to bStats and received response: " + builder.toString());
|
||||
plugin.getLogger().info(
|
||||
"Sent data to bStats and received response: "
|
||||
+ builder.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -442,9 +452,10 @@ public class Metrics {
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/** Represents a custom chart. */
|
||||
/**
|
||||
* Represents a custom chart.
|
||||
*/
|
||||
public abstract static class CustomChart {
|
||||
|
||||
// The id of the chart
|
||||
final String chartId;
|
||||
|
||||
@ -455,7 +466,8 @@ public class Metrics {
|
||||
*/
|
||||
CustomChart(String chartId) {
|
||||
if (chartId == null || chartId.isEmpty()) {
|
||||
throw new IllegalArgumentException("ChartId cannot be null or empty!");
|
||||
throw new IllegalArgumentException(
|
||||
"ChartId cannot be null or empty!");
|
||||
}
|
||||
this.chartId = chartId;
|
||||
}
|
||||
@ -472,10 +484,10 @@ public class Metrics {
|
||||
chart.add("data", data);
|
||||
} catch (Throwable t) {
|
||||
if (logFailedRequests) {
|
||||
Bukkit.getLogger()
|
||||
.log(
|
||||
Bukkit.getLogger().log(
|
||||
Level.WARNING,
|
||||
"Failed to get data for custom chart with id " + chartId,
|
||||
"Failed to get data for custom chart with id "
|
||||
+ chartId,
|
||||
t);
|
||||
}
|
||||
return null;
|
||||
@ -486,9 +498,10 @@ public class Metrics {
|
||||
protected abstract JsonObject getChartData() throws Exception;
|
||||
}
|
||||
|
||||
/** Represents a custom simple pie. */
|
||||
/**
|
||||
* Represents a custom simple pie.
|
||||
*/
|
||||
public static class SimplePie extends CustomChart {
|
||||
|
||||
private final Callable<String> callable;
|
||||
|
||||
/**
|
||||
@ -515,9 +528,10 @@ public class Metrics {
|
||||
}
|
||||
}
|
||||
|
||||
/** Represents a custom advanced pie. */
|
||||
/**
|
||||
* Represents a custom advanced pie.
|
||||
*/
|
||||
public static class AdvancedPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
@ -526,7 +540,8 @@ public class Metrics {
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
public AdvancedPie(String chartId,
|
||||
Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
@ -557,9 +572,10 @@ public class Metrics {
|
||||
}
|
||||
}
|
||||
|
||||
/** Represents a custom drilldown pie. */
|
||||
/**
|
||||
* Represents a custom drilldown pie.
|
||||
*/
|
||||
public static class DrilldownPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Map<String, Integer>>> callable;
|
||||
|
||||
/**
|
||||
@ -568,7 +584,9 @@ public class Metrics {
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
|
||||
public DrilldownPie(
|
||||
String chartId,
|
||||
Callable<Map<String, Map<String, Integer>>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
@ -583,12 +601,14 @@ public class Metrics {
|
||||
return null;
|
||||
}
|
||||
boolean reallyAllSkipped = true;
|
||||
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
|
||||
for (Map.Entry<String, Map<String, Integer>> entryValues :
|
||||
map.entrySet()) {
|
||||
JsonObject value = new JsonObject();
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> valueEntry :
|
||||
map.get(entryValues.getKey()).entrySet()) {
|
||||
value.addProperty(valueEntry.getKey(), valueEntry.getValue());
|
||||
value.addProperty(valueEntry.getKey(),
|
||||
valueEntry.getValue());
|
||||
allSkipped = false;
|
||||
}
|
||||
if (!allSkipped) {
|
||||
@ -605,9 +625,10 @@ public class Metrics {
|
||||
}
|
||||
}
|
||||
|
||||
/** Represents a custom single line chart. */
|
||||
/**
|
||||
* Represents a custom single line chart.
|
||||
*/
|
||||
public static class SingleLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Integer> callable;
|
||||
|
||||
/**
|
||||
@ -634,9 +655,10 @@ public class Metrics {
|
||||
}
|
||||
}
|
||||
|
||||
/** Represents a custom multi line chart. */
|
||||
/**
|
||||
* Represents a custom multi line chart.
|
||||
*/
|
||||
public static class MultiLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
@ -645,7 +667,8 @@ public class Metrics {
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
public MultiLineChart(String chartId,
|
||||
Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
@ -676,9 +699,10 @@ public class Metrics {
|
||||
}
|
||||
}
|
||||
|
||||
/** Represents a custom simple bar chart. */
|
||||
/**
|
||||
* Represents a custom simple bar chart.
|
||||
*/
|
||||
public static class SimpleBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
@ -687,7 +711,8 @@ public class Metrics {
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
public SimpleBarChart(String chartId,
|
||||
Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
@ -711,9 +736,10 @@ public class Metrics {
|
||||
}
|
||||
}
|
||||
|
||||
/** Represents a custom advanced bar chart. */
|
||||
/**
|
||||
* Represents a custom advanced bar chart.
|
||||
*/
|
||||
public static class AdvancedBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, int[]>> callable;
|
||||
|
||||
/**
|
||||
@ -722,7 +748,8 @@ public class Metrics {
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
|
||||
public AdvancedBarChart(String chartId,
|
||||
Callable<Map<String, int[]>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
@ -1,37 +1,39 @@
|
||||
package com.sekwah.advancedportals.spigot.reflection;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Just a util class to force spigot to allow us to have fun with the minecraft: channel category
|
||||
* Just a util class to force spigot to allow us to have fun with the
|
||||
* minecraft: channel category
|
||||
*
|
||||
* <p>Atm at least this is just designed to be able to access debug/ for showing visuals of the
|
||||
* portals and such
|
||||
* <p>Atm at least this is just designed to be able to access debug/ for
|
||||
* showing visuals of the portals and such
|
||||
*/
|
||||
public class MinecraftCustomPayload {
|
||||
|
||||
public static boolean sendCustomPayload(Player player, String channel, byte[] data) {
|
||||
public static boolean sendCustomPayload(Player player, String channel,
|
||||
byte[] data) {
|
||||
try {
|
||||
// Access the MinecraftKey class using reflection
|
||||
Class<?> minecraftKeyClass = Class.forName("net.minecraft.resources.MinecraftKey");
|
||||
Constructor<?> minecraftKeyConstructor = minecraftKeyClass.getConstructor(String.class);
|
||||
Class<?> minecraftKeyClass =
|
||||
Class.forName("net.minecraft.resources.MinecraftKey");
|
||||
Constructor<?> minecraftKeyConstructor =
|
||||
minecraftKeyClass.getConstructor(String.class);
|
||||
|
||||
// Create an instance of MinecraftKey with the channel name
|
||||
Object minecraftKey = minecraftKeyConstructor.newInstance(channel);
|
||||
|
||||
// Access the sendCustomPayload method in the CraftPlayer class
|
||||
Method sendCustomPayloadMethod =
|
||||
player.getClass()
|
||||
.getDeclaredMethod(
|
||||
player.getClass().getDeclaredMethod(
|
||||
"sendCustomPayload", minecraftKeyClass, byte[].class);
|
||||
|
||||
// Make the private method accessible
|
||||
sendCustomPayloadMethod.setAccessible(true);
|
||||
|
||||
// Invoke the sendCustomPayload method with the MinecraftKey and data
|
||||
// Invoke the sendCustomPayload method with the MinecraftKey and
|
||||
// data
|
||||
sendCustomPayloadMethod.invoke(player, minecraftKey, data);
|
||||
|
||||
return true; // Successfully sent the custom payload
|
||||
|
@ -2,23 +2,17 @@ package com.sekwah.advancedportals.spigot.utils;
|
||||
|
||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class ContainerHelpers {
|
||||
|
||||
public static PlayerLocation toPlayerLocation(Location loc) {
|
||||
return new PlayerLocation(
|
||||
loc.getWorld().getName(),
|
||||
loc.getX(),
|
||||
loc.getY(),
|
||||
loc.getZ(),
|
||||
loc.getYaw(),
|
||||
return new PlayerLocation(loc.getWorld().getName(), loc.getX(),
|
||||
loc.getY(), loc.getZ(), loc.getYaw(),
|
||||
loc.getPitch());
|
||||
}
|
||||
|
||||
public static BlockLocation toBlockLocation(Location loc) {
|
||||
return new BlockLocation(
|
||||
loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
return new BlockLocation(loc.getWorld().getName(), loc.getBlockX(),
|
||||
loc.getBlockY(), loc.getBlockZ());
|
||||
}
|
||||
}
|
||||
|
@ -8,27 +8,31 @@ import com.sekwah.advancedportals.spigot.connector.container.SpigotPlayerContain
|
||||
import org.bukkit.Effect;
|
||||
|
||||
public class EnderWarpEffect implements WarpEffect.Visual, WarpEffect.Sound {
|
||||
|
||||
@Override
|
||||
public void onWarpSound(PlayerContainer playerContainer, WarpEffect.Action action) {
|
||||
if(playerContainer instanceof SpigotPlayerContainer spigotPlayerContainer) {
|
||||
public void onWarpSound(PlayerContainer playerContainer,
|
||||
WarpEffect.Action action) {
|
||||
if (playerContainer
|
||||
instanceof SpigotPlayerContainer spigotPlayerContainer) {
|
||||
var player = spigotPlayerContainer.getPlayer();
|
||||
|
||||
player.getWorld().playSound(player.getLocation(), "entity.enderman.teleport", 1, 1);
|
||||
player.getWorld().playSound(player.getLocation(),
|
||||
"entity.enderman.teleport", 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWarpVisual(PlayerContainer playerContainer, WarpEffect.Action action) {
|
||||
if(playerContainer instanceof SpigotPlayerContainer spigotPlayerContainer) {
|
||||
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();
|
||||
for(int i = 0; i < 10; i++){
|
||||
for (int i = 0; i < 10; i++) {
|
||||
world.playEffect(loc, Effect.ENDER_SIGNAL, 0);
|
||||
}
|
||||
loc.add(0D, 1D, 0D);
|
||||
for(int i = 0; i < 10; i++){
|
||||
for (int i = 0; i < 10; i++) {
|
||||
world.playEffect(loc, Effect.ENDER_SIGNAL, 0);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,9 @@
|
||||
package com.sekwah.advancedportals.spigot.warpeffects;
|
||||
|
||||
import com.sekwah.advancedportals.core.registry.WarpEffectRegistry;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class SpigotWarpEffects {
|
||||
|
||||
@Inject private WarpEffectRegistry warpEffectRegistry;
|
||||
|
||||
public void registerEffects() {
|
||||
|
Loading…
Reference in New Issue
Block a user