diff --git a/mcmmo-api/build.gradle.kts b/mcmmo-api/build.gradle.kts index da1493ee4..681865fc7 100644 --- a/mcmmo-api/build.gradle.kts +++ b/mcmmo-api/build.gradle.kts @@ -1,3 +1,8 @@ plugins { `java-library` +} + + +dependencies { + api("org.jetbrains:annotations:17.0.0") } \ No newline at end of file diff --git a/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/data/MMOEntity.java b/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/data/MMOEntity.java new file mode 100644 index 000000000..e9c0169c6 --- /dev/null +++ b/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/data/MMOEntity.java @@ -0,0 +1,4 @@ +package com.gmail.nossr50.mcmmo.api.data; + +public interface MMOEntity { +} diff --git a/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/data/MMOPlayer.java b/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/data/MMOPlayer.java index d86849652..b4e41aad2 100644 --- a/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/data/MMOPlayer.java +++ b/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/data/MMOPlayer.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.mcmmo.api.data; -public interface MMOPlayer { +public interface MMOPlayer extends MMOEntity { N getPlayer(); diff --git a/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/PlatformProvider.java b/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/PlatformProvider.java index 90277c9f6..174b44058 100644 --- a/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/PlatformProvider.java +++ b/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/PlatformProvider.java @@ -1,5 +1,9 @@ package com.gmail.nossr50.mcmmo.api.platform; +import com.gmail.nossr50.mcmmo.api.data.MMOPlayer; +import com.gmail.nossr50.mcmmo.api.platform.util.MetadataStore; + +import java.io.File; import java.util.logging.Logger; public interface PlatformProvider { @@ -7,4 +11,10 @@ public interface PlatformProvider { Logger getLogger(); void tearDown(); + + MetadataStore getMetadataStore(); + + File getDataFolder(); + + void getVersion(); } diff --git a/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/util/MetadataKey.java b/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/util/MetadataKey.java new file mode 100644 index 000000000..be021ebe7 --- /dev/null +++ b/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/util/MetadataKey.java @@ -0,0 +1,17 @@ +package com.gmail.nossr50.mcmmo.api.platform.util; + +import org.jetbrains.annotations.NotNull; + +public class MetadataKey { + + private final String key; + + public MetadataKey(@NotNull String key) { + this.key = key; + } + + @NotNull + public String getKey() { + return key; + } +} diff --git a/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/util/MetadataStore.java b/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/util/MetadataStore.java new file mode 100644 index 000000000..539d70da3 --- /dev/null +++ b/mcmmo-api/src/main/java/com/gmail/nossr50/mcmmo/api/platform/util/MetadataStore.java @@ -0,0 +1,39 @@ +package com.gmail.nossr50.mcmmo.api.platform.util; + +import com.gmail.nossr50.mcmmo.api.data.MMOEntity; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + + +public interface MetadataStore { + + /** + * @param holder holder of the metadata + * @param key key for the metdata + * @param value type + * @return the metadata value or null + */ + @Nullable + V getMetadata(@NotNull MMOEntity holder, @NotNull MetadataKey key); + + /** + * @param holder holder of the metdata + * @param key metadata key + * @param value metadata value + * @param value type + * @return the existing metadata value if set, or null + */ + @Nullable + V setMetadata(@NotNull MMOEntity holder, @NotNull MetadataKey key, @Nullable V value); + + /** + * @param holder holder of the metadata + * @param key metadata key + * @param value type + * @return the removed metadata key + */ + @Nullable + V removeMetadata(@NotNull MMOEntity holder, @NotNull MetadataKey key); + +} diff --git a/mcmmo-bukkit/build.gradle.kts b/mcmmo-bukkit/build.gradle.kts index 938f3c110..04ab4ccd4 100644 --- a/mcmmo-bukkit/build.gradle.kts +++ b/mcmmo-bukkit/build.gradle.kts @@ -33,7 +33,7 @@ dependencies { implementation(project(":mcmmo-core")) api("org.apache.tomcat:tomcat-jdbc:7.0.52") - implementation("org.jetbrains:annotations:17.0.0") + api("net.kyori:event-api:3.0.0") implementation("org.apache.maven.scm:maven-scm-provider-gitexe:1.8.1") implementation("org.bstats:bstats-bukkit:1.4") implementation("org.spigotmc:spigot:1.14.4-R0.1-SNAPSHOT") diff --git a/mcmmo-bukkit/src/main/java/com/gmail/nossr50/mcmmo/bukkit/BukkitBoostrap.java b/mcmmo-bukkit/src/main/java/com/gmail/nossr50/mcmmo/bukkit/BukkitBoostrap.java index afd637fdb..8834ae955 100644 --- a/mcmmo-bukkit/src/main/java/com/gmail/nossr50/mcmmo/bukkit/BukkitBoostrap.java +++ b/mcmmo-bukkit/src/main/java/com/gmail/nossr50/mcmmo/bukkit/BukkitBoostrap.java @@ -2,6 +2,7 @@ package com.gmail.nossr50.mcmmo.bukkit; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcmmo.api.platform.PlatformProvider; +import com.gmail.nossr50.mcmmo.api.platform.util.MetadataStore; import org.bukkit.event.HandlerList; import org.bukkit.plugin.java.JavaPlugin; @@ -25,4 +26,9 @@ public class BukkitBoostrap extends JavaPlugin implements PlatformProvider { core.debug("Unregister all events..."); HandlerList.unregisterAll(this); // Cancel event registrations } + + @Override + public MetadataStore getMetadataStore() { + return null; + } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/MetadataConstants.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/MetadataConstants.java index bc138bc5d..c747747d1 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/core/MetadataConstants.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/MetadataConstants.java @@ -1,5 +1,7 @@ package com.gmail.nossr50.core; +import com.gmail.nossr50.mcmmo.api.platform.util.MetadataKey; + import org.bukkit.metadata.FixedMetadataValue; /** @@ -8,30 +10,28 @@ import org.bukkit.metadata.FixedMetadataValue; public class MetadataConstants { /* Metadata Values */ - public static final String FISH_HOOK_REF_METAKEY = "mcMMO: Fish Hook Tracker"; - public static final String DODGE_TRACKER = "mcMMO: Dodge Tracker"; - public static final String CUSTOM_DAMAGE_METAKEY = "mcMMO: Custom Damage"; - public final static String UNNATURAL_MOB_METAKEY = "mcMMO: Spawned Entity"; - public final static String PISTON_TRACKING_METAKEY = "mcMMO: Piston Tracking"; - public final static String FURNACE_TRACKING_METAKEY = "mcMMO: Tracked Furnace"; - public final static String TNT_TRACKING_METAKEY = "mcMMO: Tracked TNT"; - public final static String SPAWNED_FIREWORKS_METAKEY = "mcMMO: Funfetti"; - public final static String SAFE_TNT_METAKEY = "mcMMO: Safe TNT"; - public final static String CUSTOM_NAME_METAKEY = "mcMMO: Custom Name"; - public final static String NAME_VISIBILITY_METAKEY = "mcMMO: Name Visibility"; - public final static String DROPPED_ITEM_TRACKING_METAKEY = "mcMMO: Tracked Item"; - public final static String INFINITE_ARROW_METAKEY = "mcMMO: Infinite Arrow"; - public final static String BOW_FORCE_METAKEY = "mcMMO: Bow Force"; - public final static String ARROW_DISTANCE_METAKEY = "mcMMO: Arrow Distance"; - public final static String ARROW_TRACKER_METAKEY = "mcMMO: Arrow Tracker"; - public final static String BONUS_DROPS_METAKEY = "mcMMO: Bonus Drops"; - public final static String DISARMED_ITEM_METAKEY = "mcMMO: Disarmed Item"; - public final static String PLAYER_DATA_METAKEY = "mcMMO: Player Data"; - public final static String GREEN_THUMB_METAKEY = "mcMMO: Green Thumb"; - public final static String DATABASE_PROCESSING_COMMAND_METAKEY = "mcMMO: Processing Database Command"; - public final static String PETS_ANIMAL_TRACKING_METAKEY = "mcMMO: Pet Animal"; - public static final String COTW_TEMPORARY_SUMMON = "mcMMO: COTW Entity"; - - public static FixedMetadataValue metadataValue; //Gains value in onEnable + public static final MetadataKey FISH_HOOK_REF_METAKEY = new MetadataKey<>("mcMMO: Fish Hook Tracker"); + public static final MetadataKey DODGE_TRACKER = new MetadataKey<>("mcMMO: Dodge Tracker"); + public static final MetadataKey CUSTOM_DAMAGE_METAKEY = new MetadataKey<>("mcMMO: Custom Damage"); + public final static MetadataKey UNNATURAL_MOB_METAKEY = new MetadataKey<>("mcMMO: Spawned Entity"); + public final static MetadataKey PISTON_TRACKING_METAKEY = new MetadataKey<>("mcMMO: Piston Tracking"); + public final static MetadataKey FURNACE_TRACKING_METAKEY = new MetadataKey<>("mcMMO: Tracked Furnace"); + public final static MetadataKey TNT_TRACKING_METAKEY = new MetadataKey<>("mcMMO: Tracked TNT"); + public final static MetadataKey SPAWNED_FIREWORKS_METAKEY = new MetadataKey<>("mcMMO: Funfetti"); + public final static MetadataKey SAFE_TNT_METAKEY = new MetadataKey<>("mcMMO: Safe TNT"); + public final static MetadataKey CUSTOM_NAME_METAKEY = new MetadataKey<>("mcMMO: Custom Name"); + public final static MetadataKey NAME_VISIBILITY_METAKEY = new MetadataKey<>("mcMMO: Name Visibility"); + public final static MetadataKey DROPPED_ITEM_TRACKING_METAKEY = new MetadataKey<>("mcMMO: Tracked Item"); + public final static MetadataKey INFINITE_ARROW_METAKEY = new MetadataKey<>("mcMMO: Infinite Arrow"); + public final static MetadataKey BOW_FORCE_METAKEY = new MetadataKey<>("mcMMO: Bow Force"); + public final static MetadataKey ARROW_DISTANCE_METAKEY = new MetadataKey<>("mcMMO: Arrow Distance"); + public final static MetadataKey ARROW_TRACKER_METAKEY = new MetadataKey<>("mcMMO: Arrow Tracker"); + public final static MetadataKey BONUS_DROPS_METAKEY = new MetadataKey<>("mcMMO: Bonus Drops"); + public final static MetadataKey DISARMED_ITEM_METAKEY = new MetadataKey<>("mcMMO: Disarmed Item"); + public final static MetadataKey PLAYER_DATA_METAKEY = new MetadataKey<>("mcMMO: Player Data"); + public final static MetadataKey GREEN_THUMB_METAKEY = new MetadataKey<>("mcMMO: Green Thumb"); + public final static MetadataKey DATABASE_PROCESSING_COMMAND_METAKEY = new MetadataKey<>("mcMMO: Processing Database Command"); + public final static MetadataKey PETS_ANIMAL_TRACKING_METAKEY = new MetadataKey<>("mcMMO: Pet Animal"); + public static final MetadataKey COTW_TEMPORARY_SUMMON = new MetadataKey<>("mcMMO: COTW Entity"); } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java b/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java index 194cfb2fe..aa89dac9b 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/mcMMO.java @@ -139,9 +139,6 @@ public class mcMMO implements McMMOApi { try { platformProvider.getLogger().setFilter(new LogFilter(this)); - //TODO: Disgusting... - MetadataConstants.metadataValue = new FixedMetadataValue(this, true); - PluginManager pluginManager = platformProvider.getServer().getPluginManager(); healthBarPluginEnabled = pluginManager.getPlugin("HealthBar") != null; @@ -214,7 +211,7 @@ public class mcMMO implements McMMOApi { new PlayerProfileLoadingTask(this, player).runTaskLaterAsynchronously(this, 1); // 1 Tick delay to ensure the player is marked as online before we begin loading } - debug("Version " + getDescription().getVersion() + " is enabled!"); + debug("Version " + getVersion() + " is enabled!"); scheduleTasks(); commandRegistrationManager = new CommandRegistrationManager(this); @@ -307,6 +304,10 @@ public class mcMMO implements McMMOApi { perkUtils = new PerkUtils(this); } + private String getVersion() { + platformProvider.getVersion(); + } + public void onLoad() { if(getServer().getPluginManager().getPlugin("WorldGuard") != null) { @@ -579,7 +580,7 @@ public class mcMMO implements McMMOApi { * Setup the various storage file paths */ private void setupFilePaths() { - mainDirectory = getDataFolder().getPath() + File.separator; + mainDirectory = platformProvider.getDataFolder().getPath() + File.separator; localesDirectory = mainDirectory + "locales" + File.separator; flatFileDirectory = mainDirectory + "flatfile" + File.separator; usersFile = flatFileDirectory + "mcmmo.users";