Skip to content

Commit

Permalink
improvements to godmode patch
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Feb 13, 2024
1 parent a11754f commit 53a8a95
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ public class PreventGoingBelowBedrockFloor implements AnarchyExploitFixesModule,

private final Set<String> exemptedWorlds;
private final Material fillMaterial;
private final boolean teleport_enabled;
private final boolean filling_enabled;
private final boolean eject_enabled;
private final boolean stop_elytra_enabled;
private final boolean teleport_enabled, filling_enabled, eject_enabled, stop_elytra_enabled;

public PreventGoingBelowBedrockFloor() {
shouldEnable();
Config config = AnarchyExploitFixes.getConfiguration();
config.addComment("bedrock.prevent-going-below-bedrock-floor.enable", "Prevents the player from being hit by a bedrock");
this.teleport_enabled = config.getBoolean("bedrock.prevent-going-below-bedrock-floor.teleport", true, "Teleports the player above the bedrock");
this.eject_enabled = config.getBoolean("bedrock.prevent-going-below-bedrock-floor.eject-player", true, "Eject player from the vehicle");
this.stop_elytra_enabled = config.getBoolean("bedrock.prevent-going-below-bedrock-floor.stop-elytra", true, "Disables a player's elytra flight");
this.filling_enabled = config.getBoolean("bedrock.prevent-going-below-bedrock-floor.fill-bedrock-hole", true, "Indicates whether the hole should be filled from bedorck");
config.addComment("bedrock.prevent-going-below-bedrock-floor.enable",
"Prevents players from going below bedrock the bedrock floor.");
this.teleport_enabled = config.getBoolean("bedrock.prevent-going-below-bedrock-floor.teleport", true,
"Teleports the player above the bedrock");
this.eject_enabled = config.getBoolean("bedrock.prevent-going-below-bedrock-floor.eject-player", true,
"Eject player from the vehicle");
this.stop_elytra_enabled = config.getBoolean("bedrock.prevent-going-below-bedrock-floor.stop-elytra", true,
"Disables a player's elytra flight");
this.filling_enabled = config.getBoolean("bedrock.prevent-going-below-bedrock-floor.fill-bedrock-hole", true,
"Whether the bedrock hole should be filled or not");
this.exemptedWorlds = new HashSet<>(config.getList("bedrock.prevent-going-below-bedrock-floor.exempted-worlds", List.of("world_the_end", "skyblock_world")));
String configuredFillMaterial = config.getString("bedrock.prevent-going-below-bedrock-floor.filler-material", "BEDROCK");
Material filler_material = Material.BEDROCK;
Expand Down Expand Up @@ -85,7 +87,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
// place bedrock at the min world height
if (filling_enabled) world.getBlockAt(playerLoc.getBlockX(), world.getMinHeight(), playerLoc.getBlockZ()).setType(fillMaterial);
// teleport player on top of that bedrock
if (teleport_enabled) event.setTo(event.getFrom().add(0, 2, 0));
if (teleport_enabled) event.setTo(event.getFrom().clone().add(0, 2, 0));
if (eject_enabled && player.isInsideVehicle()) player.leaveVehicle();
if (stop_elytra_enabled && player.isGliding()) player.setGliding(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import me.moomoo.anarchyexploitfixes.utils.LogUtil;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent;

import java.util.logging.Level;

public class GodMode implements AnarchyExploitFixesModule, Listener {

private final AnarchyExploitFixes plugin;

public GodMode() {
shouldEnable();
this.plugin = AnarchyExploitFixes.getInstance();
AnarchyExploitFixes.getConfiguration().addComment("patches.experimental-godmode-patch",
"Removes entities or players if they are \"invalid\". Not sure if this works.");
}
Expand All @@ -32,7 +38,6 @@ public String category() {

@Override
public void enable() {
AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance();
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

Expand All @@ -46,16 +51,59 @@ public void disable() {
HandlerList.unregisterAll(this);
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onVehicleEnter(VehicleEnterEvent event) {
final Vehicle vehicle = event.getVehicle();
if (!vehicle.isTicking() || vehicle.isDead() || !vehicle.isValid()) {
event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
private void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (player.isInsideVehicle() && !player.getVehicle().isValid()) {
player.getVehicle().eject();
LogUtil.moduleLog(Level.WARNING, name(),"Attempted to prevent godmode on player " + player.getName() + ": Dismounted from entity.");
final Player player = event.getPlayer();

if (player.isInsideVehicle()) {
final Entity vehicle = player.getVehicle();

if (vehicle == null) {
LogUtil.moduleLog(Level.WARNING, name(),"Player '" + player.getName() + "' is riding a null entity. " +
"Dismounting player from entity.");
player.leaveVehicle();
return;
}

if (!vehicle.isValid()) {
vehicle.getScheduler().run(plugin, unGod -> {
LogUtil.moduleLog(Level.WARNING, name(),"Player '" + player.getName() + "' is riding an invalid entity. " +
"Ejecting all passengers.");
vehicle.eject();
}, null);
return;
}

if (vehicle.isDead()) {
vehicle.getScheduler().run(plugin, unGod -> {
LogUtil.moduleLog(Level.WARNING, name(), "Player '" + player.getName() + "' is riding a dead entity. " +
"Ejecting all passengers.");
vehicle.eject();
}, null);
return;
}

if (!vehicle.isTicking()) {
vehicle.getScheduler().run(plugin, unGod -> {
LogUtil.moduleLog(Level.WARNING, name(),"Player '" + player.getName() + "' is riding an entity from a non-ticking chunk. " +
"Ejecting all passengers.");
vehicle.eject();
}, null);
return;
}
}

if (!player.isValid() && !player.isDead()) {
LogUtil.moduleLog(Level.WARNING, name(),"Player '" + player.getName() + "' is neither valid nor dead. Kicking player.");
player.kick(AnarchyExploitFixes.getLang(player.locale()).misc_MaskedKickMessage);
LogUtil.moduleLog(Level.WARNING, name(),"Attempted to prevent godmode on player " + player.getName() + ": Kicked player.");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.moomoo.anarchyexploitfixes.modules.bedrock;

import com.cryptomorin.xseries.XMaterial;
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.config.Config;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
Expand All @@ -24,19 +23,21 @@ public class PreventGoingBelowBedrockFloor implements AnarchyExploitFixesModule,

private final Set<String> exemptedWorlds;
private final Material fillMaterial;
private final boolean teleport_enabled;
private final boolean filling_enabled;
private final boolean eject_enabled;
private final boolean stop_elytra_enabled;
private final boolean teleport_enabled, filling_enabled, eject_enabled, stop_elytra_enabled;

public PreventGoingBelowBedrockFloor() {
shouldEnable();
Config config = AnarchyExploitFixes.getConfiguration();
config.addComment("bedrock.prevent-going-below-bedrock-floor.enable", "Fills the bedrock hole and teleports player above.");
this.teleport_enabled = config.getBoolean("bedrock.prevent-going-below-bedrock-floor.teleport", true, "Teleports the player above the bedrock");
this.eject_enabled = config.getBoolean("bedrock.prevent-going-below-bedrock-floor.eject-player", true, "Eject player from the vehicle");
this.stop_elytra_enabled = config.getBoolean("bedrock.prevent-going-below-bedrock-floor.stop-elytra", true, "Disables a player's elytra flight");
this.filling_enabled = config.getBoolean("bedrock.prevent-going-below-bedrock-floor.fill-bedrock-hole", true, "Indicates whether the hole should be filled from bedorck");
config.addComment("bedrock.prevent-going-below-bedrock-floor.enable",
"Prevents players from going below bedrock the bedrock floor.");
this.teleport_enabled = config.getBoolean("bedrock.prevent-going-below-bedrock-floor.teleport", true,
"Teleports the player above the bedrock");
this.eject_enabled = config.getBoolean("bedrock.prevent-going-below-bedrock-floor.eject-player", true,
"Eject player from the vehicle");
this.stop_elytra_enabled = config.getBoolean("bedrock.prevent-going-below-bedrock-floor.stop-elytra", true,
"Disables a player's elytra flight");
this.filling_enabled = config.getBoolean("bedrock.prevent-going-below-bedrock-floor.fill-bedrock-hole", true,
"Whether the bedrock hole should be filled or not");
this.exemptedWorlds = new HashSet<>(config.getList("bedrock.prevent-going-below-bedrock-floor.exempted-worlds", Arrays.asList("world_the_end", "skyblock_world")));
String configuredFillMaterial = config.getString("bedrock.prevent-going-below-bedrock-floor.filler-material", "BEDROCK");
Material filler_material = Material.BEDROCK;
Expand Down Expand Up @@ -81,7 +82,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
// place bedrock at the min world height
if (filling_enabled) world.getBlockAt(playerLoc.getBlockX(), ChunkUtil.guessMinWorldHeight(world), playerLoc.getBlockZ()).setType(fillMaterial);
// teleport player on top of that bedrock
if (teleport_enabled) event.setTo(event.getFrom().add(0, 2, 0));
if (teleport_enabled) event.setTo(event.getFrom().clone().add(0, 2, 0));
if (eject_enabled && player.isInsideVehicle()) player.leaveVehicle();
if (stop_elytra_enabled && player.isGliding()) player.setGliding(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import me.moomoo.anarchyexploitfixes.utils.LogUtil;
import org.bukkit.ChatColor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent;

import java.util.logging.Level;

Expand Down Expand Up @@ -41,16 +43,53 @@ public boolean shouldEnable() {
return AnarchyExploitFixes.getConfiguration().getBoolean("patches.experimental-godmode-patch", false);
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onVehicleEnter(VehicleEnterEvent event) {
final Vehicle vehicle = event.getVehicle();
if (!vehicle.getChunk().isLoaded() || vehicle.isDead() || !vehicle.isValid()) {
event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
private void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (player.isInsideVehicle() && !player.getVehicle().isValid()) {
player.getVehicle().eject();
LogUtil.moduleLog(Level.WARNING, name(),"Attempted to prevent godmode on player " + player.getName() + ": Dismounted from entity.");
final Player player = event.getPlayer();

if (player.isInsideVehicle()) {
final Entity vehicle = player.getVehicle();

if (vehicle == null) {
LogUtil.moduleLog(Level.WARNING, name(),"Player '" + player.getName() + "' is riding a null entity. " +
"Dismounting player from entity.");
player.leaveVehicle();
return;
}

if (!vehicle.isValid()) {
LogUtil.moduleLog(Level.WARNING, name(),"Player '" + player.getName() + "' is riding an invalid entity. " +
"Ejecting all passengers.");
vehicle.eject();
return;
}

if (vehicle.isDead()) {
LogUtil.moduleLog(Level.WARNING, name(),"Player '" + player.getName() + "' is riding a dead entity. " +
"Ejecting all passengers.");
vehicle.eject();
return;
}

if (!vehicle.getChunk().isLoaded()) {
LogUtil.moduleLog(Level.WARNING, name(),"Player '" + player.getName() + "' is riding an entity from a non-loaded chunk. " +
"Ejecting all passengers.");
vehicle.eject();
return;
}
}

if (!player.isValid() && !player.isDead()) {
player.kickPlayer(ChatColor.translateAlternateColorCodes('&', AnarchyExploitFixes.getLang(player.getLocale()).misc_MaskedKickMessage));
LogUtil.moduleLog(Level.WARNING, name(),"Attempted to prevent godmode on player " + player.getName() + ": Kicked player.");
LogUtil.moduleLog(Level.WARNING, name(),"Player '" + player.getName() + "' is neither valid nor dead. Kicking player.");
player.kickPlayer(AnarchyExploitFixes.getLang(player.getLocale()).misc_MaskedKickMessage);
}
}
}

0 comments on commit 53a8a95

Please sign in to comment.