Skip to content

Commit

Permalink
Should add TranslatableArea
Browse files Browse the repository at this point in the history
  • Loading branch information
anjoismysign committed Aug 11, 2024
1 parent 032c887 commit b762e1c
Show file tree
Hide file tree
Showing 19 changed files with 525 additions and 289 deletions.
30 changes: 25 additions & 5 deletions src/main/java/us/mytheria/bloblib/BlobLib.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package us.mytheria.bloblib;

import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import us.mytheria.bloblib.command.BlobLibCmd;
import us.mytheria.bloblib.disguises.DisguiseManager;
import us.mytheria.bloblib.enginehub.EngineHubManager;
import us.mytheria.bloblib.entities.DataAssetType;
import us.mytheria.bloblib.entities.area.WorldGuardArea;
import us.mytheria.bloblib.entities.logger.BlobPluginLogger;
import us.mytheria.bloblib.entities.positionable.Positionable;
import us.mytheria.bloblib.entities.positionable.PositionableReader;
import us.mytheria.bloblib.entities.tag.TagSet;
import us.mytheria.bloblib.entities.tag.TagSetReader;
import us.mytheria.bloblib.entities.translatable.BlobTranslatablePositionable;
import us.mytheria.bloblib.entities.translatable.TranslatableItem;
import us.mytheria.bloblib.entities.translatable.TranslatablePositionable;
import us.mytheria.bloblib.entities.translatable.TranslatableReader;
import us.mytheria.bloblib.entities.translatable.*;
import us.mytheria.bloblib.exception.ConfigurationFieldException;
import us.mytheria.bloblib.hologram.HologramManager;
import us.mytheria.bloblib.managers.*;
Expand Down Expand Up @@ -59,6 +59,7 @@ public class BlobLib extends JavaPlugin {

private LocalizableDataAssetManager<TranslatableItem> translatableItemManager;
private LocalizableDataAssetManager<TranslatablePositionable> translatablePositionableManager;
private LocalizableDataAssetManager<TranslatableArea> translatableAreaManager;
private DataAssetManager<TagSet> tagSetManager;

private MinecraftVersion running;
Expand Down Expand Up @@ -103,6 +104,7 @@ public void onEnable() {
colorManager = new ColorManager();
fileManager = new BlobLibFileManager();
fileManager.unpackYamlFile("/BlobInventory", "CurrencyBuilder", false);
engineHubManager = EngineHubManager.getInstance();

inventoryManager = new InventoryManager();
inventoryTrackerManager = new InventoryTrackerManager();
Expand All @@ -128,12 +130,26 @@ public void onEnable() {
},
DataAssetType.TRANSLATABLE_POSITIONABLE,
section -> section.isDouble("X") && section.isDouble("Y") && section.isDouble("Z"));
translatableAreaManager = LocalizableDataAssetManager
.of(fileManager.getDirectory(DataAssetType.TRANSLATABLE_AREA),
(section, locale, key) -> {
if (!engineHubManager.isWorldGuardInstalled()) {
getLogger().severe("WorldGuard is not installed, failed to load Area: " + key);
return null;
}
String worldName = section.getString("World");
@NotNull World world = SerializationLib.deserializeWorld(worldName);
String id = section.getString("Id");
String display = section.getString("Display");
return BlobTranslatableArea.of(key, locale, display, WorldGuardArea.of(world, id));
},
DataAssetType.TRANSLATABLE_AREA,
section -> section.isString("World") && section.isString("Id"));
messageManager = new MessageManager();
actionManager = new ActionManager();
soundManager = new SoundManager();
fillerManager = new FillerManager();
vaultManager = new VaultManager();
engineHubManager = new EngineHubManager();
disguiseManager = new DisguiseManager();
hologramManager = new HologramManager();
chatManager = new ChatListenerManager();
Expand Down Expand Up @@ -244,6 +260,10 @@ public LocalizableDataAssetManager<TranslatablePositionable> getTranslatablePosi
return translatablePositionableManager;
}

