From ee4f2709b889acdf8246df571c0c8a8a0737e6f5 Mon Sep 17 00:00:00 2001 From: Alex Thomson Date: Sat, 15 Sep 2018 18:14:47 +1200 Subject: [PATCH] Remove items that teleport across dimensions Quick fix for https://github.com/SpongePowered/SpongeCommon/issues/2103 --- build.gradle | 2 +- .../lxgaming/sledgehammer/Sledgehammer.java | 1 + .../sledgehammer/SledgehammerPlugin.java | 2 + .../category/IntegrationCategory.java | 7 +++ .../category/MessageCategory.java | 7 +++ .../SpongeIntegration_Border.java | 2 +- .../SpongeIntegration_ItemTeleport.java | 60 +++++++++++++++++++ .../lxgaming/sledgehammer/util/Reference.java | 2 +- 8 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 src/main/java/io/github/lxgaming/sledgehammer/integrations/SpongeIntegration_ItemTeleport.java diff --git a/build.gradle b/build.gradle index 1beae20..6c43788 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ targetCompatibility = 1.8 group = "io.github.lxgaming" archivesBaseName = "Sledgehammer" -version = "1.12.2-1.2.9" +version = "1.12.2-1.2.10" minecraft { version = "1.12.2-14.23.4.2705" diff --git a/src/main/java/io/github/lxgaming/sledgehammer/Sledgehammer.java b/src/main/java/io/github/lxgaming/sledgehammer/Sledgehammer.java index d1fea74..7c7ed3b 100644 --- a/src/main/java/io/github/lxgaming/sledgehammer/Sledgehammer.java +++ b/src/main/java/io/github/lxgaming/sledgehammer/Sledgehammer.java @@ -63,6 +63,7 @@ private void registerMappings() { getIntegrationMappings().put("io.github.lxgaming.sledgehammer.integrations.PrimalIntegration", IntegrationCategory::isPrimal); getIntegrationMappings().put("io.github.lxgaming.sledgehammer.integrations.SpongeIntegration_Border", IntegrationCategory::isSpongeBorder); getIntegrationMappings().put("io.github.lxgaming.sledgehammer.integrations.SpongeIntegration_Death", IntegrationCategory::isSpongeDeath); + getIntegrationMappings().put("io.github.lxgaming.sledgehammer.integrations.SpongeIntegration_ItemTeleport", IntegrationCategory::isSpongeItemTeleport); getIntegrationMappings().put("io.github.lxgaming.sledgehammer.integrations.SpongeIntegration_Phase", IntegrationCategory::isSpongePhase); // Mixin Core diff --git a/src/main/java/io/github/lxgaming/sledgehammer/SledgehammerPlugin.java b/src/main/java/io/github/lxgaming/sledgehammer/SledgehammerPlugin.java index b49ff45..3578d70 100644 --- a/src/main/java/io/github/lxgaming/sledgehammer/SledgehammerPlugin.java +++ b/src/main/java/io/github/lxgaming/sledgehammer/SledgehammerPlugin.java @@ -23,6 +23,7 @@ import io.github.lxgaming.sledgehammer.integrations.PrimalIntegration; import io.github.lxgaming.sledgehammer.integrations.SpongeIntegration_Border; import io.github.lxgaming.sledgehammer.integrations.SpongeIntegration_Death; +import io.github.lxgaming.sledgehammer.integrations.SpongeIntegration_ItemTeleport; import io.github.lxgaming.sledgehammer.integrations.SpongeIntegration_Phase; import io.github.lxgaming.sledgehammer.managers.CommandManager; import io.github.lxgaming.sledgehammer.managers.IntegrationManager; @@ -62,6 +63,7 @@ public void onGameInitialization(GameInitializationEvent event) { IntegrationManager.registerIntegration(PrimalIntegration.class); IntegrationManager.registerIntegration(SpongeIntegration_Border.class); IntegrationManager.registerIntegration(SpongeIntegration_Death.class); + IntegrationManager.registerIntegration(SpongeIntegration_ItemTeleport.class); IntegrationManager.registerIntegration(SpongeIntegration_Phase.class); } diff --git a/src/main/java/io/github/lxgaming/sledgehammer/configuration/category/IntegrationCategory.java b/src/main/java/io/github/lxgaming/sledgehammer/configuration/category/IntegrationCategory.java index f9934a6..6cf7d29 100644 --- a/src/main/java/io/github/lxgaming/sledgehammer/configuration/category/IntegrationCategory.java +++ b/src/main/java/io/github/lxgaming/sledgehammer/configuration/category/IntegrationCategory.java @@ -37,6 +37,9 @@ public class IntegrationCategory { @Setting(value = "sponge-death", comment = "Prevent sending blank death messages") private boolean spongeDeath = false; + @Setting(value = "sponge-item-teleport", comment = "Deletes any items that teleport across dimensions") + private boolean spongeItemTeleport = false; + @Setting(value = "sponge-phase", comment = "Fixes https://github.com/SpongePowered/SpongeForge/issues/2355") private boolean spongePhase = false; @@ -60,6 +63,10 @@ public boolean isSpongeDeath() { return spongeDeath; } + public boolean isSpongeItemTeleport() { + return spongeItemTeleport; + } + public boolean isSpongePhase() { return spongePhase; } diff --git a/src/main/java/io/github/lxgaming/sledgehammer/configuration/category/MessageCategory.java b/src/main/java/io/github/lxgaming/sledgehammer/configuration/category/MessageCategory.java index c1e85b3..2b05214 100644 --- a/src/main/java/io/github/lxgaming/sledgehammer/configuration/category/MessageCategory.java +++ b/src/main/java/io/github/lxgaming/sledgehammer/configuration/category/MessageCategory.java @@ -25,7 +25,14 @@ public class MessageCategory { @Setting(value = "move-outside-border", comment = "Sent to the player when attempting to move outside the world border") private String moveOutsideBorder = "&cCannot move outside of the world border"; + @Setting(value = "item-teleport", comment = "Sent to the player when a thrown item gets deleted") + private String itemTeleport = "&f[ITEM] &cwas lost in time and space"; + public String getMoveOutsideBorder() { return moveOutsideBorder; } + + public String getItemTeleport() { + return itemTeleport; + } } \ No newline at end of file diff --git a/src/main/java/io/github/lxgaming/sledgehammer/integrations/SpongeIntegration_Border.java b/src/main/java/io/github/lxgaming/sledgehammer/integrations/SpongeIntegration_Border.java index 406258f..512293b 100644 --- a/src/main/java/io/github/lxgaming/sledgehammer/integrations/SpongeIntegration_Border.java +++ b/src/main/java/io/github/lxgaming/sledgehammer/integrations/SpongeIntegration_Border.java @@ -21,7 +21,7 @@ import io.github.lxgaming.sledgehammer.configuration.Config; import io.github.lxgaming.sledgehammer.configuration.category.MessageCategory; import io.github.lxgaming.sledgehammer.util.Toolbox; -import org.codehaus.plexus.util.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.spongepowered.api.Sponge; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; diff --git a/src/main/java/io/github/lxgaming/sledgehammer/integrations/SpongeIntegration_ItemTeleport.java b/src/main/java/io/github/lxgaming/sledgehammer/integrations/SpongeIntegration_ItemTeleport.java new file mode 100644 index 0000000..6c6a7ce --- /dev/null +++ b/src/main/java/io/github/lxgaming/sledgehammer/integrations/SpongeIntegration_ItemTeleport.java @@ -0,0 +1,60 @@ +/* + * Copyright 2018 Alex Thomson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.github.lxgaming.sledgehammer.integrations; + +import io.github.lxgaming.sledgehammer.Sledgehammer; +import io.github.lxgaming.sledgehammer.configuration.Config; +import io.github.lxgaming.sledgehammer.configuration.category.MessageCategory; +import io.github.lxgaming.sledgehammer.util.Toolbox; +import org.apache.commons.lang3.StringUtils; +import org.spongepowered.api.Sponge; +import org.spongepowered.api.entity.Item; +import org.spongepowered.api.event.Listener; +import org.spongepowered.api.event.Order; +import org.spongepowered.api.event.entity.MoveEntityEvent; +import org.spongepowered.api.event.filter.cause.Root; +import org.spongepowered.api.text.Text; + +public class SpongeIntegration_ItemTeleport extends AbstractIntegration { + + public SpongeIntegration_ItemTeleport() { + addDependency("sponge"); + } + + @Override + public boolean prepareIntegration() { + Sponge.getEventManager().registerListeners(Sledgehammer.getInstance().getPluginContainer(), this); + return true; + } + + @Listener(order = Order.LAST) + public void onMoveEntity(MoveEntityEvent.Teleport event, @Root Item item) { + if (event.getFromTransform().getExtent() == event.getToTransform().getExtent()) { + return; + } + + event.setCancelled(true); + item.remove(); + + Sledgehammer.getInstance().debugMessage("Item {} removed", item.getItemType().getId()); + Sledgehammer.getInstance().getConfig().map(Config::getMessageCategory).map(MessageCategory::getItemTeleport).filter(StringUtils::isNotBlank).ifPresent(message -> { + item.getCreator().flatMap(Sponge.getServer()::getPlayer).ifPresent(player -> { + player.sendMessage(Text.of(Toolbox.getTextPrefix(), Toolbox.convertColor(message.replace("[ITEM]", item.getItemType().getId())))); + }); + }); + } +} \ No newline at end of file diff --git a/src/main/java/io/github/lxgaming/sledgehammer/util/Reference.java b/src/main/java/io/github/lxgaming/sledgehammer/util/Reference.java index 1eb162d..86b4000 100644 --- a/src/main/java/io/github/lxgaming/sledgehammer/util/Reference.java +++ b/src/main/java/io/github/lxgaming/sledgehammer/util/Reference.java @@ -20,7 +20,7 @@ public class Reference { public static final String PLUGIN_ID = "sledgehammer"; public static final String PLUGIN_NAME = "Sledgehammer"; - public static final String PLUGIN_VERSION = "1.12.2-1.2.9"; + public static final String PLUGIN_VERSION = "1.12.2-1.2.10"; public static final String DESCRIPTION = "Smashes the stupid out of the server."; public static final String AUTHORS = "LX_Gaming"; public static final String SOURCE = "https://github.com/LXGaming/Sledgehammer/";