Skip to content

Commit

Permalink
Prevent movement outside of the world border
Browse files Browse the repository at this point in the history
  • Loading branch information
LXGaming committed Sep 11, 2018
1 parent c81c1bf commit 9860438
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 2 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.7"
version = "1.12.2-1.2.8"

minecraft {
version = "1.12.2-14.23.4.2705"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private void registerMappings() {
getIntegrationMappings().put("io.github.lxgaming.sledgehammer.integrations.ForgeIntegration", IntegrationCategory::isForge);
getIntegrationMappings().put("io.github.lxgaming.sledgehammer.integrations.MistIntegration", IntegrationCategory::isMist);
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_Phase", IntegrationCategory::isSpongePhase);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.github.lxgaming.sledgehammer.integrations.ForgeIntegration;
import io.github.lxgaming.sledgehammer.integrations.MistIntegration;
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_Phase;
import io.github.lxgaming.sledgehammer.managers.CommandManager;
Expand Down Expand Up @@ -59,6 +60,7 @@ public void onGameInitialization(GameInitializationEvent event) {
IntegrationManager.registerIntegration(ForgeIntegration.class);
IntegrationManager.registerIntegration(MistIntegration.class);
IntegrationManager.registerIntegration(PrimalIntegration.class);
IntegrationManager.registerIntegration(SpongeIntegration_Border.class);
IntegrationManager.registerIntegration(SpongeIntegration_Death.class);
IntegrationManager.registerIntegration(SpongeIntegration_Phase.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class IntegrationCategory {
@Setting(value = "primal", comment = "Fixes https://github.com/An-Sar/PrimalCore/issues/210 (Fixed in 0.6.56 according to Dev)")
private boolean primal = false;

@Setting(value = "sponge-border", comment = "Prevent movement outside of the world border")
private boolean spongeBorder = false;

@Setting(value = "sponge-death", comment = "Prevent sending blank death messages")
private boolean spongeDeath = false;

Expand All @@ -49,6 +52,10 @@ public boolean isPrimal() {
return primal;
}

public boolean isSpongeBorder() {
return spongeBorder;
}

public boolean isSpongeDeath() {
return spongeDeath;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 com.flowpowered.math.vector.Vector3d;
import io.github.lxgaming.sledgehammer.Sledgehammer;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.Player;
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.world.Location;
import org.spongepowered.api.world.World;

public class SpongeIntegration_Border extends AbstractIntegration {

public SpongeIntegration_Border() {
addDependency("sponge");
}

@Override
public boolean prepareIntegration() {
Sponge.getEventManager().registerListeners(Sledgehammer.getInstance().getPluginContainer(), this);
return true;
}

@Listener(order = Order.LAST)
public void onMoveEntity(MoveEntityEvent event, @Root Player player) {
// https://github.com/NucleusPowered/Nucleus/blob/c55d92191741214b09a6952ca853723c27f640d0/src/main/java/io/github/nucleuspowered/nucleus/Util.java#L393
Location<World> location = event.getToTransform().getLocation();
World world = location.getExtent();
long radius = (long) Math.floor(world.getWorldBorder().getDiameter() / 2.0) + 1L;
Vector3d displacement = location.getPosition().sub(world.getWorldBorder().getCenter()).abs();
if (displacement.getX() > radius || displacement.getZ() > radius) {
event.setCancelled(true);
Sledgehammer.getInstance().debugMessage("Move denied for {} ({})", player.getName(), player.getUniqueId());
}
}
}
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.7";
public static final String PLUGIN_VERSION = "1.12.2-1.2.8";
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 9860438

Please sign in to comment.