diff --git a/Changelog.txt b/Changelog.txt index e79cd9cc2..8845f00c7 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -8,6 +8,7 @@ Key: - Removal Version 2.2.0 + mcMMO is now abstracted from the Bukkit API in order to support more platforms (WIP) Salvage config entries are no longer case sensitive mcMMO has changed from using maven to gradle! mcMMO is now a gradle project (this makes it much easier for us to support older versions of MC and other APIs) diff --git a/core/src/main/java/com/gmail/nossr50/core/McmmoCore.java b/core/src/main/java/com/gmail/nossr50/core/McmmoCore.java index f2b27a659..2c76fad73 100644 --- a/core/src/main/java/com/gmail/nossr50/core/McmmoCore.java +++ b/core/src/main/java/com/gmail/nossr50/core/McmmoCore.java @@ -1,5 +1,7 @@ package com.gmail.nossr50.core; -public class McmmoCore { +import com.gmail.nossr50.core.mcmmo.plugin.Plugin; +public class McmmoCore { + public static Plugin p; } diff --git a/core/src/main/java/com/gmail/nossr50/core/api/ExperienceAPI.java b/core/src/main/java/com/gmail/nossr50/core/api/ExperienceAPI.java index 61617ca00..17aab077e 100644 --- a/core/src/main/java/com/gmail/nossr50/core/api/ExperienceAPI.java +++ b/core/src/main/java/com/gmail/nossr50/core/api/ExperienceAPI.java @@ -1,8 +1,8 @@ package com.gmail.nossr50.core.api; import com.gmail.nossr50.core.api.exceptions.*; -import com.gmail.nossr50.core.config.experience.ExperienceConfig; import com.gmail.nossr50.core.config.Config; +import com.gmail.nossr50.core.config.experience.ExperienceConfig; import com.gmail.nossr50.core.data.UserManager; import com.gmail.nossr50.core.datatypes.experience.FormulaType; import com.gmail.nossr50.core.datatypes.experience.XPGainReason; diff --git a/core/src/main/java/com/gmail/nossr50/core/datatypes/player/McMMOPlayer.java b/core/src/main/java/com/gmail/nossr50/core/datatypes/player/McMMOPlayer.java index e516ba1e9..222db87a7 100644 --- a/core/src/main/java/com/gmail/nossr50/core/datatypes/player/McMMOPlayer.java +++ b/core/src/main/java/com/gmail/nossr50/core/datatypes/player/McMMOPlayer.java @@ -1,9 +1,10 @@ package com.gmail.nossr50.core.datatypes.player; -import com.gmail.nossr50.config.experience.ExperienceConfig; +import com.gmail.nossr50.core.McmmoCore; import com.gmail.nossr50.core.config.AdvancedConfig; import com.gmail.nossr50.core.config.Config; import com.gmail.nossr50.core.config.WorldBlacklist; +import com.gmail.nossr50.core.config.experience.ExperienceConfig; import com.gmail.nossr50.core.data.UserManager; import com.gmail.nossr50.core.datatypes.chat.ChatMode; import com.gmail.nossr50.core.datatypes.experience.XPGainReason; @@ -12,52 +13,48 @@ import com.gmail.nossr50.core.datatypes.interactions.NotificationType; import com.gmail.nossr50.core.datatypes.mods.CustomTool; import com.gmail.nossr50.core.datatypes.party.Party; import com.gmail.nossr50.core.datatypes.party.PartyTeleportRecord; +import com.gmail.nossr50.core.locale.LocaleLoader; +import com.gmail.nossr50.core.mcmmo.entity.Player; +import com.gmail.nossr50.core.mcmmo.meta.Metadata; +import com.gmail.nossr50.core.mcmmo.meta.MetadataDefinitions; +import com.gmail.nossr50.core.mcmmo.world.Location; +import com.gmail.nossr50.core.party.PartyManager; +import com.gmail.nossr50.core.party.ShareHandler; +import com.gmail.nossr50.core.runnables.skills.AbilityDisableTask; +import com.gmail.nossr50.core.runnables.skills.BleedTimerTask; +import com.gmail.nossr50.core.runnables.skills.ToolLowerTask; import com.gmail.nossr50.core.skills.PrimarySkillType; +import com.gmail.nossr50.core.skills.SkillManager; import com.gmail.nossr50.core.skills.SuperAbilityType; import com.gmail.nossr50.core.skills.ToolType; -import com.gmail.nossr50.locale.LocaleLoader; -import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.party.PartyManager; -import com.gmail.nossr50.party.ShareHandler; -import com.gmail.nossr50.runnables.skills.AbilityDisableTask; -import com.gmail.nossr50.runnables.skills.BleedTimerTask; -import com.gmail.nossr50.runnables.skills.ToolLowerTask; -import com.gmail.nossr50.skills.SkillManager; -import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager; -import com.gmail.nossr50.skills.alchemy.AlchemyManager; -import com.gmail.nossr50.skills.archery.ArcheryManager; -import com.gmail.nossr50.skills.axes.AxesManager; -import com.gmail.nossr50.skills.child.FamilyTree; -import com.gmail.nossr50.skills.excavation.ExcavationManager; -import com.gmail.nossr50.skills.fishing.FishingManager; -import com.gmail.nossr50.skills.herbalism.HerbalismManager; -import com.gmail.nossr50.skills.mining.MiningManager; -import com.gmail.nossr50.skills.repair.RepairManager; -import com.gmail.nossr50.skills.salvage.SalvageManager; -import com.gmail.nossr50.skills.smelting.SmeltingManager; -import com.gmail.nossr50.skills.swords.SwordsManager; -import com.gmail.nossr50.skills.taming.TamingManager; -import com.gmail.nossr50.skills.unarmed.UnarmedManager; -import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager; -import com.gmail.nossr50.util.EventUtils; -import com.gmail.nossr50.util.Misc; -import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.experience.ExperienceBarManager; -import com.gmail.nossr50.util.player.NotificationManager; -import com.gmail.nossr50.util.scoreboards.ScoreboardManager; -import com.gmail.nossr50.util.skills.ParticleEffectUtils; -import com.gmail.nossr50.util.skills.PerksUtils; -import com.gmail.nossr50.util.skills.RankUtils; -import com.gmail.nossr50.util.skills.SkillUtils; -import com.gmail.nossr50.util.sounds.SoundManager; -import com.gmail.nossr50.util.sounds.SoundType; -import org.apache.commons.lang.Validate; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.metadata.FixedMetadataValue; -import org.bukkit.plugin.Plugin; +import com.gmail.nossr50.core.skills.child.FamilyTree; +import com.gmail.nossr50.core.skills.child.salvage.SalvageManager; +import com.gmail.nossr50.core.skills.child.smelting.SmeltingManager; +import com.gmail.nossr50.core.skills.primary.acrobatics.AcrobaticsManager; +import com.gmail.nossr50.core.skills.primary.alchemy.AlchemyManager; +import com.gmail.nossr50.core.skills.primary.archery.ArcheryManager; +import com.gmail.nossr50.core.skills.primary.axes.AxesManager; +import com.gmail.nossr50.core.skills.primary.excavation.ExcavationManager; +import com.gmail.nossr50.core.skills.primary.fishing.FishingManager; +import com.gmail.nossr50.core.skills.primary.herbalism.HerbalismManager; +import com.gmail.nossr50.core.skills.primary.mining.MiningManager; +import com.gmail.nossr50.core.skills.primary.repair.RepairManager; +import com.gmail.nossr50.core.skills.primary.swords.SwordsManager; +import com.gmail.nossr50.core.skills.primary.taming.TamingManager; +import com.gmail.nossr50.core.skills.primary.unarmed.UnarmedManager; +import com.gmail.nossr50.core.skills.primary.woodcutting.WoodcuttingManager; +import com.gmail.nossr50.core.util.EventUtils; +import com.gmail.nossr50.core.util.Misc; +import com.gmail.nossr50.core.util.Permissions; +import com.gmail.nossr50.core.util.experience.ExperienceBarManager; +import com.gmail.nossr50.core.util.player.NotificationManager; +import com.gmail.nossr50.core.util.scoreboards.ScoreboardManager; +import com.gmail.nossr50.core.util.skills.ParticleEffectUtils; +import com.gmail.nossr50.core.util.skills.PerksUtils; +import com.gmail.nossr50.core.util.skills.RankUtils; +import com.gmail.nossr50.core.util.skills.SkillUtils; +import com.gmail.nossr50.core.util.sounds.SoundManager; +import com.gmail.nossr50.core.util.sounds.SoundType; import java.util.HashMap; import java.util.Map; @@ -69,7 +66,7 @@ public class McMMOPlayer { private final Map abilityMode = new HashMap(); private final Map abilityInformed = new HashMap(); private final Map toolMode = new HashMap(); - private final FixedMetadataValue playerMetadata; + private final Metadata playerMetadata; private Player player; private PlayerProfile profile; private ExperienceBarManager experienceBarManager; @@ -94,10 +91,10 @@ public class McMMOPlayer { public McMMOPlayer(Player player, PlayerProfile profile) { String playerName = player.getName(); - UUID uuid = player.getUniqueId(); + UUID uuid = player.getUUID(); this.player = player; - playerMetadata = new FixedMetadataValue(mcMMO.p, playerName); + playerMetadata = player.setMetadata(MetadataDefinitions.MCMMO_METADATA_PLAYERDATA_KEY, playerName); //new FixedMetadataValue(mcMMO.p, playerName); this.profile = profile; if (profile.getUniqueId() == null) { @@ -115,7 +112,8 @@ public class McMMOPlayer { } } catch (Exception e) { e.printStackTrace(); - mcMMO.p.getPluginLoader().disablePlugin(mcMMO.p); + McmmoCore.p.disablePlugin(); //Disable Plugin + //mcMMO.p.getPluginLoader().disablePlugin(mcMMO.p); } for (SuperAbilityType superAbilityType : SuperAbilityType.values()) { diff --git a/core/src/main/java/com/gmail/nossr50/core/mcmmo/Nameable.java b/core/src/main/java/com/gmail/nossr50/core/mcmmo/Nameable.java index 435acbfbd..a69a5ca45 100644 --- a/core/src/main/java/com/gmail/nossr50/core/mcmmo/Nameable.java +++ b/core/src/main/java/com/gmail/nossr50/core/mcmmo/Nameable.java @@ -1,7 +1,5 @@ package com.gmail.nossr50.core.mcmmo; -import com.gmail.nossr50.core.mcmmo.Named; - public interface Nameable extends Named { /** * Change the name for this entity diff --git a/core/src/main/java/com/gmail/nossr50/core/mcmmo/entity/Entity.java b/core/src/main/java/com/gmail/nossr50/core/mcmmo/entity/Entity.java index 60921d830..b92430411 100644 --- a/core/src/main/java/com/gmail/nossr50/core/mcmmo/entity/Entity.java +++ b/core/src/main/java/com/gmail/nossr50/core/mcmmo/entity/Entity.java @@ -1,9 +1,9 @@ package com.gmail.nossr50.core.mcmmo.entity; -import com.gmail.nossr50.core.mcmmo.world.Location; import com.gmail.nossr50.core.mcmmo.Named; import com.gmail.nossr50.core.mcmmo.Unique; import com.gmail.nossr50.core.mcmmo.meta.MetadataHolder; +import com.gmail.nossr50.core.mcmmo.world.Location; /** * Entities can be a lot of things in MC diff --git a/core/src/main/java/com/gmail/nossr50/core/mcmmo/meta/MetadataDefinitions.java b/core/src/main/java/com/gmail/nossr50/core/mcmmo/meta/MetadataDefinitions.java new file mode 100644 index 000000000..1ac325724 --- /dev/null +++ b/core/src/main/java/com/gmail/nossr50/core/mcmmo/meta/MetadataDefinitions.java @@ -0,0 +1,5 @@ +package com.gmail.nossr50.core.mcmmo.meta; + +public class MetadataDefinitions { + public static final String MCMMO_METADATA_PLAYERDATA_KEY = "mcMMO_PlayerDataKey"; +} diff --git a/core/src/main/java/com/gmail/nossr50/core/mcmmo/meta/MetadataHolder.java b/core/src/main/java/com/gmail/nossr50/core/mcmmo/meta/MetadataHolder.java index ce2c7e646..129b11349 100644 --- a/core/src/main/java/com/gmail/nossr50/core/mcmmo/meta/MetadataHolder.java +++ b/core/src/main/java/com/gmail/nossr50/core/mcmmo/meta/MetadataHolder.java @@ -15,6 +15,15 @@ public interface MetadataHolder { /** * Sets the metadata, will replace metadata with an existing key or add metadata if there was none * @param metadata metadata to add + * @return a copy of the metadata */ - void setMetadata(Metadata metadata); + Metadata setMetadata(Metadata metadata); + + /** + * Sets the metadata, will replace metadata with a matching key or add metadata if there was none + * @param key metadata key + * @param value metadata value + * @return a copy of the metadata + */ + Metadata setMetadata(String key, Object value); } diff --git a/core/src/main/java/com/gmail/nossr50/core/mcmmo/plugin/Plugin.java b/core/src/main/java/com/gmail/nossr50/core/mcmmo/plugin/Plugin.java new file mode 100644 index 000000000..d719c9bc1 --- /dev/null +++ b/core/src/main/java/com/gmail/nossr50/core/mcmmo/plugin/Plugin.java @@ -0,0 +1,13 @@ +package com.gmail.nossr50.core.mcmmo.plugin; + +/** + * Represents mcMMO as it is seen by various APIs + * In Bukkit, its useful to have a Plugin reference to schedule tasks etc, that is why this abstraction exists + * I'm actually not sure I need this though + */ +public interface Plugin { + /** + * In the event of some critical failure in mcMMO shut down the plugin + */ + void disablePlugin(); +} diff --git a/core/src/main/java/com/gmail/nossr50/core/mcmmo/tasks/ASyncTask.java b/core/src/main/java/com/gmail/nossr50/core/mcmmo/tasks/ASyncTask.java new file mode 100644 index 000000000..63ffb4c22 --- /dev/null +++ b/core/src/main/java/com/gmail/nossr50/core/mcmmo/tasks/ASyncTask.java @@ -0,0 +1,8 @@ +package com.gmail.nossr50.core.mcmmo.tasks; + +/** + * An ASync Task + * You have to be careful where you use these, a lot of things are not thread safe + */ +public interface ASyncTask extends PluginTask { +} diff --git a/core/src/main/java/com/gmail/nossr50/core/mcmmo/tasks/PluginTask.java b/core/src/main/java/com/gmail/nossr50/core/mcmmo/tasks/PluginTask.java new file mode 100644 index 000000000..444f03d33 --- /dev/null +++ b/core/src/main/java/com/gmail/nossr50/core/mcmmo/tasks/PluginTask.java @@ -0,0 +1,23 @@ +package com.gmail.nossr50.core.mcmmo.tasks; + +/** + * Represents a schedules task + * Bukkit and Sponge both have systems for this + */ +public interface PluginTask { + /** + * Kills the current task + */ + void killTask(); + + /** + * Schedule a delayed task in n ticks + * @param ticks ticks until the task should start + */ + void scheduleTask(int ticks); + + /** + * Schedule this task (begins ASAP) + */ + void scheduleTask(); +} diff --git a/core/src/main/java/com/gmail/nossr50/core/mcmmo/tasks/SyncTask.java b/core/src/main/java/com/gmail/nossr50/core/mcmmo/tasks/SyncTask.java new file mode 100644 index 000000000..495a7f3b2 --- /dev/null +++ b/core/src/main/java/com/gmail/nossr50/core/mcmmo/tasks/SyncTask.java @@ -0,0 +1,9 @@ +package com.gmail.nossr50.core.mcmmo.tasks; + +/** + * Represents a SyncTask + * SyncTasks run on the main thread + */ +public interface SyncTask extends PluginTask { + +} diff --git a/core/src/main/java/com/gmail/nossr50/core/mcmmo/world/Location.java b/core/src/main/java/com/gmail/nossr50/core/mcmmo/world/Location.java index 2ee1343f2..a16305f6f 100644 --- a/core/src/main/java/com/gmail/nossr50/core/mcmmo/world/Location.java +++ b/core/src/main/java/com/gmail/nossr50/core/mcmmo/world/Location.java @@ -1,7 +1,6 @@ package com.gmail.nossr50.core.mcmmo.world; import com.flowpowered.math.vector.Vector3d; -import com.gmail.nossr50.core.mcmmo.world.World; /** * This class represents a Location in MC