forked from SteamWar/SteamWar
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7de562bf84 | ||
|
|
c9bfa9896b |
@@ -131,7 +131,6 @@ public class BauScoreboard implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
SWScoreboard.impl.removeScoreboard(event.getPlayer());
|
|
||||||
ADDITIONAL_SCOREBOARD_LINES.remove(event.getPlayer());
|
ADDITIONAL_SCOREBOARD_LINES.remove(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -325,7 +325,7 @@ public class FixedRegion implements Region {
|
|||||||
}
|
}
|
||||||
|
|
||||||
floorLevel = prototype.getFloorOffset() != 0 ? minPoint.getY() + prototype.getFloorOffset() : 0;
|
floorLevel = prototype.getFloorOffset() != 0 ? minPoint.getY() + prototype.getFloorOffset() : 0;
|
||||||
waterLevel = prototype.getWaterOffset() != 0 ? minPoint.getY() + prototype.getWaterOffset() : 0;
|
waterLevel = prototype.getWaterOffset() != 0 ? minPoint.getX() + prototype.getWaterOffset() : 0;
|
||||||
|
|
||||||
File found = null;
|
File found = null;
|
||||||
File baseFile = new File(BauSystem.getInstance().getDataFolder().getParentFile(), "FightSystem");
|
File baseFile = new File(BauSystem.getInstance().getDataFolder().getParentFile(), "FightSystem");
|
||||||
|
|||||||
@@ -307,12 +307,12 @@ class SteamwarUser(id: EntityID<Int>) : IntEntity(id) {
|
|||||||
punishments[punishment] = Punishment.createPunishment(this@SteamwarUser.id.value, from, punishment, reason, time, perma)
|
punishments[punishment] = Punishment.createPunishment(this@SteamwarUser.id.value, from, punishment, reason, time, perma)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setLocale(locale: Locale?, manualLocale: Boolean) {
|
fun setLocale(locale: Locale?, manualeLocale: Boolean) {
|
||||||
if (locale == null || (this.manualLocale && !manualLocale)) return
|
if (locale == null || (this.manualLocale && !manualLocale)) return
|
||||||
|
|
||||||
useDb {
|
useDb {
|
||||||
this@SteamwarUser.locale = locale
|
this@SteamwarUser.locale = locale
|
||||||
this@SteamwarUser.manualLocale = manualLocale
|
this@SteamwarUser.manualLocale = manualeLocale
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.core.events;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
|
import de.steamwar.core.Core;
|
||||||
|
import de.steamwar.linkage.Linked;
|
||||||
|
import de.steamwar.sql.SWException;
|
||||||
|
import de.steamwar.techhider.ProtocolUtils;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
|
||||||
|
import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@Linked
|
||||||
|
public class AntiNocom implements Listener {
|
||||||
|
|
||||||
|
private final Map<Player, Integer> flags = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public AntiNocom() {
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundPlayerActionPacket.class, this::onDig);
|
||||||
|
registerUseItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onQuit(PlayerQuitEvent e) {
|
||||||
|
flags.remove(e.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerUseItem() {
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, (player, packet) -> {
|
||||||
|
BlockPos pos = packet.getHitResult().getBlockPos();
|
||||||
|
return isValid(player, "UseItem", pos.getX(), pos.getZ()) ? packet : null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private ServerboundPlayerActionPacket onDig(Player player, ServerboundPlayerActionPacket packet) {
|
||||||
|
BlockPos pos = packet.getPos();
|
||||||
|
return isValid(player, "Dig", pos.getX(), pos.getZ()) ? packet : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isValid(Player player, String type, int x, int z) {
|
||||||
|
if ((x == 0 && z == 0) || player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int amount = flags.compute(player, (p, a) -> a == null ? 1 : a + 1);
|
||||||
|
if (amount % 8 == 0) { // Only after 8 and every 8 to reduce false flags and spam
|
||||||
|
if (amount == 8) {
|
||||||
|
// Schedule player kick only once
|
||||||
|
Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
SWException.log(player.getName() + " kicked for potential NoCom-DOS attack", x + " " + z + " " + type + " " + amount);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,13 +30,16 @@ import com.sk89q.worldedit.regions.selector.limit.PermissiveSelectorLimits;
|
|||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.core.SWPlayer;
|
import de.steamwar.core.SWPlayer;
|
||||||
|
import de.steamwar.entity.CWireframe;
|
||||||
|
import de.steamwar.entity.REntityServer;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.*;
|
import net.minecraft.network.protocol.game.*;
|
||||||
import org.bukkit.*;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.FluidCollisionMode;
|
||||||
import org.bukkit.attribute.AttributeModifier;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@@ -44,7 +47,6 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.inventory.InventoryType;
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.bukkit.util.RayTraceResult;
|
import org.bukkit.util.RayTraceResult;
|
||||||
|
|
||||||
@@ -63,16 +65,6 @@ public class SteamEditWand implements Listener {
|
|||||||
};
|
};
|
||||||
public static final ItemStack ITEM = new SWItem(MATERIAL, NAME).setLore(LORE).getItemStack();
|
public static final ItemStack ITEM = new SWItem(MATERIAL, NAME).setLore(LORE).getItemStack();
|
||||||
|
|
||||||
static {
|
|
||||||
ItemMeta itemMeta = ITEM.getItemMeta();
|
|
||||||
itemMeta.addAttributeModifier(Attribute.BLOCK_INTERACTION_RANGE, new AttributeModifier(
|
|
||||||
NamespacedKey.fromString("range", Core.getInstance()),
|
|
||||||
35.0,
|
|
||||||
AttributeModifier.Operation.ADD_NUMBER
|
|
||||||
));
|
|
||||||
ITEM.setItemMeta(itemMeta);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean noWand(Player player) {
|
private boolean noWand(Player player) {
|
||||||
return player.getInventory().getItemInMainHand().getType() != SteamEditWand.MATERIAL;
|
return player.getInventory().getItemInMainHand().getType() != SteamEditWand.MATERIAL;
|
||||||
}
|
}
|
||||||
@@ -95,6 +87,15 @@ public class SteamEditWand implements Listener {
|
|||||||
TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, this::rightClick);
|
TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, this::rightClick);
|
||||||
TinyProtocol.instance.addFilter(ServerboundPickItemFromBlockPacket.class, this::middleClick);
|
TinyProtocol.instance.addFilter(ServerboundPickItemFromBlockPacket.class, this::middleClick);
|
||||||
TinyProtocol.instance.addFilter(ServerboundPlayerActionPacket.class, this::swapHands);
|
TinyProtocol.instance.addFilter(ServerboundPlayerActionPacket.class, this::swapHands);
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Pos.class, this::movePlayerPacket);
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Rot.class, this::movePlayerPacket);
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.PosRot.class, this::movePlayerPacket);
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (noWand(player)) SWPlayer.of(player).removeComponent(SWEditCursor.class);
|
||||||
|
}
|
||||||
|
}, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@@ -103,6 +104,29 @@ public class SteamEditWand implements Listener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class SWEditCursor implements SWPlayer.Component {
|
||||||
|
private Player player;
|
||||||
|
private REntityServer entityServer = new REntityServer();
|
||||||
|
private CWireframe wireframe;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMount(SWPlayer player) {
|
||||||
|
this.player = player.getPlayer();
|
||||||
|
entityServer.addPlayer(player.getPlayer());
|
||||||
|
wireframe = new CWireframe(entityServer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUnmount(SWPlayer player) {
|
||||||
|
entityServer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(Location location) {
|
||||||
|
wireframe.setPos1And2(location, location);
|
||||||
|
wireframe.setBlock(WorldEditRendererCUIEditor.Type.CURSOR.getMaterial(player).createBlockData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Packet<?> leftClick(Player player, Packet<?> packet) {
|
private Packet<?> leftClick(Player player, Packet<?> packet) {
|
||||||
if (noWand(player)) return packet;
|
if (noWand(player)) return packet;
|
||||||
if (player.getOpenInventory().getType() != InventoryType.CREATIVE) return packet;
|
if (player.getOpenInventory().getType() != InventoryType.CREATIVE) return packet;
|
||||||
@@ -356,4 +380,30 @@ public class SteamEditWand implements Listener {
|
|||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServerboundMovePlayerPacket movePlayerPacket(Player player, ServerboundMovePlayerPacket packet) {
|
||||||
|
SWPlayer swPlayer = SWPlayer.of(player);
|
||||||
|
|
||||||
|
if (noWand(player)) {
|
||||||
|
swPlayer.removeComponent(SWEditCursor.class);
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
double distance = WorldEditRendererCUIEditor.Type.CURSOR.getWidth(player).blocks;
|
||||||
|
RayTraceResult result = player.rayTraceBlocks(distance, FluidCollisionMode.NEVER);
|
||||||
|
Block block = result == null ? null : result.getHitBlock();
|
||||||
|
if (result == null || block == null) {
|
||||||
|
swPlayer.removeComponent(SWEditCursor.class);
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!swPlayer.hasComponent(SWEditCursor.class)) {
|
||||||
|
swPlayer.setComponent(new SWEditCursor());
|
||||||
|
}
|
||||||
|
|
||||||
|
swPlayer.getComponent(SWEditCursor.class).ifPresent(cursor -> {
|
||||||
|
cursor.setLocation(block.getLocation());
|
||||||
|
});
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
package de.steamwar.cursor;
|
package de.steamwar.cursor;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.core.SWPlayer;
|
import de.steamwar.core.SWPlayer;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import net.minecraft.network.protocol.Packet;
|
||||||
|
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class CursorListener implements Listener {
|
public class CursorListener implements Listener {
|
||||||
@@ -20,6 +26,10 @@ public class CursorListener implements Listener {
|
|||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Pos.class, this::updateCursorFromPacket);
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Rot.class, this::updateCursorFromPacket);
|
||||||
|
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.PosRot.class, this::updateCursorFromPacket);
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
||||||
SWPlayer.allWithSingleComponent(Cursor.class)
|
SWPlayer.allWithSingleComponent(Cursor.class)
|
||||||
.map(SWPlayer.SWPlayerWithComponent::getComponent)
|
.map(SWPlayer.SWPlayerWithComponent::getComponent)
|
||||||
@@ -27,6 +37,15 @@ public class CursorListener implements Listener {
|
|||||||
}, 1, 1);
|
}, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Packet<?> updateCursorFromPacket(Player player, Packet<?> packet) {
|
||||||
|
SWPlayer swPlayer = SWPlayer.of(player);
|
||||||
|
Optional<Cursor> activeCursor = swPlayer.getComponent(Cursor.class);
|
||||||
|
|
||||||
|
activeCursor.ifPresent(Cursor::renderDeduplicated);
|
||||||
|
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
SWPlayer.of(event.getPlayer()).getComponent(Cursor.class).ifPresent(cursor -> {
|
SWPlayer.of(event.getPlayer()).getComponent(Cursor.class).ifPresent(cursor -> {
|
||||||
|
|||||||
@@ -67,9 +67,7 @@ public class SWScoreboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removeScoreboard(Player player) {
|
public void removeScoreboard(Player player) {
|
||||||
if (player.getScoreboard().getObjective(SIDEBAR) != null) {
|
player.getScoreboard().getObjective(SIDEBAR).unregister();
|
||||||
player.getScoreboard().getObjective(SIDEBAR).unregister();
|
|
||||||
}
|
|
||||||
playerBoards.remove(player);
|
playerBoards.remove(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user