[Bleeding] Added a Metadata framework for Entities, Blocks, and Worlds

This metadata implementation has the following features:

- All metadata is lazy. Metadata values are not actually computed until another plugin requests them. Memory and CPU are conserved by not computing and storing unnecessary metadata values.

- All metadata is cached. Once a metadata value is computed its value is cached in the metadata store to prevent further unnecessary computation. An invalidation mechanism is provided to flush the cache and force recompilation of metadata values.

- All metadata is stored in basic data types. Convenience methods in the MetadataValue class allow for the conversion of metadata data types when possible. Restricting metadata to basic data types prevents the accidental linking of large object graphs into metadata. Metadata is persistent across the lifetime of the application and adding large object graphs would damage garbage collector performance.

- Metadata access is thread safe. Care has been taken to protect the internal data structures and access them in a thread safe manner.

- Metadata is exposed for all objects that descend from Entity, Block, and World. All Entity and World metadata is stored at the Server  level and all Block metadata is stored at the World level.

- Metadata is NOT keyed on references to original objects - instead metadata is keyed off of unique fields within those objects. Doing this allows metadata to exist for blocks that are in chunks not currently in memory. Additionally, Player objects are keyed off of player name so that Player metadata remains consistent between logins.

- Metadata convenience methods have been added to all Entities, Players, Blocks, BlockStates, and World allowing direct access to an individual instance's metadata.

- Players and OfflinePlayers share a single metadata store, allowing player metadata to be manipulated regardless of the player's current online status.

By: rmichela <deltahat@gmail.com>
This commit is contained in:
Bukkit/Spigot
2011-12-08 00:33:33 -05:00
parent 5906da7948
commit dd1bee786b
22 changed files with 1064 additions and 78 deletions

View File

@@ -11,8 +11,9 @@ public class StandardMessengerTest {
return new StandardMessenger();
}
private int count = 0;
public TestPlugin getPlugin() {
return new TestPlugin();
return new TestPlugin("" + count++);
}
@Test

View File

@@ -22,6 +22,7 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.map.MapView;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
@@ -658,4 +659,20 @@ public class TestPlayer implements Player {
public EntityType getType() {
return EntityType.PLAYER;
}
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
throw new UnsupportedOperationException("Not supported yet.");
}
public List<MetadataValue> getMetadata(String metadataKey) {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean hasMetadata(String metadataKey) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void removeMetadata(String metadataKey, Plugin owningPlugin) {
throw new UnsupportedOperationException("Not supported yet.");
}
}

View File

@@ -1,8 +1,8 @@
package org.bukkit.plugin.messaging;
import com.avaje.ebean.EbeanServer;
import java.io.File;
import java.io.InputStream;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -13,19 +13,31 @@ import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.PluginLogger;
public class TestPlugin implements Plugin {
import com.avaje.ebean.EbeanServer;
public class TestPlugin extends Plugin {
private boolean enabled = true;
final private String pluginName;
public TestPlugin(String pluginName) {
this.pluginName = pluginName;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public String getName() {
return pluginName;
}
public File getDataFolder() {
throw new UnsupportedOperationException("Not supported.");
}
public PluginDescriptionFile getDescription() {
throw new UnsupportedOperationException("Not supported.");
return new PluginDescriptionFile(pluginName, "1.0", "test.test");
}
public FileConfiguration getConfig() {
@@ -100,4 +112,19 @@ public class TestPlugin implements Plugin {
throw new UnsupportedOperationException("Not supported.");
}
@Override
public int hashCode() {
return getName().hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
return getName().equals(((TestPlugin) obj).getName());
}
}