Skip to content

Commit

Permalink
feat: switch files over to using yaml (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Nov 18, 2024
1 parent 8afbae5 commit 5f44e24
Show file tree
Hide file tree
Showing 31 changed files with 497 additions and 256 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
2 changes: 2 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand Down Expand Up @@ -67,18 +68,22 @@ 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;
this.dataStorage = new DataStorage(dataStorageLoc);
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};
}
Expand Down Expand Up @@ -110,7 +115,7 @@ public void onEnable() {

this.portalServices.loadPortals();
this.destinationServices.loadDestinations();
this.infoLogger.log(Lang.translate("logger.pluginenable"));
this.infoLogger.info(Lang.translate("logger.pluginenable"));
}

private void registerTags() {
Expand Down Expand Up @@ -172,14 +177,14 @@ public boolean registerDestiCommand(String arg, SubCommand subCommand, String...
*/
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public void onCommand(CommandSenderContainer sender, String[] args) {

// 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,36 +105,39 @@ public void registered() {
}


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);
}
}
}
}
Expand All @@ -150,13 +153,13 @@ private void debugVisuals(PlayerContainer player, AdvancedPortal portal, Color c
}

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();

Expand All @@ -171,7 +174,7 @@ private void debugVisuals(PlayerContainer player, BlockLocation pos1, BlockLocat
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) {
Expand All @@ -188,23 +191,23 @@ private void debugVisuals(PlayerContainer player, BlockLocation pos1, BlockLocat
} 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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,7 +19,7 @@
* 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
*/
Expand All @@ -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;
}
Expand Down
Loading

0 comments on commit 5f44e24

Please sign in to comment.