Merge branch 'development'

This commit is contained in:
Brianna 2020-02-01 11:20:59 -05:00
commit 5d6baf18bc
5 changed files with 64 additions and 19 deletions

View File

@ -2,7 +2,7 @@
<groupId>com.songoda</groupId>
<artifactId>UltimateStacker</artifactId>
<modelVersion>4.0.0</modelVersion>
<version>1.11.4</version>
<version>1.11.5</version>
<build>
<defaultGoal>clean install</defaultGoal>
<finalName>UltimateStacker-${project.version}</finalName>

View File

@ -17,8 +17,13 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataStoreBase;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
public class EntityStack {
@ -148,15 +153,8 @@ public class EntityStack {
newEntity.getEquipment().setItemInHand(CompatibleMaterial.GOLDEN_SWORD.getItem());
if (Settings.CARRY_OVER_METADATA_ON_DEATH.getBoolean()) {
if (killed.hasMetadata("US_REASON"))
newEntity.setMetadata("US_REASON", killed.getMetadata("US_REASON").get(0));
if (killed.hasMetadata("ES"))
newEntity.setMetadata("ES", killed.getMetadata("ES").get(0));
String entityMetadataKey = "mcMMO: Spawned Entity";
if (killed.hasMetadata(entityMetadataKey))
newEntity.setMetadata(entityMetadataKey, new FixedMetadataValue(UltimateStacker.getInstance(), true));
for (Map.Entry<String, MetadataValue> entry : getMetadata(killed).entrySet())
newEntity.setMetadata(entry.getKey(), entry.getValue());
}
DropUtils.processStackedDrop(killed, drops, event);
@ -172,6 +170,43 @@ public class EntityStack {
}
}
public Map<String, MetadataValue> getMetadata(LivingEntity subject) {
Map<String, MetadataValue> v = new HashMap<>();
Map<String, Map<Plugin, MetadataValue>> metadataMap = null;
try {
Object entityMetadata = methodGetEntityMetadata.invoke(Bukkit.getServer());
metadataMap = (Map) fieldMetadataMap.get(entityMetadata);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
if (metadataMap == null) return v;
for (Map.Entry<String, Map<Plugin, MetadataValue>> entry : metadataMap.entrySet()) {
if (!entry.getKey().startsWith(subject.getUniqueId().toString())) continue;
String key = entry.getKey().split(":")[1];
for (MetadataValue value : entry.getValue().values())
v.put(key, value);
}
return v;
}
private static Method methodGetEntityMetadata;
private static Field fieldMetadataMap;
static {
try {
String ver = Bukkit.getServer().getClass().getPackage().getName().substring(23);
Class<?> clazzCraftServer = Class.forName("org.bukkit.craftbukkit." + ver + ".CraftServer");
methodGetEntityMetadata = clazzCraftServer.getDeclaredMethod("getEntityMetadata");
fieldMetadataMap = MetadataStoreBase.class.getDeclaredField("metadataMap");
} catch (NoSuchFieldException | ClassNotFoundException | NoSuchMethodException e) {
e.printStackTrace();
}
fieldMetadataMap.setAccessible(true);
}
public void onDeath(LivingEntity killed, List<Drop> drops, boolean custom, int droppedExp, EntityDeathEvent event) {
killed.setCustomName(null);
killed.setCustomNameVisible(false);

View File

@ -110,6 +110,7 @@ public class BlockListeners implements Listener {
if (!event.isCancelled()) {
if (block.getType() != CompatibleMaterial.SPAWNER.getMaterial()
|| !(block.getState() instanceof CreatureSpawner) // Needed for a DataPack
|| !plugin.spawnersEnabled())
return;

View File

@ -97,6 +97,8 @@ public class EntityUtils {
newEntity.setVelocity(toClone.getVelocity());
}
newEntity.setInvulnerable(false);
for (String checkStr : checks) {
Check check = Check.valueOf(checkStr);
switch (check) {

View File

@ -1,13 +1,20 @@
#General Messages
# General Messages
general.nametag.prefix = "&8[&6UltimateStacker&8]"
general:
nametag:
prefix: '&8[&6UltimateStacker&8]'
#Command Messages
# Command Messages
command.give.success = "&7You have been given a &6%type%&7."
command:
give:
success: '&7You have been given a &6%type%&7.'
#Event Messages
# Event Messages
event.general.nopermission = "&cYou do not have permission to do that."
event.egg.needmore = "&7You need &6%amount% &7Monster Eggs to convert this spawner."
event.egg.sametype = "&7This already spawns &6%type%s&7."
event:
general:
nopermission: '&cYou do not have permission to do that.'
egg:
needmore: '&7You need &6%amount% &7Monster Eggs to convert this spawner.'
sametype: '&7This already spawns &6%type%s&7.'