Remove the unused extractors
This commit is contained in:
parent
e0e91bc064
commit
dbf5925e0d
@ -1,82 +0,0 @@
|
||||
package com.massivecraft.massivecore;
|
||||
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.metadata.MetadataValueAdapter;
|
||||
import org.bukkit.metadata.Metadatable;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataSimple extends MetadataValueAdapter
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private Object value;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public MetadataSimple(Plugin plugin, Object value)
|
||||
{
|
||||
super(plugin);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Object value()
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
// This can not be invalidated
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static void set(Plugin plugin, Metadatable metadatable, String key, Object value)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
metadatable.setMetadata(key, new MetadataSimple(plugin, value));
|
||||
}
|
||||
else
|
||||
{
|
||||
metadatable.removeMetadata(key, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
public static MetadataValue getMeta(Metadatable metadatable, String key)
|
||||
{
|
||||
if (metadatable == null) return null;
|
||||
List<MetadataValue> metaValues = metadatable.getMetadata(key);
|
||||
if (metaValues == null) return null;
|
||||
if (metaValues.isEmpty()) return null;
|
||||
return metaValues.get(0);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T get(Metadatable metadatable, String key)
|
||||
{
|
||||
MetadataValue metaValue = getMeta(metadatable, key);
|
||||
if (metaValue == null) return null;
|
||||
return (T) metaValue.value();
|
||||
}
|
||||
|
||||
public static boolean has(Metadatable metadatable, String key)
|
||||
{
|
||||
return get(metadatable, key) != null;
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,6 @@ package com.massivecraft.massivecore.entity;
|
||||
import com.massivecraft.massivecore.MassiveCore;
|
||||
import com.massivecraft.massivecore.command.type.TypeUniverse;
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -86,12 +85,6 @@ public class Multiverse extends Entity<Multiverse>
|
||||
return MassiveCore.DEFAULT;
|
||||
}
|
||||
|
||||
public String getUniverse(Object worldNameExtractable)
|
||||
{
|
||||
String worldName = MUtil.extract(String.class, "worldName", worldNameExtractable);
|
||||
return this.getUniverseForWorldName(worldName);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UNIVERSE AND WORLD
|
||||
// -------------------------------------------- //
|
||||
|
@ -16,9 +16,6 @@ import com.massivecraft.massivecore.nms.NmsEntityGet;
|
||||
import com.massivecraft.massivecore.predicate.PredicateElementGarbage;
|
||||
import com.massivecraft.massivecore.predicate.PredicateElementSignificant;
|
||||
import com.massivecraft.massivecore.util.extractor.Extractor;
|
||||
import com.massivecraft.massivecore.util.extractor.ExtractorPlayer;
|
||||
import com.massivecraft.massivecore.util.extractor.ExtractorPlayerName;
|
||||
import com.massivecraft.massivecore.util.extractor.ExtractorSender;
|
||||
import com.massivecraft.massivecore.util.extractor.ExtractorSenderId;
|
||||
import com.massivecraft.massivecore.util.extractor.ExtractorWorld;
|
||||
import com.massivecraft.massivecore.util.extractor.ExtractorWorldName;
|
||||
@ -1909,27 +1906,19 @@ public class MUtil
|
||||
// -------------------------------------------- //
|
||||
|
||||
protected static Map<Class<?>, Map<String, Set<Extractor>>> classesPropertiesExtractors = new HashMap<>();
|
||||
|
||||
protected static Map<String, Set<Extractor>> getPropertiesExtractors(Class<?> propertyClass)
|
||||
{
|
||||
Map<String, Set<Extractor>> ret = classesPropertiesExtractors.get(propertyClass);
|
||||
if (ret == null)
|
||||
{
|
||||
ret = new HashMap<>();
|
||||
classesPropertiesExtractors.put(propertyClass, ret);
|
||||
}
|
||||
return ret;
|
||||
classesPropertiesExtractors.computeIfAbsent(propertyClass, x -> new HashMap<>());
|
||||
return classesPropertiesExtractors.get(propertyClass);
|
||||
}
|
||||
|
||||
protected static Set<Extractor> getExtractors(Class<?> propertyClass, String propertyName)
|
||||
{
|
||||
Map<String, Set<Extractor>> propertiesExtractors = getPropertiesExtractors(propertyClass);
|
||||
Set<Extractor> ret = propertiesExtractors.get(propertyName);
|
||||
if (ret == null)
|
||||
{
|
||||
ret = new HashSet<>();
|
||||
propertiesExtractors.put(propertyName, ret);
|
||||
}
|
||||
return ret;
|
||||
|
||||
propertiesExtractors.computeIfAbsent(propertyName, x -> new HashSet<>());
|
||||
return propertiesExtractors.get(propertyName);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -1955,17 +1944,10 @@ public class MUtil
|
||||
|
||||
static
|
||||
{
|
||||
registerExtractor(CommandSender.class, "sender", ExtractorSender.get());
|
||||
registerExtractor(String.class, "senderId", ExtractorSenderId.get());
|
||||
|
||||
registerExtractor(Player.class, "player", ExtractorPlayer.get());
|
||||
registerExtractor(String.class, "playerName", ExtractorPlayerName.get());
|
||||
|
||||
registerExtractor(World.class, "world", ExtractorWorld.get());
|
||||
registerExtractor(String.class, "worldName", ExtractorWorldName.get());
|
||||
|
||||
// The accountId extractor is used for the money mixin.
|
||||
// For now we act on the name instead of the ID since vault needs names.
|
||||
registerExtractor(String.class, "accountId", ExtractorSenderId.get());
|
||||
}
|
||||
|
||||
|
@ -2,150 +2,15 @@ package com.massivecraft.massivecore.util.extractor;
|
||||
|
||||
import com.massivecraft.massivecore.mixin.MixinSenderPs;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockDamageEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.enchantment.EnchantItemEvent;
|
||||
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
|
||||
import org.bukkit.event.entity.EntityEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.event.vehicle.VehicleDamageEvent;
|
||||
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEvent;
|
||||
import org.bukkit.event.vehicle.VehicleExitEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ExtractorLogic
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// SENDER
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static CommandSender sender(String o) { return IdUtil.getSender(o); }
|
||||
|
||||
public static CommandSender sender(PlayerEvent o) { return o.getPlayer(); }
|
||||
public static CommandSender sender(BlockBreakEvent o) { return o.getPlayer(); }
|
||||
public static CommandSender sender(BlockDamageEvent o) { return o.getPlayer(); }
|
||||
public static CommandSender sender(BlockIgniteEvent o) { return o.getPlayer(); }
|
||||
public static CommandSender sender(BlockPlaceEvent o) { return o.getPlayer(); }
|
||||
public static CommandSender sender(SignChangeEvent o) { return o.getPlayer(); }
|
||||
public static CommandSender sender(EnchantItemEvent o) { return o.getEnchanter(); }
|
||||
public static CommandSender sender(PrepareItemEnchantEvent o) { return o.getEnchanter(); }
|
||||
public static CommandSender sender(Entity o) { if (o instanceof CommandSender) return (CommandSender)o; return null; }
|
||||
public static CommandSender sender(EntityEvent o) { return sender(o.getEntity()); }
|
||||
public static CommandSender sender(InventoryClickEvent o) { return sender(o.getWhoClicked()); }
|
||||
public static CommandSender sender(InventoryCloseEvent o) { return sender(o.getPlayer()); }
|
||||
public static CommandSender sender(InventoryOpenEvent o) { return sender(o.getPlayer()); }
|
||||
public static CommandSender sender(HangingBreakByEntityEvent o) { return sender(o.getRemover()); }
|
||||
public static CommandSender sender(VehicleDamageEvent o) { return sender(o.getAttacker()); }
|
||||
public static CommandSender sender(VehicleDestroyEvent o) { return sender(o.getAttacker()); }
|
||||
public static CommandSender sender(VehicleEnterEvent o) { return sender(o.getEntered()); }
|
||||
public static CommandSender sender(VehicleExitEvent o) { return sender(o.getExited()); }
|
||||
public static CommandSender sender(VehicleEvent o) { return sender(o.getVehicle().getPassenger()); }
|
||||
|
||||
public static CommandSender senderFromObject(Object o)
|
||||
{
|
||||
if (o == null) return null;
|
||||
|
||||
if (o instanceof CommandSender) return (CommandSender)o;
|
||||
|
||||
if (o instanceof String) return sender((String)o);
|
||||
if (o instanceof PlayerEvent) return sender((PlayerEvent)o);
|
||||
if (o instanceof BlockBreakEvent) return sender((BlockBreakEvent)o);
|
||||
if (o instanceof BlockDamageEvent) return sender((BlockDamageEvent)o);
|
||||
if (o instanceof BlockIgniteEvent) return sender((BlockIgniteEvent)o);
|
||||
if (o instanceof BlockPlaceEvent) return sender((BlockPlaceEvent)o);
|
||||
if (o instanceof SignChangeEvent) return sender((SignChangeEvent)o);
|
||||
if (o instanceof EnchantItemEvent) return sender((EnchantItemEvent)o);
|
||||
if (o instanceof PrepareItemEnchantEvent) return sender((PrepareItemEnchantEvent)o);
|
||||
if (o instanceof Entity) return sender((Entity)o);
|
||||
if (o instanceof EntityEvent) return sender((EntityEvent)o);
|
||||
if (o instanceof InventoryClickEvent) return sender((InventoryClickEvent)o);
|
||||
if (o instanceof InventoryCloseEvent) return sender((InventoryCloseEvent)o);
|
||||
if (o instanceof InventoryOpenEvent) return sender((InventoryOpenEvent)o);
|
||||
if (o instanceof HangingBreakByEntityEvent) return sender((HangingBreakByEntityEvent)o);
|
||||
if (o instanceof VehicleDamageEvent) return sender((VehicleDamageEvent)o);
|
||||
if (o instanceof VehicleDestroyEvent) return sender((VehicleDestroyEvent)o);
|
||||
if (o instanceof VehicleEnterEvent) return sender((VehicleEnterEvent)o);
|
||||
if (o instanceof VehicleExitEvent) return sender((VehicleExitEvent)o);
|
||||
if (o instanceof VehicleEvent) return sender((VehicleEvent)o);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PLAYER
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static Player playerFromObject(Object o)
|
||||
{
|
||||
CommandSender sender = senderFromObject(o);
|
||||
if (sender instanceof Player) return (Player)sender;
|
||||
return null;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SENDER ID
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static String senderIdFromObject(Object o)
|
||||
{
|
||||
if (o == null) return null;
|
||||
|
||||
String id = IdUtil.getId(o);
|
||||
if (id != null) return id;
|
||||
|
||||
CommandSender sender = senderFromObject(o);
|
||||
if (sender == null) return null;
|
||||
|
||||
return IdUtil.getId(sender);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SENDER NAME
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static String senderNameFromObject(Object o)
|
||||
{
|
||||
if (o == null) return null;
|
||||
|
||||
String name = IdUtil.getName(o);
|
||||
if (name != null) return name;
|
||||
|
||||
CommandSender sender = senderFromObject(o);
|
||||
if (sender == null) return null;
|
||||
|
||||
return IdUtil.getName(sender);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PLAYER NAME
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static String playerNameFromObject(Object o)
|
||||
{
|
||||
String senderId = senderNameFromObject(o);
|
||||
//if (SenderUtil.isPlayerId(senderId)) return senderId;
|
||||
//return null;
|
||||
return senderId;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// WORLD
|
||||
// -------------------------------------------- //
|
||||
|
@ -1,22 +0,0 @@
|
||||
package com.massivecraft.massivecore.util.extractor;
|
||||
|
||||
public class ExtractorPlayer implements Extractor
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ExtractorPlayer i = new ExtractorPlayer();
|
||||
public static ExtractorPlayer get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: EXTRACTOR
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Object extract(Object o)
|
||||
{
|
||||
return ExtractorLogic.playerFromObject(o);
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.massivecraft.massivecore.util.extractor;
|
||||
|
||||
public class ExtractorPlayerName implements Extractor
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ExtractorPlayerName i = new ExtractorPlayerName();
|
||||
public static ExtractorPlayerName get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: EXTRACTOR
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Object extract(Object o)
|
||||
{
|
||||
return ExtractorLogic.playerNameFromObject(o);
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.massivecraft.massivecore.util.extractor;
|
||||
|
||||
public class ExtractorSender implements Extractor
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ExtractorSender i = new ExtractorSender();
|
||||
public static ExtractorSender get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: EXTRACTOR
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Object extract(Object o)
|
||||
{
|
||||
return ExtractorLogic.senderFromObject(o);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package com.massivecraft.massivecore.util.extractor;
|
||||
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
|
||||
public class ExtractorSenderId implements Extractor
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
@ -16,7 +18,7 @@ public class ExtractorSenderId implements Extractor
|
||||
@Override
|
||||
public Object extract(Object o)
|
||||
{
|
||||
return ExtractorLogic.senderIdFromObject(o);
|
||||
return IdUtil.getId(o);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
package com.massivecraft.massivecore.util.extractor;
|
||||
|
||||
public class ExtractorSenderName implements Extractor
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ExtractorSenderName i = new ExtractorSenderName();
|
||||
public static ExtractorSenderName get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: EXTRACTOR
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Object extract(Object o)
|
||||
{
|
||||
return ExtractorLogic.senderNameFromObject(o);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user