mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-07-02 04:56:40 +00:00
Compare commits
3 Commits
merge-bran
...
dependabot
Author | SHA1 | Date | |
---|---|---|---|
e6f3b74523 | |||
181371e0c7 | |||
60efca28c3 |
4
pom.xml
4
pom.xml
@ -220,7 +220,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
<version>3.1.2</version>
|
<version>3.3.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@ -430,7 +430,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
<version>3.1.2</version>
|
<version>3.3.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<configLocation>checkstyle.xml</configLocation>
|
<configLocation>checkstyle.xml</configLocation>
|
||||||
<failOnViolation>true</failOnViolation>
|
<failOnViolation>true</failOnViolation>
|
||||||
|
@ -1,17 +1,25 @@
|
|||||||
package me.totalfreedom.totalfreedommod;
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import java.util.Collection;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.attribute.AttributeModifier;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.spigotmc.event.player.PlayerSpawnLocationEvent;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
public class MovementValidator extends FreedomService
|
public class MovementValidator extends FreedomService
|
||||||
{
|
{
|
||||||
@ -33,36 +41,67 @@ public class MovementValidator extends FreedomService
|
|||||||
public void onPlayerTeleport(PlayerTeleportEvent event)
|
public void onPlayerTeleport(PlayerTeleportEvent event)
|
||||||
{
|
{
|
||||||
// Check absolute value to account for negatives
|
// Check absolute value to account for negatives
|
||||||
if (isOutOfBounds(event.getTo()))
|
if (Math.abs(Objects.requireNonNull(event.getTo()).getX()) >= MAX_XYZ_COORD || Math.abs(event.getTo().getZ()) >= MAX_XYZ_COORD || Math.abs(event.getTo().getY()) >= MAX_XYZ_COORD)
|
||||||
{
|
{
|
||||||
event.setCancelled(true); // illegal position, cancel it
|
event.setCancelled(true); // illegal position, cancel it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOutOfBounds(final Location position)
|
|
||||||
{
|
|
||||||
return Math.abs(position.getX()) >= MAX_XYZ_COORD || Math.abs(position.getY()) >= MAX_XYZ_COORD || Math.abs(position.getZ()) >= MAX_XYZ_COORD;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onPlayerMove(PlayerMoveEvent event)
|
public void onPlayerMove(PlayerMoveEvent event)
|
||||||
{
|
{
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
Location from = event.getFrom();
|
Location from = event.getFrom();
|
||||||
Location to = event.getTo();
|
Location to = event.getTo();
|
||||||
double distance = from.distanceSquared(to);
|
assert to != null;
|
||||||
|
if (to.getX() >= from.getX() + MAX_DISTANCE_TRAVELED || to.getY() >= from.getY() + MAX_DISTANCE_TRAVELED || to.getZ() >= from.getZ() + MAX_DISTANCE_TRAVELED)
|
||||||
if (distance >= MAX_DISTANCE_TRAVELED)
|
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
player.kick(Component.text("You were moving too quickly!", NamedTextColor.RED));
|
player.kickPlayer(ChatColor.RED + "You were moving too quickly!");
|
||||||
}
|
}
|
||||||
// Check absolute value to account for negatives
|
// Check absolute value to account for negatives
|
||||||
if (isOutOfBounds(event.getTo()))
|
if (Math.abs(event.getTo().getX()) >= MAX_XYZ_COORD || Math.abs(event.getTo().getZ()) >= MAX_XYZ_COORD || Math.abs(event.getTo().getY()) >= MAX_XYZ_COORD)
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
PaperLib.teleportAsync(player, player.getWorld().getSpawnLocation());
|
PaperLib.teleportAsync(player, player.getWorld().getSpawnLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (exploitItem(event.getPlayer().getInventory().getHelmet()))
|
||||||
|
{
|
||||||
|
event.getPlayer().getInventory().setHelmet(new ItemStack(Material.AIR));
|
||||||
|
event.getPlayer().sendMessage(ChatColor.RED + "An item with both negative infinity and positive infinity attributes was cleared from your helmet slot.");
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
if (exploitItem(event.getPlayer().getInventory().getBoots()))
|
||||||
|
{
|
||||||
|
event.getPlayer().getInventory().setBoots(new ItemStack(Material.AIR));
|
||||||
|
event.getPlayer().sendMessage(ChatColor.RED + "An item with both negative infinity and positive infinity attributes was cleared from your boots slot.");
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
if (exploitItem(event.getPlayer().getInventory().getLeggings()))
|
||||||
|
{
|
||||||
|
event.getPlayer().getInventory().setLeggings(new ItemStack(Material.AIR));
|
||||||
|
event.getPlayer().sendMessage(ChatColor.RED + "An item with both negative infinity and positive infinity attributes was cleared from your leggings slot.");
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
if (exploitItem(event.getPlayer().getInventory().getChestplate()))
|
||||||
|
{
|
||||||
|
event.getPlayer().getInventory().setChestplate(new ItemStack(Material.AIR));
|
||||||
|
event.getPlayer().sendMessage(ChatColor.RED + "An item with both negative infinity and positive infinity attributes was cleared from your chestplate slot.");
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
if (exploitItem(event.getPlayer().getInventory().getItemInMainHand()))
|
||||||
|
{
|
||||||
|
event.getPlayer().getInventory().setItemInMainHand(new ItemStack(Material.AIR));
|
||||||
|
event.getPlayer().sendMessage(ChatColor.RED + "An item with both negative infinity and positive infinity attributes was cleared from your hand.");
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
if (exploitItem(event.getPlayer().getInventory().getItemInOffHand()))
|
||||||
|
{
|
||||||
|
event.getPlayer().getInventory().setItemInOffHand(new ItemStack(Material.AIR));
|
||||||
|
event.getPlayer().sendMessage(ChatColor.RED + "An item with both negative infinity and positive infinity attributes was cleared from your offhand.");
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
@ -71,28 +110,72 @@ public class MovementValidator extends FreedomService
|
|||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
// Validate position
|
// Validate position
|
||||||
if (isOutOfBounds(player.getLocation()))
|
if (Math.abs(player.getLocation().getX()) >= MAX_XYZ_COORD || Math.abs(player.getLocation().getZ()) >= MAX_XYZ_COORD || Math.abs(player.getLocation().getY()) >= MAX_XYZ_COORD)
|
||||||
{
|
{
|
||||||
PaperLib.teleportAsync(player, player.getWorld().getSpawnLocation()); // Illegal position, teleport to spawn
|
PaperLib.teleportAsync(player, player.getWorld().getSpawnLocation()); // Illegal position, teleport to spawn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler
|
||||||
public void onPlayerSpawn(PlayerSpawnLocationEvent event)
|
public void onPlayerHoldItem(PlayerItemHeldEvent event)
|
||||||
{
|
{
|
||||||
final Location playerSpawn = event.getSpawnLocation();
|
if (exploitItem(event.getPlayer().getInventory().getItemInMainHand()))
|
||||||
final Location worldSpawn = event.getPlayer().getWorld().getSpawnLocation();
|
|
||||||
|
|
||||||
// If the player's spawn is equal to the world's spawn, there is no need to check.
|
|
||||||
// This will also prevent any possible feedback loops pertaining to setting an out of bounds world spawn to the same world spawn.
|
|
||||||
if (playerSpawn == worldSpawn)
|
|
||||||
{
|
{
|
||||||
return;
|
event.getPlayer().getInventory().setItemInMainHand(new ItemStack(Material.AIR));
|
||||||
|
event.getPlayer().sendMessage(ChatColor.RED + "An item with both negative infinity and positive infinity attributes was cleared from your hand.");
|
||||||
}
|
}
|
||||||
|
if (exploitItem(event.getPlayer().getInventory().getItemInOffHand()))
|
||||||
if (isOutOfBounds(worldSpawn))
|
|
||||||
{
|
{
|
||||||
event.setSpawnLocation(worldSpawn);
|
event.getPlayer().getInventory().setItemInOffHand(new ItemStack(Material.AIR));
|
||||||
|
event.getPlayer().sendMessage(ChatColor.RED + "An item with both negative infinity and positive infinity attributes was cleared from your offhand.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Boolean exploitItem(ItemStack item)
|
||||||
|
{
|
||||||
|
if (item == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta != null)
|
||||||
|
{
|
||||||
|
Multimap<Attribute, AttributeModifier> attributes = meta.getAttributeModifiers();
|
||||||
|
if (attributes != null)
|
||||||
|
{
|
||||||
|
Map<Attribute, Collection<AttributeModifier>> attrMap = attributes.asMap();
|
||||||
|
|
||||||
|
// For every attribute...
|
||||||
|
for (Attribute attr : attributes.keySet())
|
||||||
|
{
|
||||||
|
// Default values
|
||||||
|
boolean posInf = false;
|
||||||
|
boolean negInf = false;
|
||||||
|
|
||||||
|
// For every AttributeModifier...
|
||||||
|
for (AttributeModifier modifier : attrMap.get(attr))
|
||||||
|
{
|
||||||
|
// Are they ∞ or -∞?
|
||||||
|
if (modifier.getAmount() == Double.POSITIVE_INFINITY)
|
||||||
|
{
|
||||||
|
posInf = true;
|
||||||
|
}
|
||||||
|
else if (modifier.getAmount() == Double.NEGATIVE_INFINITY)
|
||||||
|
{
|
||||||
|
negInf = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Are both values set as true?
|
||||||
|
if (posInf && negInf)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
@ -108,16 +108,6 @@ public class EventBlocker extends FreedomService
|
|||||||
|
|
||||||
event.setRadius(ConfigEntry.EXPLOSIVE_RADIUS.getDouble().floatValue());
|
event.setRadius(ConfigEntry.EXPLOSIVE_RADIUS.getDouble().floatValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
|
||||||
public void onBlockExplode(BlockExplodeEvent event) {
|
|
||||||
if(!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setYield(ConfigEntry.EXPLOSIVE_RADIUS.getDouble().floatValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onBlockExplode(BlockExplodeEvent event)
|
public void onBlockExplode(BlockExplodeEvent event)
|
||||||
|
@ -18,4 +18,4 @@ libraries:
|
|||||||
- org.apache.commons:commons-lang3:3.12.0
|
- org.apache.commons:commons-lang3:3.12.0
|
||||||
- commons-io:commons-io:2.11.0
|
- commons-io:commons-io:2.11.0
|
||||||
- org.jetbrains:annotations:23.0.0
|
- org.jetbrains:annotations:23.0.0
|
||||||
- org.javassist:javassist:3.29.1-GA
|
- org.javassist:javassist:3.29.1-GA
|
Reference in New Issue
Block a user