Skip to content

Commit

Permalink
add partial support for entity tags to compat-api. ref #77
Browse files Browse the repository at this point in the history
  • Loading branch information
crashdemons committed Feb 16, 2021
1 parent 1ccaf98 commit 2143405
Show file tree
Hide file tree
Showing 20 changed files with 743 additions and 12 deletions.
4 changes: 2 additions & 2 deletions PlayerHeads-compatibility/PlayerHeads-common-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.shininet.bukkit</groupId>
<artifactId>PlayerHeads-compatibility</artifactId>
<version>5.2.14-SNAPSHOT</version>
<version>5.2.15-SNAPSHOT</version>
</parent>
<artifactId>PlayerHeads-common-support</artifactId>
<packaging>jar</packaging>
Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>org.shininet.bukkit</groupId>
<artifactId>PlayerHeads-compatibility-api</artifactId>
<version>5.2.14-SNAPSHOT</version>
<version>5.2.15-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>fr.neatmonster</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import com.github.crashdemons.playerheads.compatibility.RuntimeReferences;
import com.github.crashdemons.playerheads.compatibility.SkullType;
import com.github.crashdemons.playerheads.compatibility.Version;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import static org.bukkit.Warning.WarningState.value;
import org.bukkit.block.BlockState;
import org.bukkit.block.Skull;
import org.bukkit.entity.AnimalTamer;
Expand All @@ -32,6 +34,10 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.metadata.Metadatable;
import org.bukkit.plugin.Plugin;
import org.bukkit.projectiles.ProjectileSource;

/**
Expand Down Expand Up @@ -260,4 +266,49 @@ public LivingEntity getKillerEntity(EntityDeathEvent event, boolean considermobk
//if(killer!=null) System.out.println(" final killer: "+killer.getType().name()+" "+killer.getName());
return killer;
}

protected boolean setTemporaryTag(Entity ent, Plugin plugin, String key, String value){
if(ent instanceof Metadatable){
ent.setMetadata(key, new FixedMetadataValue(plugin,value));
return true;
}
return false;
}
protected String getTemporaryTag(Entity ent, Plugin plugin, String key){
if(ent instanceof Metadatable){
List<MetadataValue> values = ent.getMetadata(key);
for(MetadataValue value : values){
Plugin valuePlugin = value.getOwningPlugin();
if(valuePlugin==plugin || (valuePlugin!=null && valuePlugin.equals(plugin))){
return value.asString();
}
}
}
return null;
}

protected boolean setPersistentTag(Entity entity, Plugin plugin, String key, String value){
return false;
}
protected String getPersistentTag(Entity entity, Plugin plugin, String key){
return null;
}

@Override
public boolean supportsEntityTagType(boolean persistent){
return !persistent;
}

@Override
public boolean setEntityTag(Entity entity, Plugin plugin, String key, String value, boolean persistent){
if(persistent) return setPersistentTag(entity,plugin,key,value);
return setTemporaryTag(entity,plugin,key,value);
}

@Override
public String getEntityTag(Entity entity, Plugin plugin, String key, boolean persistent){
if(persistent) return getPersistentTag(entity,plugin,key);
return getTemporaryTag(entity,plugin,key);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.github.crashdemons.playerheads.compatibility.SkullDetails;
import com.github.crashdemons.playerheads.compatibility.SkullType;
import com.github.crashdemons.playerheads.compatibility.common.Provider_common;
import java.util.List;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
Expand All @@ -24,6 +25,10 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.metadata.Metadatable;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.Nullable;

/**
Expand Down Expand Up @@ -134,4 +139,5 @@ public boolean clearProfile(Object o){
throw new IllegalStateException("Not supported by test class");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.shininet.bukkit</groupId>
<artifactId>PlayerHeads-compatibility</artifactId>
<version>5.2.14-SNAPSHOT</version>
<version>5.2.15-SNAPSHOT</version>
</parent>
<artifactId>PlayerHeads-compatibility-api</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -499,4 +500,41 @@ public interface CompatibilityProvider {
*/
public LivingEntity getKillerEntity(EntityDeathEvent event, boolean considermobkillers, boolean considertameowners);

}

/**
* Checks whether the compatibility provider supports entity tags of the provided type
* @param persistent whether the tag should be persistent (saved through restarts).
* @return whether the tags were supported
*/
public boolean supportsEntityTagType(boolean persistent);

/**
* Sets a custom tag on the entity.
* This should only be used for information-tracking purposes (such as spawn-cause).
* Not all versions may support setting persistent tags - you must check the result.
* Tag support will be different between versions - a tag may not be detected in a different server version.
* @param entity the entity to set the tag on.
* @param plugin the plugin requesting the tag to be set.
* @param key the key or name of the tag to set
* @param value the value of the tag to set, or null to remove it.
* @param persistent whether the tag should be persistent (saved through restarts).
* @return whether the requested tag could be set. Usually this will fail if Persistence is not supported.
* @since 5.2.15-SNAPSHOT
*/
public boolean setEntityTag(Entity entity, Plugin plugin, String key, String value, boolean persistent);



