Skip to content

Commit

Permalink
Remove items that teleport across dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
LXGaming committed Sep 15, 2018
1 parent b433cef commit ee4f270
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -60,6 +63,10 @@ public boolean isSpongeDeath() {
return spongeDeath;
}

public boolean isSpongeItemTeleport() {
return spongeItemTeleport;
}

public boolean isSpongePhase() {
return spongePhase;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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()))));
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand Down

0 comments on commit ee4f270

Please sign in to comment.