Browse Source

Fleshing out the abstraction

nossr50 6 years ago
parent
commit
1ab4645223

+ 3 - 0
core/build.gradle.kts

@@ -5,8 +5,11 @@ plugins {
 repositories {
 repositories {
     // Repo containing the Configurable library
     // Repo containing the Configurable library
     maven("https://repo.spongepowered.org/maven")
     maven("https://repo.spongepowered.org/maven")
+    // Flow Math
+    maven("https://oss.sonatype.org/content/groups/public/")
 }
 }
 
 
 dependencies {
 dependencies {
+    compile("com.flowpowered", "flow-math", "1.0.4-SNAPSHOT")
     compile("org.spongepowered", "configurate-yaml", "3.6") // Configurable (config library from Sponge)
     compile("org.spongepowered", "configurate-yaml", "3.6") // Configurable (config library from Sponge)
 }
 }

+ 1 - 1
core/src/main/java/com/gmail/nossr50/core/data/blockmeta/chunkmeta/PrimitiveChunkStore.java

@@ -1,7 +1,7 @@
 package com.gmail.nossr50.core.data.blockmeta.chunkmeta;
 package com.gmail.nossr50.core.data.blockmeta.chunkmeta;
 
 
 import com.gmail.nossr50.core.data.blockmeta.ChunkletStore;
 import com.gmail.nossr50.core.data.blockmeta.ChunkletStore;
-import com.gmail.nossr50.core.mcmmo.World;
+import com.gmail.nossr50.core.mcmmo.world.World;
 
 
 import java.io.IOException;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectInputStream;

+ 1 - 1
core/src/main/java/com/gmail/nossr50/core/datatypes/LimitedSizeList.java

@@ -1,6 +1,6 @@
 package com.gmail.nossr50.core.datatypes;
 package com.gmail.nossr50.core.datatypes;
 
 
-import com.gmail.nossr50.core.mcmmo.Location;
+import com.gmail.nossr50.core.mcmmo.world.Location;
 
 
 public class LimitedSizeList {
 public class LimitedSizeList {
     private final int size;
     private final int size;

+ 2 - 0
core/src/main/java/com/gmail/nossr50/core/mcmmo/Nameable.java

@@ -1,5 +1,7 @@
 package com.gmail.nossr50.core.mcmmo;
 package com.gmail.nossr50.core.mcmmo;
 
 
+import com.gmail.nossr50.core.mcmmo.Named;
+
 public interface Nameable extends Named {
 public interface Nameable extends Named {
     /**
     /**
      * Change the name for this entity
      * Change the name for this entity

+ 11 - 0
core/src/main/java/com/gmail/nossr50/core/mcmmo/Unique.java

@@ -0,0 +1,11 @@
+package com.gmail.nossr50.core.mcmmo;
+
+import java.util.UUID;
+
+/**
+ * Many things in MC use UUID to be uniquely identified
+ *
+ */
+public interface Unique {
+    UUID getUUID();
+}

+ 0 - 10
core/src/main/java/com/gmail/nossr50/core/mcmmo/World.java

@@ -1,10 +0,0 @@
-package com.gmail.nossr50.core.mcmmo;
-
-public interface World {
-    /**
-     * Gets the name of this World
-     *
-     * @return the name of this world
-     */
-    String getName();
-}

+ 0 - 2
core/src/main/java/com/gmail/nossr50/core/mcmmo/block/Block.java

@@ -1,7 +1,5 @@
 package com.gmail.nossr50.core.mcmmo.block;
 package com.gmail.nossr50.core.mcmmo.block;
 
 
-import com.gmail.nossr50.core.mcmmo.Property;
-
 /**
 /**
  * Represents a container of properties and values for a Block
  * Represents a container of properties and values for a Block
  *
  *

+ 0 - 1
core/src/main/java/com/gmail/nossr50/core/mcmmo/block/BlockState.java

@@ -1,6 +1,5 @@
 package com.gmail.nossr50.core.mcmmo.block;
 package com.gmail.nossr50.core.mcmmo.block;
 
 
-import com.gmail.nossr50.core.mcmmo.Property;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMap;
 
 
 import java.util.Collection;
 import java.util.Collection;

+ 1 - 1
core/src/main/java/com/gmail/nossr50/core/mcmmo/Property.java → core/src/main/java/com/gmail/nossr50/core/mcmmo/block/Property.java

@@ -1,4 +1,4 @@
-package com.gmail.nossr50.core.mcmmo;
+package com.gmail.nossr50.core.mcmmo.block;
 
 
 import java.util.Collection;
 import java.util.Collection;
 
 

+ 4 - 10
core/src/main/java/com/gmail/nossr50/core/mcmmo/entity/Entity.java

@@ -1,21 +1,15 @@
 package com.gmail.nossr50.core.mcmmo.entity;
 package com.gmail.nossr50.core.mcmmo.entity;
 
 
-import com.gmail.nossr50.core.mcmmo.Location;
+import com.gmail.nossr50.core.mcmmo.world.Location;
 import com.gmail.nossr50.core.mcmmo.Named;
 import com.gmail.nossr50.core.mcmmo.Named;
-
-import java.util.UUID;
+import com.gmail.nossr50.core.mcmmo.Unique;
+import com.gmail.nossr50.core.mcmmo.meta.MetadataHolder;
 
 
 /**
 /**
  * Entities can be a lot of things in MC
  * Entities can be a lot of things in MC
  * Entities can be monsters, animals, players, etc...
  * Entities can be monsters, animals, players, etc...
  */
  */
-public interface Entity extends Location, Named {
-    /**
-     * The UUID for this entity
-     *
-     * @return this entity's UUID
-     */
-    UUID getUUID();
+public interface Entity extends Location, Named, Unique, MetadataHolder {
 
 
     /**
     /**
      * The Location for this entity
      * The Location for this entity

+ 0 - 2
core/src/main/java/com/gmail/nossr50/core/mcmmo/entity/Player.java

@@ -3,8 +3,6 @@ package com.gmail.nossr50.core.mcmmo.entity;
 import com.gmail.nossr50.core.datatypes.player.McMMOPlayer;
 import com.gmail.nossr50.core.datatypes.player.McMMOPlayer;
 import com.gmail.nossr50.core.mcmmo.Nameable;
 import com.gmail.nossr50.core.mcmmo.Nameable;
 
 
-import java.util.UUID;
-
 /**
 /**
  * Players
  * Players
  */
  */

+ 25 - 0
core/src/main/java/com/gmail/nossr50/core/mcmmo/meta/Metadata.java

@@ -0,0 +1,25 @@
+package com.gmail.nossr50.core.mcmmo.meta;
+
+/**
+ * Represents custom state in the API
+ * Mostly provided by plugins
+ */
+public interface Metadata {
+    /**
+     * The metadata key for this metadata
+     * @return the metadata key
+     */
+    String getKey();
+
+    /**
+     * The value for this metadata key
+     * @return the value of this metadata
+     */
+    Object getValue();
+
+    /**
+     * Replace the value in this metadata
+     * @param newValue the replacement metadata value
+     */
+    void setValue(Object newValue);
+}

+ 20 - 0
core/src/main/java/com/gmail/nossr50/core/mcmmo/meta/MetadataHolder.java

@@ -0,0 +1,20 @@
+package com.gmail.nossr50.core.mcmmo.meta;
+
+/**
+ * A metadataHolder is something that can hold metadata
+ * Both Bukkit and Sponge provide metadata APIs
+ */
+public interface MetadataHolder {
+    /**
+     * Gets the metadata for the appropriate key
+     * @param key the key for the metadata
+     * @return the metadata for this key
+     */
+    Metadata getMetadata(String key);
+
+    /**
+     * Sets the metadata, will replace metadata with an existing key or add metadata if there was none
+     * @param metadata metadata to add
+     */
+    void setMetadata(Metadata metadata);
+}

+ 1 - 1
core/src/main/java/com/gmail/nossr50/core/mcmmo/AbstractWorld.java → core/src/main/java/com/gmail/nossr50/core/mcmmo/world/AbstractWorld.java

@@ -1,4 +1,4 @@
-package com.gmail.nossr50.core.mcmmo;
+package com.gmail.nossr50.core.mcmmo.world;
 
 
 import java.util.Objects;
 import java.util.Objects;
 
 

+ 13 - 4
core/src/main/java/com/gmail/nossr50/core/mcmmo/Location.java → core/src/main/java/com/gmail/nossr50/core/mcmmo/world/Location.java

@@ -1,4 +1,7 @@
-package com.gmail.nossr50.core.mcmmo;
+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
  * This class represents a Location in MC
@@ -6,26 +9,32 @@ package com.gmail.nossr50.core.mcmmo;
  */
  */
 public interface Location {
 public interface Location {
 
 
+    /**
+     * The Vector3d of this location
+     * @return this vector
+     */
+    Vector3d getVector();
+
     /**
     /**
      * Returns the position of this location on the x-axis
      * Returns the position of this location on the x-axis
      *
      *
      * @return x-axis position
      * @return x-axis position
      */
      */
-    double getX();
+    //double getX();
 
 
     /**
     /**
      * Returns the position of this location on the y-axis
      * Returns the position of this location on the y-axis
      *
      *
      * @return y-axis position
      * @return y-axis position
      */
      */
-    double getY();
+    //double getY();
 
 
     /**
     /**
      * Returns the position of this location on the z-axis
      * Returns the position of this location on the z-axis
      *
      *
      * @return z-axis position
      * @return z-axis position
      */
      */
-    double getZ();
+    //double getZ();
 
 
     /**
     /**
      * The world for this Location
      * The world for this Location

+ 15 - 0
core/src/main/java/com/gmail/nossr50/core/mcmmo/world/World.java

@@ -0,0 +1,15 @@
+package com.gmail.nossr50.core.mcmmo.world;
+
+import com.gmail.nossr50.core.mcmmo.Unique;
+
+/**
+ * Represents a world in MC
+ */
+public interface World extends Unique {
+    /**
+     * Gets the name of this World
+     *
+     * @return the name of this world
+     */
+    String getName();
+}