/**
* Retrieves a custom tag on an entity.
* @param entity the entity containing the tag
* @param plugin the plugin which set the tag
* @param key the key or name of the tag
* @param persistent whether the tag was set as persistent (saved through restarts).
* @return the tag's value, or null if it is not present
* @since 5.2.15-SNAPSHOT
*/
@Nullable
public String getEntityTag(Entity entity, Plugin plugin, String key, boolean persistent);

}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<include>org.shininet.bukkit:PlayerHeads-craftbukkit-1.8-support:jar:</include>
<include>org.shininet.bukkit:PlayerHeads-glowstone-1.12-support:jar:</include>
<include>org.shininet.bukkit:PlayerHeads-craftbukkit-1.13-support:jar:</include>
<include>org.shininet.bukkit:PlayerHeads-craftbukkit-1.16-support:jar:</include>
<include>org.shininet.bukkit:PlayerHeads-craftbukkit-1.14-support:jar:</include>
</includes>
</artifactSet>
<filters>
Expand Down
10 changes: 8 additions & 2 deletions PlayerHeads-compatibility/PlayerHeads-compatibility-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<!-- This shouldn't be a dep which is packaging: pom -->
<groupId>${project.groupId}</groupId>
<artifactId>PlayerHeads-compatibility-api</artifactId>
<version>5.2.14-SNAPSHOT</version>
<version>5.2.15-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.bukkit</groupId>
Expand Down Expand Up @@ -81,6 +81,12 @@
<artifactId>PlayerHeads-craftbukkit-1.13-support</artifactId>
<version>5.2.15-SNAPSHOT</version>
</dependency>
<dependency>
<!-- This shouldn't be a dep which is packaging: pom -->
<groupId>${project.groupId}</groupId>
<artifactId>PlayerHeads-craftbukkit-1.14-support</artifactId>
<version>5.2.15-SNAPSHOT</version>
</dependency>

<dependency>
<!-- This shouldn't be a dep which is packaging: pom -->
Expand Down Expand Up @@ -218,7 +224,7 @@
<include>org.shininet.bukkit:PlayerHeads-craftbukkit-1.8-support:jar:</include>
<include>org.shininet.bukkit:PlayerHeads-glowstone-1.12-support:jar:</include>
<include>org.shininet.bukkit:PlayerHeads-craftbukkit-1.13-support:jar:</include>
<include>org.shininet.bukkit:PlayerHeads-craftbukkit-1.16-support:jar:</include>
<include>org.shininet.bukkit:PlayerHeads-craftbukkit-1.14-support:jar:</include>
</includes>
</artifactSet>
<filters>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class CompatibilitySupport {
static{
VERSIONS=new HashMap<>();
VERSIONS.put("craftbukkit", new Integer[][]{
{1,14},
{1,13},
{1,8}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@


<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>PlayerHeads-compatibility-api</artifactId>
<version>5.2.15-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<!-- This shouldn't be a dep which is packaging: pom -->
<groupId>${project.groupId}</groupId>
Expand Down Expand Up @@ -78,11 +89,15 @@
<!-- This shouldn't be a dep which is packaging: pom -->
<groupId>${project.groupId}</groupId>
<artifactId>PlayerHeads-common-support</artifactId>
<version>5.2.14-SNAPSHOT</version>
<version>5.2.15-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
</exclusion>
<exclusion>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
</exclusion>
</exclusions>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Eclipse stuff
/.classpath
/.project
/.settings

# netbeans
/nbproject

# maven
/build.xml
/target
/pom.xml.versionsBackup

# vim
.*.sw[a-p]

# various other potential build files
/build
/bin
/dist
/manifest.mf

/world

# Mac filesystem dust
/.DS_Store

# intellij
*.iml
*.ipr
*.iws
.idea/

#personal
/test-in-spigot.bat

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# PlayerHeads
Bukkit Plugin - Drops a player's head when s/he dies, also mob heads
* Drop player heads on player death
* Drop mob heads on death
* Configure drop rate chances
* Configure whether player-kills are required to drop

All credit goes to meiskam for creating the plugin and zand, Dragoboss, any many others for maintaining it.

# Craftbukkit support
This is the implementation branch for Craftbukkit 1.13 support. While this branch is mostly reliant on bukkit-standard features, it also presumes the server has the "authlib" API available to it (for head texturing and improved UUID retrieval), which makes it insufficient for other implementations like Glowstone.



Loading

0 comments on commit 2143405

Please sign in to comment.