public LocalizableDataAssetManager<TranslatableArea> getTranslatableAreaManager() {
return translatableAreaManager;
}

public DataAssetManager<TagSet> getTagSetManager() {
return tagSetManager;
}
Expand Down
56 changes: 51 additions & 5 deletions src/main/java/us/mytheria/bloblib/api/BlobLibTranslatableAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import us.mytheria.bloblib.BlobLib;
import us.mytheria.bloblib.entities.translatable.TranslatableBlock;
import us.mytheria.bloblib.entities.translatable.TranslatableItem;
import us.mytheria.bloblib.entities.translatable.TranslatablePositionable;
import us.mytheria.bloblib.entities.translatable.TranslatableSnippet;
import us.mytheria.bloblib.entities.translatable.*;
import us.mytheria.bloblib.managers.BlobLibConfigManager;
import us.mytheria.bloblib.managers.TranslatableManager;

Expand Down Expand Up @@ -198,7 +195,7 @@ public TranslatablePositionable getTranslatablePositionable(@NotNull String key)
*
* @param key The key of the translatable
* @param player The player to get the locale from
* @return The TranslatableItem
* @return The TranslatablePositionable
*/
@Nullable
public TranslatablePositionable getTranslatablePositionable(@NotNull String key,
Expand All @@ -218,6 +215,55 @@ public List<TranslatablePositionable> getTranslatablePositionables(@NotNull Stri
return plugin.getTranslatablePositionableManager().getAssets(locale);
}

/**
* Will get a TranslatableArea by its key and locale.
*
* @param key The key of the translatable
* @param locale The locale of the translatable
* @return The TranslatableArea
*/
@Nullable
public TranslatableArea getTranslatableArea(@NotNull String key,
@NotNull String locale) {
return plugin.getTranslatableAreaManager().getAsset(key, locale);
}

/**
* Will get a TranslatableArea by its key and the default locale.
*
* @param key The key of the translatable
* @return The TranslatableArea
*/
@Nullable
public TranslatableArea getTranslatableArea(@NotNull String key) {
return plugin.getTranslatableAreaManager().getAsset(key);
}

/**
* Will get a TranslatableArea by its key and the player's locale.
*
* @param key The key of the translatable
* @param player The player to get the locale from
* @return The TranslatableArea
*/
@Nullable
public TranslatableArea getTranslatableArea(@NotNull String key,
@NotNull Player player) {
Objects.requireNonNull(player);
return plugin.getTranslatableAreaManager().getAsset(key, player.getLocale());
}

/**
* Get all the TranslatableAreas by their key.
*
* @param locale The locale for the TranslatableAreas
* @return The list of TranslatableArea
*/
@NotNull
public List<TranslatableArea> getTranslatableAreas(@NotNull String locale) {
return plugin.getTranslatableAreaManager().getAssets(locale);
}

/**
* Will get the real locale from the locale.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public DisguiseManager() {
* Should not be run by plugins, only by BlobLib
*/
public void load() {
if (loaded)
return;
if (Bukkit.getPluginManager().getPlugin("LibsDisguises") != null) {
updateDisguiser(new LibsDisguises());
} else {
Expand All @@ -25,7 +27,7 @@ public void load() {
private void updateDisguiser(Disguiser disguiser) {
this.disguiser = disguiser;
}

public Disguiser getDisguiser() {
if (!loaded)
throw new IllegalStateException("DisguiseManager loads after world load!");
Expand Down
70 changes: 0 additions & 70 deletions src/main/java/us/mytheria/bloblib/enginehub/EngineHubAPI.java

This file was deleted.

12 changes: 10 additions & 2 deletions src/main/java/us/mytheria/bloblib/enginehub/EngineHubManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ public class EngineHubManager {
private final WorldGuardWorker worldGuard;
private boolean worldGuardInstalled = false;

public EngineHubManager() {
private static EngineHubManager instance;

public static EngineHubManager getInstance() {
if (instance == null)
instance = new EngineHubManager();
return instance;
}

private EngineHubManager() {
if (Bukkit.getPluginManager().getPlugin("WorldEdit") == null) {
Bukkit.getLogger().info("[BlobLib] WorldEdit not found, disabling its features.");
worldEdit = new Absent();
Expand All @@ -24,7 +32,7 @@ public EngineHubManager() {
Bukkit.getLogger().info("[BlobLib] WorldGuard not found, disabling its features.");
worldGuard = new us.mytheria.bloblib.enginehub.worldguard.Absent();
} else {
worldGuard = new us.mytheria.bloblib.enginehub.worldguard.Found();
worldGuard = new us.mytheria.bloblib.enginehub.worldguard.Found(worldEdit);
worldGuardInstalled = true;
}
}
Expand Down
20 changes: 7 additions & 13 deletions src/main/java/us/mytheria/bloblib/enginehub/worldedit/Absent.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package us.mytheria.bloblib.enginehub.worldedit;

import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import org.bukkit.Location;
import org.bukkit.World;

Expand All @@ -20,7 +14,7 @@ public class Absent implements WorldEditWorker {
* @return null
*/
@Override
public EditSession editSession(World world) {
public Object editSession(World world) {
return null;
}

Expand All @@ -31,7 +25,7 @@ public EditSession editSession(World world) {
* @return null
*/
@Override
public com.sk89q.worldedit.world.World world(World world) {
public Object world(World world) {
return null;
}

Expand All @@ -42,7 +36,7 @@ public com.sk89q.worldedit.world.World world(World world) {
* @return null
*/
@Override
public Pattern parse(String string) {
public Object pattern(String string) {
return null;
}

Expand All @@ -55,7 +49,7 @@ public Pattern parse(String string) {
* @return true
*/
@Override
public boolean setBlocks(EditSession session, Region region, Pattern pattern) {
public boolean setBlocks(Object session, Object region, Object pattern) {
return true;
}

Expand All @@ -67,7 +61,7 @@ public boolean setBlocks(EditSession session, Region region, Pattern pattern) {
* @return null
*/
@Override
public CuboidRegion cuboidRegion(Location min, Location max) {
public Object cuboidRegion(Location min, Location max) {
return null;
}

Expand All @@ -78,7 +72,7 @@ public CuboidRegion cuboidRegion(Location min, Location max) {
* @return null
*/
@Override
public BlockVector3 blockVector3(Location location) {
public Object blockVector3(Location location) {
return null;
}

Expand All @@ -89,7 +83,7 @@ public BlockVector3 blockVector3(Location location) {
* @return null
*/
@Override
public BlockVector2 blockVector2(Location location) {
public Object blockVector2(Location location) {
return null;
}
}
10 changes: 8 additions & 2 deletions src/main/java/us/mytheria/bloblib/enginehub/worldedit/Found.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public com.sk89q.worldedit.world.World world(World world) {
}

@Override
public Pattern parse(String string) {
public Pattern pattern(String string) {
PatternFactory factory = com.sk89q.worldedit.WorldEdit.getInstance().getPatternFactory();
try {
ParserContext context = new ParserContext();
Expand All @@ -42,7 +42,13 @@ public Pattern parse(String string) {
}

@Override
public boolean setBlocks(EditSession session, Region region, Pattern pattern) {
public boolean setBlocks(Object sessionObject, Object regionObject, Object patternObject) {
if (!(sessionObject instanceof EditSession session))
return false;
if (!(regionObject instanceof Region region))
return false;
if (!(patternObject instanceof Pattern pattern))
return false;
try {
session.setBlocks(region, pattern);
Operation operation = session.commit();
Expand Down
Loading

0 comments on commit b762e1c

Please sign in to comment.