feat: switch files over to using yaml (#427)

This commit is contained in:
Sekwah 2024-06-16 03:32:49 +01:00
parent 8afbae50fb
commit 5f44e24824
31 changed files with 495 additions and 254 deletions

View File

@ -244,16 +244,16 @@ tasks.register('copyPlugin') {
def destinationFilePath = Paths.get("$buildDir/MinecraftServer/plugins/Advanced-Portals.jar")
println "Handling file: $destinationFilePath"
byte[] newContent = Files.readAllBytes(sourceFilePath)
if (Files.exists(destinationFilePath)) {
println "File exists. Overwriting with new binary content."
Files.write(destinationFilePath, newContent, StandardOpenOption.TRUNCATE_EXISTING)
} else {
println "File does not exist. Copying from source."
Files.copy(sourceFilePath, destinationFilePath, StandardCopyOption.REPLACE_EXISTING)
}
}

View File

@ -19,6 +19,8 @@ dependencies {
implementation group: 'com.google.code.gson', name: 'gson', version:'2.8.9'
includeLibs group: 'com.google.inject', name: 'guice', version:'5.0.1'
implementation group: 'com.google.inject', name: 'guice', version:'5.0.1'
implementation group: 'org.yaml', name: 'snakeyaml', version: '2.2'
includeLibs group: 'org.yaml', name: 'snakeyaml', version: '2.2'
implementation group: 'com.google.guava', name: 'guava', version: '33.2.0-jre'
implementation group: 'io.netty', name: 'netty-buffer', version: '4.1.109.Final'
implementation group: 'io.netty', name: 'netty-codec', version: '4.1.109.Final'

View File

@ -9,6 +9,7 @@ import com.sekwah.advancedportals.core.commands.subcommands.portal.*;
import com.sekwah.advancedportals.core.connector.commands.CommandRegister;
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
import com.sekwah.advancedportals.core.registry.TagRegistry;
import com.sekwah.advancedportals.core.repository.IPlayerDataRepository;
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
import com.sekwah.advancedportals.core.module.AdvancedPortalsModule;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
@ -67,6 +68,10 @@ public class AdvancedPortalsCore {
@Inject
private GameScheduler gameScheduler;
// TEMP REMOVE THIS THIS IS JUST FOR DEV
@Inject
private IPlayerDataRepository tempDataRepository;
public AdvancedPortalsCore(String mcVersion, File dataStorageLoc, InfoLogger infoLogger, ServerContainer serverContainer) {
instance = this;
this.serverContainer = serverContainer;
@ -74,11 +79,11 @@ public class AdvancedPortalsCore {
this.infoLogger = infoLogger;
int[] mcVersionTemp;
infoLogger.log("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();
} catch (NumberFormatException e) {
infoLogger.log("Failed to parse MC version: " + mcVersion);
infoLogger.info("Failed to parse MC version: " + mcVersion);
e.printStackTrace();
mcVersionTemp = new int[]{0, 0, 0};
}
@ -110,7 +115,7 @@ public class AdvancedPortalsCore {
this.portalServices.loadPortals();
this.destinationServices.loadDestinations();
this.infoLogger.log(Lang.translate("logger.pluginenable"));
this.infoLogger.info(Lang.translate("logger.pluginenable"));
}
private void registerTags() {
@ -172,14 +177,14 @@ public class AdvancedPortalsCore {
*/
public void loadPortalConfig() {
this.configRepository.loadConfig(this.dataStorage);
this.dataStorage.storeJson(this.configRepository, "config.json");
this.configRepository.storeConfig();
}
public void onDisable() {
for(var playerContainer : this.serverContainer.getPlayers()) {
playerDataRepository.playerLeave(playerContainer);
}
this.infoLogger.log(Lang.translate("logger.plugindisable"));
this.infoLogger.info(Lang.translate("logger.plugindisable"));
}
public InfoLogger getInfoLogger() {

View File

@ -48,8 +48,8 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand {
// Find the tag with the "name" NAME
DataTag nameTag = portalTags.stream().filter(tag -> {
this.infoLogger.log("Tag: " + tag.NAME);
this.infoLogger.log("Equals: " + tag.NAME.equals(NameTag.TAG_NAME));
this.infoLogger.info("Tag: " + tag.NAME);
this.infoLogger.info("Equals: " + tag.NAME.equals(NameTag.TAG_NAME));
return tag.NAME.equals(NameTag.TAG_NAME);
}).findFirst().orElse(null);

View File

@ -105,36 +105,39 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
}
if (tempData.getPos1() != null && tempData.getPos2() != null && tempData.getPos1().worldName.equals(player.getWorldName()) && tempData.getPos2().worldName.equals(player.getWorldName())) {
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().worldName.equals(player.getWorldName())) {
if(tempData.getPos1() != null && tempData.getPos1().getWorldName().equals(player.getWorldName())) {
Debug.addMarker(player, tempData.getPos1(), "Pos1", POS1_COLOR, SHOW_TICKS);
}
if(tempData.getPos2() != null && tempData.getPos2().worldName.equals(player.getWorldName())) {
if(tempData.getPos2() != null && 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().worldName, player.getWorldName()) && portal.isLocationInPortal(player.getLoc(), config.getVisibleRange())) {
if(Objects.equals(portal.getMinLoc().getWorldName(), player.getWorldName()) && portal.isLocationInPortal(player.getLoc(), config.getVisibleRange())) {
BlockLocation minLoc = portal.getMinLoc();
BlockLocation maxLoc = portal.getMaxLoc();
int midX = (minLoc.posX + maxLoc.posX) / 2;
int midZ = (minLoc.posZ + maxLoc.posZ) / 2;
BlockLocation midPoint = new BlockLocation(minLoc.worldName, midX, maxLoc.posY, midZ);
int midX = (minLoc.getPosX() + maxLoc.getPosX()) / 2;
int midZ = (minLoc.getPosZ() + maxLoc.getPosZ()) / 2;
BlockLocation midPoint = new BlockLocation(minLoc.getWorldName(), midX, maxLoc.getPosY(), midZ);
Color color;
if(portal.isTriggerBlock(world.getBlock(midPoint))) {
color = TRIGGER_OUTLINE_COLOR;
} else {
if(midPoint.posX == minLoc.posX || midPoint.posX == maxLoc.posX || midPoint.posZ == minLoc.posZ || midPoint.posZ == maxLoc.posZ)
if(midPoint.getPosX() == minLoc.getPosX() || midPoint.getPosX() == maxLoc.getPosX() || midPoint.getPosZ() == minLoc.getPosZ() || midPoint.getPosZ() == maxLoc.getPosZ())
color = OUTLINE_COLOR;
else
color = new Color(0, 0, 0, 0);
}
debugVisuals(player, portal, OUTLINE_COLOR, SHOW_TICKS, TRIGGER_COLOR);
Debug.addMarker(player, midPoint, portal.getArgValues(NameTag.TAG_NAME)[0], color, SHOW_TICKS);
var name = portal.getArgValues(NameTag.TAG_NAME);
if(name != null && name.length > 0) {
Debug.addMarker(player, midPoint, name[0], color, SHOW_TICKS);
}
}
}
}
@ -150,13 +153,13 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
}
private void debugVisuals(PlayerContainer player, BlockLocation pos1, BlockLocation pos2, Color color, int time, Color triggerColor, AdvancedPortal portal) {
int minX = Math.min(pos1.posX, pos2.posX);
int minY = Math.min(pos1.posY, pos2.posY);
int minZ = Math.min(pos1.posZ, pos2.posZ);
int minX = Math.min(pos1.getPosX(), pos2.getPosX());
int minY = Math.min(pos1.getPosY(), pos2.getPosY());
int minZ = Math.min(pos1.getPosZ(), pos2.getPosZ());
int maxX = Math.max(pos1.posX, pos2.posX);
int maxY = Math.max(pos1.posY, pos2.posY);
int maxZ = Math.max(pos1.posZ, pos2.posZ);
int maxX = Math.max(pos1.getPosX(), pos2.getPosX());
int maxY = Math.max(pos1.getPosY(), pos2.getPosY());
int maxZ = Math.max(pos1.getPosZ(), pos2.getPosZ());
var world = player.getWorld();
@ -171,7 +174,7 @@ 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.worldName, x, y, 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) && (x == minX || x == maxX || z == minZ || z == maxZ) || (z == minZ || z == maxZ) && (x == minX || x == maxX);
if (isTrigger && isOutline && alternate_show_trigger) {
@ -188,23 +191,23 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
} else {
for (int x = minX; x <= maxX; x++) {
Debug.addMarker(player, new BlockLocation(pos1.worldName, x, minY, minZ), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.worldName, x, minY, maxZ), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.worldName, x, maxY, minZ), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.worldName, x, maxY, maxZ), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.getWorldName(), x, minY, minZ), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.getWorldName(), x, minY, maxZ), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.getWorldName(), x, maxY, minZ), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.getWorldName(), x, maxY, maxZ), "", color, time);
}
for (int z = minZ + 1; z < maxZ; z++) {
Debug.addMarker(player, new BlockLocation(pos1.worldName, minX, minY, z), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.worldName, maxX, minY, z), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.worldName, minX, maxY, z), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.worldName, maxX, maxY, z), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.getWorldName(), minX, minY, z), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.getWorldName(), maxX, minY, z), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.getWorldName(), minX, maxY, z), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.getWorldName(), maxX, maxY, z), "", color, time);
}
for (int y = minY + 1; y < maxY; y++) {
Debug.addMarker(player, new BlockLocation(pos1.worldName, minX, y, minZ), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.worldName, maxX, y, minZ), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.worldName, minX, y, maxZ), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.worldName, maxX, y, maxZ), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.getWorldName(), minX, y, minZ), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.getWorldName(), maxX, y, minZ), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.getWorldName(), minX, y, maxZ), "", color, time);
Debug.addMarker(player, new BlockLocation(pos1.getWorldName(), maxX, y, maxZ), "", color, time);
}
}
}

