mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-21 23:51:42 +01:00
Only use convert spawners tagged by the give command (#3963)
This commit is contained in:
parent
7852aedabd
commit
a009b2f9b5
@ -353,7 +353,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
|||||||
serverStateProvider = new PaperServerStateProvider();
|
serverStateProvider = new PaperServerStateProvider();
|
||||||
containerProvider = new PaperContainerProvider();
|
containerProvider = new PaperContainerProvider();
|
||||||
} else {
|
} else {
|
||||||
serverStateProvider = new ReflServerStateProvider(getLogger());
|
serverStateProvider = new ReflServerStateProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Event Providers
|
//Event Providers
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import com.earth2me.essentials.utils.LocationUtil;
|
|
||||||
import com.earth2me.essentials.utils.MaterialUtil;
|
import com.earth2me.essentials.utils.MaterialUtil;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@ -24,15 +23,9 @@ public class EssentialsBlockListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
public void onBlockPlace(final BlockPlaceEvent event) {
|
public void onBlockPlace(final BlockPlaceEvent event) {
|
||||||
// Do not rely on getItemInHand();
|
final ItemStack is = event.getItemInHand();
|
||||||
// http://leaky.bukkit.org/issues/663
|
|
||||||
final ItemStack is = LocationUtil.convertBlockToItem(event.getBlockPlaced());
|
|
||||||
|
|
||||||
if (is == null) {
|
if (is.getType() == MaterialUtil.SPAWNER && ess.getPersistentDataProvider().getString(is, "convert") != null) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is.getType() == MaterialUtil.SPAWNER && event.getItemInHand() != null && event.getPlayer() != null && event.getItemInHand().getType() == MaterialUtil.SPAWNER) {
|
|
||||||
final BlockState blockState = event.getBlockPlaced().getState();
|
final BlockState blockState = event.getBlockPlaced().getState();
|
||||||
if (blockState instanceof CreatureSpawner) {
|
if (blockState instanceof CreatureSpawner) {
|
||||||
final CreatureSpawner spawner = (CreatureSpawner) blockState;
|
final CreatureSpawner spawner = (CreatureSpawner) blockState;
|
||||||
@ -48,15 +41,10 @@ public class EssentialsBlockListener implements Listener {
|
|||||||
|
|
||||||
final User user = ess.getUser(event.getPlayer());
|
final User user = ess.getUser(event.getPlayer());
|
||||||
if (user.hasUnlimited(is) && user.getBase().getGameMode() == GameMode.SURVIVAL) {
|
if (user.hasUnlimited(is) && user.getBase().getGameMode() == GameMode.SURVIVAL) {
|
||||||
class UnlimitedItemSpawnTask implements Runnable {
|
ess.scheduleSyncDelayedTask(() -> {
|
||||||
@Override
|
user.getBase().getInventory().addItem(is);
|
||||||
public void run() {
|
user.getBase().updateInventory();
|
||||||
user.getBase().getInventory().addItem(is);
|
});
|
||||||
user.getBase().updateInventory();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ess.scheduleSyncDelayedTask(new UnlimitedItemSpawnTask());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,6 +152,7 @@ public class FlatItemDb extends AbstractItemDb {
|
|||||||
final EntityType entity = data.getEntity();
|
final EntityType entity = data.getEntity();
|
||||||
if (entity != null && material.toString().contains("SPAWNER")) {
|
if (entity != null && material.toString().contains("SPAWNER")) {
|
||||||
ess.getSpawnerItemProvider().setEntityType(stack, entity);
|
ess.getSpawnerItemProvider().setEntityType(stack, entity);
|
||||||
|
ess.getPersistentDataProvider().set(stack, "convert", "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
|
@ -191,6 +191,7 @@ public class LegacyItemDb extends AbstractItemDb {
|
|||||||
if (metaData == 0) metaData = EntityType.PIG.getTypeId();
|
if (metaData == 0) metaData = EntityType.PIG.getTypeId();
|
||||||
try {
|
try {
|
||||||
retval = ess.getSpawnerItemProvider().setEntityType(retval, EntityType.fromId(metaData));
|
retval = ess.getSpawnerItemProvider().setEntityType(retval, EntityType.fromId(metaData));
|
||||||
|
ess.getPersistentDataProvider().set(retval, "convert", "true");
|
||||||
} catch (final IllegalArgumentException e) {
|
} catch (final IllegalArgumentException e) {
|
||||||
throw new Exception("Can't spawn entity ID " + metaData + " from mob spawners.");
|
throw new Exception("Can't spawn entity ID " + metaData + " from mob spawners.");
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,12 @@ import net.ess3.provider.ServerStateProvider;
|
|||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.invoke.MethodType;
|
import java.lang.invoke.MethodType;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
public class ReflServerStateProvider implements ServerStateProvider {
|
public class ReflServerStateProvider implements ServerStateProvider {
|
||||||
private final Object nmsServer;
|
private final Object nmsServer;
|
||||||
private final MethodHandle nmsIsRunning;
|
private final MethodHandle nmsIsRunning;
|
||||||
|
|
||||||
public ReflServerStateProvider(final Logger logger) {
|
public ReflServerStateProvider() {
|
||||||
Object serverObject = null;
|
Object serverObject = null;
|
||||||
MethodHandle isRunning = null;
|
MethodHandle isRunning = null;
|
||||||
final Class<?> nmsClass = ReflUtil.getNMSClass("MinecraftServer");
|
final Class<?> nmsClass = ReflUtil.getNMSClass("MinecraftServer");
|
||||||
|
Loading…
Reference in New Issue
Block a user