View File

@ -1,24 +1,24 @@
package com.sekwah.advancedportals.core.connector.containers;
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
import com.sekwah.advancedportals.core.serializeddata.Vector;
public interface EntityContainer {
PlayerLocation getLoc();
double getHeight();
BlockLocation getBlockLoc();
boolean teleport(PlayerLocation location);
WorldContainer getWorld();
String getName();
String getWorldName();
void setVelocity(Vector vector);
}
package com.sekwah.advancedportals.core.connector.containers;
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
import com.sekwah.advancedportals.core.serializeddata.Vector;
public interface EntityContainer {
PlayerLocation getLoc();
double getHeight();
BlockLocation getBlockLoc();
boolean teleport(PlayerLocation location);
WorldContainer getWorld();
String getName();
String getWorldName();
void setVelocity(Vector vector);
}

View File

@ -1,6 +1,5 @@
package com.sekwah.advancedportals.core.destination;
import com.google.gson.annotations.SerializedName;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.registry.TagTarget;
@ -20,7 +19,7 @@ import java.util.Set;
* 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 effect performance and would definitely effect speed)
* could affect performance and would definitely affect speed)
*
* @author sekwah41
*/
@ -29,14 +28,16 @@ public class Destination implements TagTarget {
@Inject
transient TagRegistry tagRegistry;
@SerializedName("l")
private PlayerLocation loc;
@SerializedName("a")
private HashMap<String, String[]> args = new HashMap<>();
private transient Set<String> argsCol;
public Destination() {
this.loc = new PlayerLocation();
}
public Destination(PlayerLocation loc) {
this.loc = loc;
}

View File

@ -1,6 +1,5 @@
package com.sekwah.advancedportals.core.portal;
import com.google.gson.annotations.SerializedName;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.registry.TagTarget;
@ -25,13 +24,10 @@ public class AdvancedPortal implements TagTarget {
@Inject
private transient TagRegistry tagRegistry;
@SerializedName("max")
private BlockLocation maxLoc;
@SerializedName("min")
private BlockLocation minLoc;
@SerializedName("a")
private final HashMap<String, String[]> args = new HashMap<>();
@Inject
@ -40,6 +36,11 @@ public class AdvancedPortal implements TagTarget {
@Inject
transient ConfigRepository configRepository;
public AdvancedPortal() {
this.minLoc = new BlockLocation();
this.maxLoc = new BlockLocation();
}
public AdvancedPortal(BlockLocation minLoc, BlockLocation maxLoc, TagRegistry tagRegistry, PlayerDataServices playerDataServices) {
this.tagRegistry = tagRegistry;
this.playerDataServices = playerDataServices;
@ -59,6 +60,7 @@ public class AdvancedPortal implements TagTarget {
return this.args.get(argName);
}
@Override
public void setArgValues(String argName, String[] argValues) {
this.args.put(argName, argValues);
@ -66,7 +68,7 @@ public class AdvancedPortal implements TagTarget {
@Override
public void addArg(String argName, String argValues) {
// TODO need to add the ability to add args after creation
}
@Override
@ -81,16 +83,16 @@ public class AdvancedPortal implements TagTarget {
* @param loc2 The second location.
*/
public void updateBounds(BlockLocation loc1, BlockLocation loc2) {
int minX = Math.min(loc1.posX, loc2.posX);
int minY = Math.min(loc1.posY, loc2.posY);
int minZ = Math.min(loc1.posZ, loc2.posZ);
int minX = Math.min(loc1.getPosX(), loc2.getPosX());
int minY = Math.min(loc1.getPosY(), loc2.getPosY());
int minZ = Math.min(loc1.getPosZ(), loc2.getPosZ());
int maxX = Math.max(loc1.posX, loc2.posX);
int maxY = Math.max(loc1.posY, loc2.posY);
int maxZ = Math.max(loc1.posZ, loc2.posZ);
int maxX = Math.max(loc1.getPosX(), loc2.getPosX());
int maxY = Math.max(loc1.getPosY(), loc2.getPosY());
int maxZ = Math.max(loc1.getPosZ(), loc2.getPosZ());
this.minLoc = new BlockLocation(loc1.worldName, minX, minY, minZ);
this.maxLoc = new BlockLocation(loc2.worldName, maxX, maxY, maxZ);
this.minLoc = new BlockLocation(loc1.getWorldName(), minX, minY, minZ);
this.maxLoc = new BlockLocation(loc2.getWorldName(), maxX, maxY, maxZ);
}
/*public boolean hasTriggerBlock(String blockMaterial) {
@ -117,7 +119,8 @@ public class AdvancedPortal implements TagTarget {
player.sendMessage(Lang.translateInsertVariables("portal.cooldown.join", 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);
var rand = new Random();
player.playSound("block.portal.travel", 0.05f, rand.nextFloat() * 0.4F + 0.8F);
}
return false;
}
@ -171,16 +174,16 @@ public class AdvancedPortal implements TagTarget {
}
public boolean isLocationInPortal(BlockLocation loc, int additionalArea) {
double playerX = loc.posX;
double playerY = loc.posY;
double playerZ = loc.posZ;
double playerX = loc.getPosX();
double playerY = loc.getPosY();
double playerZ = loc.getPosZ();
return Objects.equals(loc.worldName, this.minLoc.worldName) && playerX >= this.minLoc.posX - additionalArea &&
playerX < this.maxLoc.posX + 1 + additionalArea &&
playerY >= this.minLoc.posY - additionalArea &&
playerY < this.maxLoc.posY + 1 + additionalArea &&
playerZ >= this.minLoc.posZ - additionalArea &&
playerZ < this.maxLoc.posZ + 1 + additionalArea;
return Objects.equals(loc.getWorldName(), this.minLoc.getWorldName()) && playerX >= this.minLoc.getPosX() - additionalArea &&
playerX < this.maxLoc.getPosX() + 1 + additionalArea &&
playerY >= this.minLoc.getPosY() - additionalArea &&
playerY < this.maxLoc.getPosY() + 1 + additionalArea &&
playerZ >= this.minLoc.getPosZ() - additionalArea &&
playerZ < this.maxLoc.getPosZ() + 1 + additionalArea;
}

View File

@ -31,4 +31,6 @@ public interface ConfigRepository {
double getThrowbackStrength();
boolean playFailSound();
void storeConfig();
}

View File

@ -12,6 +12,7 @@ public class ConfigRepositoryImpl implements ConfigRepository {
private HashMap<String, Config> configs;
private Config config;
private DataStorage dataStorage;
public ConfigRepositoryImpl() {
configs = new HashMap<String,Config>();
@ -89,7 +90,8 @@ public class ConfigRepositoryImpl implements ConfigRepository {
@Override
public void loadConfig(DataStorage dataStorage) {
this.config = dataStorage.loadJson(Config.class, "config.json");
this.dataStorage = dataStorage;
this.config = dataStorage.loadFile(Config.class, "config.yaml");
}
@Override
@ -97,4 +99,9 @@ public class ConfigRepositoryImpl implements ConfigRepository {
return this.config.playFailSound;
}
@Override
public void storeConfig() {
this.dataStorage.storeFile(this.config, "config.yaml");
}
}

View File

@ -1,17 +1,12 @@
package com.sekwah.advancedportals.core.repository.impl;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
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 com.sekwah.advancedportals.core.util.InfoLogger;
import javax.inject.Singleton;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
@ -24,20 +19,20 @@ public class DestinationRepositoryImpl implements IDestinationRepository {
@Override
public boolean save(String name, Destination destination) {
return dataStorage.storeJson(destination, fileLocation + name + ".json");
return dataStorage.storeFile(destination, fileLocation + name + ".yaml");
}
public boolean containsKey(String name) {
return dataStorage.fileExists(fileLocation + name + ".json");
return dataStorage.fileExists(fileLocation + name + ".yaml");
}
@Override
public boolean delete(String name) {
return dataStorage.deleteFile(fileLocation + name + ".json");
return dataStorage.deleteFile(fileLocation + name + ".yaml");
}
public Destination get(String name) {
return dataStorage.loadJson(Destination.class, fileLocation + name + ".json");
return dataStorage.loadFile(Destination.class, fileLocation + name + ".yaml");
}
@Override

View File

@ -1,17 +1,11 @@
package com.sekwah.advancedportals.core.repository.impl;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.destination.Destination;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.repository.IPlayerDataRepository;
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
import com.sekwah.advancedportals.core.serializeddata.PlayerData;
import java.util.List;
import java.util.UUID;
public class PlayerDataRepositoryImpl implements IPlayerDataRepository {
@ -22,7 +16,7 @@ public class PlayerDataRepositoryImpl implements IPlayerDataRepository {
@Override
public boolean save(String name, PlayerData playerData) {
return dataStorage.storeJson(playerData, fileLocation + name + ".json");
return dataStorage.storeFile(playerData, fileLocation + name + ".yaml");
}
@Override
@ -32,12 +26,12 @@ public class PlayerDataRepositoryImpl implements IPlayerDataRepository {
@Override
public boolean delete(String name) {
return dataStorage.deleteFile(fileLocation + name + ".json");
return dataStorage.deleteFile(fileLocation + name + ".yaml");
}
@Override
public PlayerData get(String name) {
return dataStorage.loadJson(PlayerData.class, fileLocation + name + ".json");
return dataStorage.loadFile(PlayerData.class, fileLocation + name + ".yaml");
}
@Override

View File

@ -27,29 +27,31 @@ public class PortalRepositoryImpl implements IPortalRepository {
@Override
public boolean save(String name, AdvancedPortal portal) {
return dataStorage.storeJson(portal, fileLocation + name + ".json");
return dataStorage.storeFile(portal, fileLocation + name + ".yaml");
}
@Override
public boolean containsKey(String name) {
return dataStorage.fileExists(fileLocation + name + ".json");
return dataStorage.fileExists(fileLocation + name + ".yaml");
}
@Override
public boolean delete(String name) {
return dataStorage.deleteFile(fileLocation + name + ".json");
return dataStorage.deleteFile(fileLocation + name + ".yaml");
}
@Override
public AdvancedPortal get(String name) {
var portal = dataStorage.loadJson(AdvancedPortal.class, fileLocation + name + ".json");
AdvancedPortalsCore.getInstance().getModule().getInjector().injectMembers(portal);
var portal = dataStorage.loadFile(AdvancedPortal.class, fileLocation + name + ".yaml");
if(portal != null) {
AdvancedPortalsCore.getInstance().getModule().getInjector().injectMembers(portal);
}
return portal;
}
@Override
public List<String> getAllNames() {
return dataStorage.listAllFiles(fileLocation, true);
return dataStorage.listAllFiles(fileLocation, true, "yaml");
}
@Override
@ -57,11 +59,11 @@ public class PortalRepositoryImpl implements IPortalRepository {
List<AdvancedPortal> portals = new ArrayList<>();
List<String> allFiles = dataStorage.listAllFiles(fileLocation, false);
for (String fileName : allFiles) {
AdvancedPortal portal = dataStorage.loadJson(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(".json", "")});
portal.setArgValues(NameTag.TAG_NAME, new String[]{fileName.replace(".yaml", "")});
}
portals.add(portal);
}

View File

@ -1,21 +1,26 @@
package com.sekwah.advancedportals.core.serializeddata;
import com.google.gson.annotations.SerializedName;
import com.sekwah.advancedportals.core.data.Direction;
import java.io.Serializable;
public class BlockLocation {
@SerializedName("x")
public final int posX;
// These should be treated as final, they only are not for serialization purposes
private final int posX;
@SerializedName("y")
public final int posY;
private final int posY;
@SerializedName("z")
public final int posZ;
private final int posZ;
@SerializedName("w")
public final String worldName;
private final String worldName;
public BlockLocation() {
this.worldName = "";
this.posX = 0;
this.posY = 0;
this.posZ = 0;
}
public BlockLocation(String worldName, int posX, int posY, int posZ) {
this.worldName = worldName;
@ -44,6 +49,10 @@ public class BlockLocation {
return posZ;
}
public String getWorldName() {
return worldName;
}
public boolean equals(BlockLocation location) {
return location.posX == this.posX && location.posY == this.posY && location.posZ == this.posZ && location.worldName.equals(this.worldName);
}

View File

@ -1,14 +1,17 @@
package com.sekwah.advancedportals.core.serializeddata;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
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 org.yaml.snakeyaml.representer.Representer;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
@ -16,9 +19,7 @@ import java.util.List;
public class DataStorage {
private Gson gson = new GsonBuilder().setPrettyPrinting().create();
private File dataFolder;
private final File dataFolder;
@Inject
private AdvancedPortalsCore portalsCore;
@ -30,12 +31,26 @@ public class DataStorage {
this.dataFolder = dataStorageLoc;
}
/**
* Copies the default file, defaults to true to keep true to the name
*
* @param fileLoc
* @return
*/
private Yaml getYaml(Class<? extends Object> clazz) {
LoaderOptions loaderOptions = new LoaderOptions();
TagInspector tagInspector = tag -> tag.getClassName().equals(clazz.getName());
loaderOptions.setTagInspector(tagInspector);
var options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
var representer = new ReflectiveRepresenter(options);
representer.addClassTag(clazz, Tag.MAP);
representer.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
var constructor = new ReflectiveConstructor(clazz, loaderOptions);
AdvancedPortalsCore.getInstance().getModule().getInjector().injectMembers(constructor);
return new Yaml(constructor, representer);
}
public boolean copyDefaultFile(String fileLoc) {
return this.copyDefaultFile(fileLoc, true);
}
@ -46,18 +61,9 @@ public class DataStorage {
}
}
public <T> T loadJson(Type dataHolder, String location) {
InputStream jsonResource = this.loadResource(location);
if(jsonResource == null) {
return null;
}
BufferedReader bufReader = new BufferedReader(new InputStreamReader(jsonResource));
T object = gson.fromJson(bufReader, dataHolder);
return object;
}
public <T> T loadJson(Class<T> dataHolder, String location) {
InputStream jsonResource = this.loadResource(location);
if(jsonResource == null) {
public <T> T loadFile(Class<T> dataHolder, String location) {
InputStream yamlResource = this.loadResource(location);
if (yamlResource == null) {
try {
return dataHolder.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
@ -65,29 +71,26 @@ public class DataStorage {
}
return null;
}
BufferedReader bufReader = new BufferedReader(new InputStreamReader(jsonResource));
T data = gson.fromJson(bufReader, dataHolder);
try {
bufReader.close();
} catch (IOException e) {
throw new RuntimeException(e);
Yaml yaml = getYaml(dataHolder);
try (BufferedReader bufReader = new BufferedReader(new InputStreamReader(yamlResource))) {
return yaml.loadAs(bufReader, dataHolder);
} catch (Exception e) {
infoLogger.warning("Failed to load file: " + location);
infoLogger.error(e);
return null;
}
return data;
}
public boolean storeJson(Object dataHolder, String location) {
// Create folders if they don't exist
public boolean storeFile(Object dataHolder, String location) {
Yaml yaml = getYaml(dataHolder.getClass());
File outFile = new File(this.dataFolder, location);
if (!outFile.getParentFile().exists()) { // Check if parent folder exists
if(!outFile.getParentFile().mkdirs()) {
infoLogger.warning("Failed to create folder for file: " + location);
}
if (!outFile.getParentFile().exists() && !outFile.getParentFile().mkdirs()) {
infoLogger.warning("Failed to create folder for file: " + location);
}
String json = gson.toJson(dataHolder);
try {
FileWriter fileWriter = new FileWriter(outFile); // Use outFile directly here
fileWriter.write(json);
fileWriter.close();
String yamlFile = yaml.dump(dataHolder);
try (FileWriter fileWriter = new FileWriter(outFile)) {
fileWriter.write(yamlFile);
return true;
} catch (IOException e) {
infoLogger.error(e);
@ -179,45 +182,51 @@ public class DataStorage {
}
private void writeToFile(InputStream inputStream, File outFile) throws IOException {
FileOutputStream outStream = new FileOutputStream(outFile);
byte[] buf = new byte[1024];
int len;
while ((len = inputStream.read(buf)) > 0) {
outStream.write(buf, 0, len);
try (FileOutputStream outStream = new FileOutputStream(outFile)) {
byte[] buf = new byte[1024];
int len;
while ((len = inputStream.read(buf)) > 0) {
outStream.write(buf, 0, len);
}
}
inputStream.close();
outStream.close();
}
public boolean fileExists(String name) {
return new File(this.dataFolder, name).exists();
}
public List<String> listAllFiles(String fileLocation, boolean trimExtension) {
return listAllFiles(fileLocation, trimExtension, null);
}
/**
* @param fileLocation
* @param trimExtension
* @param fileLocation - location of the folder to list
* @param trimExtension - if true will remove the file extension
* @param extension - if null will not filter by extension
* @return
*/
public List<String> listAllFiles(String fileLocation, boolean trimExtension) {
public List<String> listAllFiles(String fileLocation, boolean trimExtension, String extension) {
File directory = new File(dataFolder, fileLocation);
var list = new ArrayList<String>();
List<String> list = new ArrayList<>();
if (directory.exists() && directory.isDirectory()) {
File[] files = directory.listFiles();
if (files != null) {
for (File file : files) {
if (file.isFile()) {
String fileName = file.getName();
boolean extensionMatches = (extension == null || fileName.endsWith("." + extension));
if (trimExtension) {
int i = fileName.lastIndexOf('.');
if (i > 0) {
fileName = fileName.substring(0, i);
if (extensionMatches) {
if (trimExtension) {
int i = fileName.lastIndexOf('.');
if (i > 0) {
fileName = fileName.substring(0, i);
}
}
list.add(fileName);
}
list.add(fileName);
}
}
}
@ -232,7 +241,7 @@ public class DataStorage {
Files.delete(Paths.get(dataFolder.getAbsolutePath(), fileLocation));
return true;
} catch (IOException e) {
e.printStackTrace();
infoLogger.error(e);
return false;
}
}

View File

@ -1,15 +1,18 @@
package com.sekwah.advancedportals.core.serializeddata;
import com.google.gson.annotations.SerializedName;
public class PlayerLocation extends WorldLocation {
@SerializedName("r")
private final float yaw;
@SerializedName("p")
private final float pitch;
public PlayerLocation() {
super("", 0, 0, 0);
this.yaw = 0;
this.pitch = 0;
}
public PlayerLocation(String worldName, double posX, double posY, double posZ) {
super(worldName, posX, posY, posZ);
this.yaw = 0;
@ -23,15 +26,15 @@ public class PlayerLocation extends WorldLocation {
}
public double getPosX() {
return X;
return x;
}
public double getPosY() {
return Y;
return y;
}
public double getPosZ() {
return Z;
return z;
}
public String getWorldName() {

View File

@ -0,0 +1,199 @@
package com.sekwah.advancedportals.core.serializeddata;
import com.sekwah.advancedportals.core.util.InfoLogger;
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;
public ReflectiveConstructor(Class<T> clazz, LoaderOptions loadingConfig) {
super(clazz, loadingConfig);
this.clazz = clazz;
}
@Override
protected Object constructObject(Node node) {
return this.constructObject(clazz, node);
}
private Object constructObject(Class<?> currentClass, Node node) {
if (node instanceof MappingNode) {
return constructFromMappingNode(currentClass, (MappingNode) node);
} else if (node instanceof ScalarNode scalarNode) {
return constructFromScalarNode(scalarNode);
} else if(node instanceof SequenceNode sequenceNode) {
return constructFromSequenceNode(sequenceNode);
} else {
infoLogger.warning("Unexpected node type encountered: " + node.getClass().getSimpleName());
return null;
}
}
private Object constructFromSequenceNode(SequenceNode sequenceNode) {
List<?> list = (List<?>) super.constructObject(sequenceNode);
if (list == null || list.isEmpty()) {
return list;
}
Class<?> componentType = list.get(0).getClass();
Object array = Array.newInstance(componentType, list.size());
for (int i = 0; i < list.size(); i++) {
Array.set(array, i, list.get(i));
}
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
if (currentClass.equals(HashMap.class)) {
Map<String, Object> values = new HashMap<>();
for (NodeTuple tuple : mappingNode.getValue()) {
var key = (String) constructObject(tuple.getKeyNode());
var node = tuple.getValueNode();
if (node instanceof ScalarNode scalarNode) {
var constructedItem = constructFromScalarNode(scalarNode);
values.put(key, constructedItem);
} 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);
values.put(key, value);
} catch (Exception e) {
infoLogger.warning("Failed to construct object from mapping node: " + e.getMessage());
}
} else {
infoLogger.warning("Unexpected node type encountered: " + node.getClass().getSimpleName());
}
}
return values;
}
try {
Object instance;
try {
instance = currentClass.getDeclaredConstructor().newInstance();
} catch (NoSuchMethodException e) {
infoLogger.info("No default constructor found for " + currentClass.getName() + ", using unsafe allocation.");
instance = unsafe.allocateInstance(currentClass);
}
Map<String, Object> mappedValues = mapMappingNode(currentClass, mappingNode);
Field[] fields = getAllFields(currentClass);
for (Field field : fields) {
if (Modifier.isTransient(field.getModifiers())) {
continue;
}
try {
if (mappedValues.containsKey(field.getName())) {
Object value = mappedValues.get(field.getName());
setField(instance, field, value);
} else {
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());
infoLogger.error(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);
}
}
private Field[] getAllFields(Class<?> clazz) {
Map<String, Field> fields = new HashMap<>();
while (clazz != null) {
for (Field field : clazz.getDeclaredFields()) {
fields.putIfAbsent(field.getName(), field);
}
clazz = clazz.getSuperclass();
}
return fields.values().toArray(new Field[0]);
}
private Object constructFromScalarNode(ScalarNode scalarNode) {
return super.constructObject(scalarNode);
}
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());
var node = tuple.getValueNode();
if (node instanceof ScalarNode scalarNode) {
values.put(key, constructFromScalarNode(scalarNode));
} else if (node instanceof MappingNode mappingNodeChild) {
try {
var field = currentClass.getDeclaredField(key);
Object value = constructFromMappingNode(field.getType(), mappingNodeChild);
values.put(key, value);
} catch (NoSuchFieldException e) {
infoLogger.warning("Field " + key + " not found on " + currentClass.getName());
}
} else {
infoLogger.warning("Expected mapping node: " + node.getClass().getSimpleName());
}
}
return values;
}
/**
* Check and convert value types e.g. double to float
*/
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) {
value = ((Double) value).floatValue();
} else if (field.getType() == int.class && value instanceof Long) {
value = ((Long) value).intValue();
} 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();
}
field.setAccessible(true);
field.set(instance, value);
}
private static Unsafe getUnsafe() {
try {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (Unsafe) f.get(null);
} catch (Exception e) {
throw new RuntimeException("Failed to get Unsafe instance", e);
}
}
}

View File

@ -0,0 +1,13 @@
package com.sekwah.advancedportals.core.serializeddata;
import org.yaml.snakeyaml.DumperOptions;
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);
}
}

View File

@ -1,33 +1,28 @@
package com.sekwah.advancedportals.core.serializeddata;
import com.google.gson.annotations.SerializedName;
public class Vector {
@SerializedName("x")
public final double X;
protected final double x;
@SerializedName("y")
public final double Y;
protected final double y;
@SerializedName("z")
public final double Z;
protected final double z;
public Vector(double X, double Y, double Z) {
this.X = X;
this.Y = Y;
this.Z = Z;
this.x = X;
this.y = Y;
this.z = Z;
}
public Vector add(Vector vec) {
return new Vector(this.X + vec.X, this.Y + vec.Y, this.Z + vec.Z);
return new Vector(this.x + vec.x, this.y + vec.y, this.z + vec.z);
}
public Vector multiply(double value) {
return new Vector(this.X * value, this.Y * value, this.Z * value);
return new Vector(this.x * value, this.y * value, this.z * value);
}
public Vector setY(double y) {
return new Vector(this.X, y, this.Z);
return new Vector(this.x, y, this.z);
}
public double distanceTo(Vector pos) {
@ -35,22 +30,22 @@ public class Vector {
}
private double distanceToSq(Vector pos) {
double dx = this.X - pos.X;
double dy = this.Y - pos.Y;
double dz = this.Z - pos.Z;
double dx = this.x - pos.x;
double dy = this.y - pos.y;
double dz = this.z - pos.z;
return dx * dx + dy * dy + dz * dz;
}
public double getX() {
return this.X;
return this.x;
}
public double getY() {
return this.Y;
return this.y;
}
public double getZ() {
return this.Z;
return this.z;
}
public Vector normalize() {
@ -58,6 +53,6 @@ public class Vector {
}
private double length() {
return Math.sqrt(this.X * this.X + this.Y * this.Y + this.Z * this.Z);
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
}
}

View File

@ -1,10 +1,7 @@
package com.sekwah.advancedportals.core.serializeddata;
import com.google.gson.annotations.SerializedName;
public class WorldLocation extends Vector {
@SerializedName("w")
public final String worldName;
public WorldLocation(String worldName, double posX, double posY, double posZ) {
@ -13,6 +10,6 @@ public class WorldLocation extends Vector {
}
public BlockLocation toBlockPos() {
return new BlockLocation(this.worldName, (int) Math.floor(this.X), (int) Math.floor(this.Y), (int) Math.floor(this.Z));
return new BlockLocation(this.worldName, (int) Math.floor(this.x), (int) Math.floor(this.y), (int) Math.floor(this.z));
}
}

View File

@ -56,6 +56,6 @@ public final class PlayerDataServices {
} else {
tempData.setPos2(blockLoc);
}
player.sendMessage(Lang.translateInsertVariables("portal.selector.poschange", leftClick ? "1" : "2", blockLoc.posX, blockLoc.posY, blockLoc.posZ));
player.sendMessage(Lang.translateInsertVariables("portal.selector.poschange", leftClick ? "1" : "2", blockLoc.getPosX(), blockLoc.getPosY(), blockLoc.getPosZ()));
}
}

View File

@ -40,6 +40,9 @@ public class PortalServices {
portalCache.clear();
for (String name : portalNames) {
AdvancedPortal portal = portalRepository.get(name);
if(portal == null) {
continue;
}
portalCache.put(name, portal);
portal.updateBounds(portal.getMinLoc(), portal.getMaxLoc());
}
@ -132,7 +135,7 @@ public class PortalServices {
return null;
}
if(!tempData.getPos1().worldName.equals(tempData.getPos2().worldName)) {
if(!tempData.getPos1().getWorldName().equals(tempData.getPos2().getWorldName())) {
player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("portal.error.selection.differentworlds"));
return null;
}

View File

@ -113,8 +113,8 @@ public class FriendlyDataOutput {
private long blockAsLong(BlockLocation blockLoc) {
long i = 0L;
i |= ((long)blockLoc.posX & PACKED_X_MASK) << X_OFFSET;
i |= ((long)blockLoc.posY & PACKED_Y_MASK) << 0;
return i | ((long)blockLoc.posZ & PACKED_Z_MASK) << Z_OFFSET;
i |= ((long)blockLoc.getPosX() & PACKED_X_MASK) << X_OFFSET;
i |= ((long)blockLoc.getPosY() & PACKED_Y_MASK) << 0;
return i | ((long)blockLoc.getPosZ() & PACKED_Z_MASK) << Z_OFFSET;
}
}

View File

@ -13,7 +13,7 @@ public abstract class InfoLogger {
* General information logging
* @param s info message
*/
public abstract void log(String s);
public abstract void info(String s);
public abstract void error(Exception e);
}

View File

@ -175,4 +175,3 @@ tag.name.error.nospaces= The name cannot contain spaces.
tag.triggerblock.description=Sets the trigger block/s of the portal. Comma seperated or multi tag.
tag.cooldown.fail= The cooldown must be a number.

View File

@ -18,7 +18,7 @@ public class SpigotInfoLogger extends InfoLogger {
}
@Override
public void log(String s) {
public void info(String s) {
plugin.getLogger().info(s);
}

View File

@ -45,7 +45,7 @@ public class UpdatePortalSubCommand implements SubCommand {
}
private int importPortals() {
ConfigAccessor portalConfig = new ConfigAccessor(AdvancedPortalsPlugin.getInstance(), "portals.yml");
ConfigAccessor portalConfig = new ConfigAccessor(AdvancedPortalsPlugin.getInstance(), "portals.yaml");
var config = portalConfig.getConfig();
Set<String> portalSet = config.getKeys(false);
@ -114,7 +114,7 @@ public class UpdatePortalSubCommand implements SubCommand {
}
public int importDestinations() {
ConfigAccessor destiConfig = new ConfigAccessor(AdvancedPortalsPlugin.getInstance(), "destinations.yml");
ConfigAccessor destiConfig = new ConfigAccessor(AdvancedPortalsPlugin.getInstance(), "destinations.yaml");
var config = destiConfig.getConfig();
Set<String> destiSet = config.getKeys(false);
@ -133,7 +133,7 @@ public class UpdatePortalSubCommand implements SubCommand {
}
public int getDestinationCount() {
ConfigAccessor destiConfig = new ConfigAccessor(AdvancedPortalsPlugin.getInstance(), "destinations.yml");
ConfigAccessor destiConfig = new ConfigAccessor(AdvancedPortalsPlugin.getInstance(), "destinations.yaml");
var config = destiConfig.getConfig();
Set<String> destiSet = config.getKeys(false);
@ -141,7 +141,7 @@ public class UpdatePortalSubCommand implements SubCommand {
}
public int getPortalCount() {
ConfigAccessor portalConfig = new ConfigAccessor(AdvancedPortalsPlugin.getInstance(), "portals.yml");
ConfigAccessor portalConfig = new ConfigAccessor(AdvancedPortalsPlugin.getInstance(), "portals.yaml");
var config = portalConfig.getConfig();
Set<String> portalSet = config.getKeys(false);

View File

@ -21,7 +21,7 @@ public class ConfigAccessor {
this.fileName = fileName;
}
// gets all of the
// gets all of the
public void reloadConfig() {
if (configFile == null) {
File dataFolder = plugin.getDataFolder();
@ -52,7 +52,7 @@ public class ConfigAccessor {
}
}
// Saves
// Saves
/**
* public void saveDefaultConfig() {

View File

@ -18,16 +18,16 @@ 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.posX, location.posY, location.posZ).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.posX, location.posY, location.posZ).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.posX, location.posY, location.posZ);
var block = world.getBlockAt(location.getPosX(), location.getPosY(), location.getPosZ());
var matData = block.getState().getBlockData();
if(matData instanceof Orientable rotatable) {
try {
@ -41,7 +41,7 @@ public class SpigotWorldContainer implements WorldContainer {
@Override
public void setBlockAxis(BlockLocation location, BlockAxis axis) {
var block = world.getBlockAt(location.posX, location.posY, location.posZ);
var block = world.getBlockAt(location.getPosX(), location.getPosY(), location.getPosZ());
var matData = block.getState().getBlockData();
if(matData instanceof Orientable rotatable) {
rotatable.setAxis(Axis.valueOf(axis.toString()));

View File

@ -83,7 +83,7 @@ public class Metrics {
// Get the config file
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
File configFile = new File(bStatsFolder, "config.yml");
File configFile = new File(bStatsFolder, "config.yaml");
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
// Check if the config file exists

View File

@ -1,18 +1,18 @@
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(), loc.getPitch());
}
public static BlockLocation toBlockLocation(Location loc) {
return new BlockLocation(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
}
}
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(), loc.getPitch());
}
public static BlockLocation toBlockLocation(Location loc) {
return new BlockLocation(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
}
}