Compare commits
5 Commits
53dbeff829
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 469cd19b55 | |||
| e745ff4721 | |||
| bc5c9a2a13 | |||
| 78f87d97f0 | |||
| db13a9f0a2 |
@@ -21,18 +21,17 @@ class ChatMessagesListener extends ApplianceListener<ChatMessages> {
|
||||
public void onPlayerChatEvent(AsyncChatEvent event) {
|
||||
event.renderer(
|
||||
(source, sourceDisplayName, message, viewer) ->
|
||||
Component.text("")
|
||||
Component.text()
|
||||
.append(this.getAppliance().getReportablePlayerName(source))
|
||||
.append(Component.text(" > ").color(TextColor.color(Color.GRAY.asRGB())))
|
||||
.append(message).color(TextColor.color(Color.SILVER.asRGB()))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
boolean wasHidden = event.joinMessage() == null;
|
||||
event.joinMessage(null);
|
||||
if(wasHidden) return;
|
||||
if(event.joinMessage() == null) return;
|
||||
IteratorUtil.onlinePlayers(player -> {
|
||||
if(!Settings.instance().getSetting(player, Settings.Key.ShowJoinAndLeaveMessages, Boolean.class)) return;
|
||||
player.sendMessage(
|
||||
@@ -45,9 +44,7 @@ class ChatMessagesListener extends ApplianceListener<ChatMessages> {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
boolean wasHidden = event.quitMessage() == null;
|
||||
event.quitMessage(null);
|
||||
if(wasHidden) return;
|
||||
if(event.quitMessage() == null) return;
|
||||
IteratorUtil.onlinePlayers(player -> {
|
||||
if(!Settings.instance().getSetting(player, Settings.Key.ShowJoinAndLeaveMessages, Boolean.class)) return;
|
||||
player.sendMessage(
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.security.antiBoatFreecam;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.tooling.acInform.AcInform;
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class AntiBoatFreecam extends Appliance {
|
||||
private static final float MAX_YAW_OFFSET = 106.0f;
|
||||
private final Map<Player, Float> violatedPlayers = new HashMap<>();
|
||||
|
||||
public AntiBoatFreecam() {
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(
|
||||
Main.instance(),
|
||||
() -> Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
if(!(player.getVehicle() instanceof Boat boat)) return;
|
||||
if(!boat.getPassengers().getFirst().equals(player)) return;
|
||||
float playerYaw = player.getYaw();
|
||||
float boatYaw = boat.getYaw();
|
||||
|
||||
float yawDelta = wrapDegrees(playerYaw - boatYaw);
|
||||
if(Math.abs(yawDelta) <= MAX_YAW_OFFSET) return;
|
||||
|
||||
this.violatedPlayers.merge(player, 1f, Float::sum);
|
||||
float violationCount = this.violatedPlayers.get(player);
|
||||
if(violationCount != 1 && violationCount % 100 != 0) return;
|
||||
Main.instance().getAppliance(AcInform.class).notifyAdmins(
|
||||
"internal",
|
||||
player.getName(),
|
||||
"illegalBoatLookYaw",
|
||||
violationCount
|
||||
);
|
||||
}),
|
||||
1L,
|
||||
1L
|
||||
);
|
||||
}
|
||||
|
||||
private static float wrapDegrees(float deg) {
|
||||
deg = deg % 360f;
|
||||
if (deg >= 180f) deg -= 360f;
|
||||
if (deg < -180f) deg += 360f;
|
||||
return deg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.security.antiFormattedBook;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import net.kyori.adventure.text.*;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class AntiFormattedBook extends Appliance {
|
||||
private static final char SECTION = '\u00A7';
|
||||
|
||||
public boolean containsFormatting(BookMeta meta) {
|
||||
if (this.hasFormattingDeep(meta.title())) return true;
|
||||
if (this.hasFormattingDeep(meta.author())) return true;
|
||||
|
||||
for (Component c : meta.pages()) {
|
||||
if (this.hasFormattingDeep(c)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean hasFormattingDeep(@Nullable Component component) {
|
||||
if(component == null) return false;
|
||||
if (this.hastFormatting(component)) return true;
|
||||
|
||||
if (component instanceof TextComponent tc && tc.content().indexOf(SECTION) >= 0) return true;
|
||||
|
||||
if (component instanceof NBTComponent<?, ?> nbt) {
|
||||
if (nbt.separator() != null && this.hasFormattingDeep(nbt.separator())) return true;
|
||||
}
|
||||
|
||||
for (Component child : component.children()) {
|
||||
if (this.hasFormattingDeep(child)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean hastFormatting(Component component) {
|
||||
Style style = component.style();
|
||||
|
||||
TextColor color = style.color();
|
||||
if (color != null) return true;
|
||||
if (style.font() != null) return true;
|
||||
if (style.insertion() != null && !Objects.requireNonNull(style.insertion()).isEmpty()) return true;
|
||||
|
||||
for (var decoration : style.decorations().entrySet()) {
|
||||
if (decoration.getValue() == TextDecoration.State.TRUE) return true;
|
||||
}
|
||||
|
||||
return style.hoverEvent() != null || style.clickEvent() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new BookEditListener()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.security.antiFormattedBook;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.tooling.acInform.AcInform;
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerEditBookEvent;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class BookEditListener extends ApplianceListener<AntiFormattedBook> {
|
||||
@EventHandler
|
||||
public void onBookEdit(PlayerEditBookEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
BookMeta meta = event.getNewBookMeta();
|
||||
|
||||
if (this.getAppliance().containsFormatting(meta)) {
|
||||
Main.instance().getAppliance(AcInform.class).notifyAdmins(
|
||||
"internal",
|
||||
player.getName(),
|
||||
"illegalBookFormatting",
|
||||
1f
|
||||
);
|
||||
|
||||
BookMeta sanitized = meta.clone();
|
||||
sanitized.title(null);
|
||||
sanitized.author(null);
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
sanitized.pages(List.of(Component.empty()));
|
||||
event.setNewBookMeta(sanitized);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.security.antiIllegalBundlePicker;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.tooling.acInform.AcInform;
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BundleMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class AntiIllegalBundlePicker extends Appliance {
|
||||
private static final int visibleSlotsInBundle = 9;
|
||||
|
||||
public void trackBundle(InventoryClickEvent event) {
|
||||
ItemStack bundle = Objects.requireNonNull(event.getCurrentItem());
|
||||
final int rawSlot = event.getRawSlot();
|
||||
final Player player = (Player) event.getWhoClicked();
|
||||
final InventoryView view = event.getView();
|
||||
final List<ItemStack> before = this.getBundleContents(bundle);
|
||||
|
||||
Bukkit.getScheduler().runTask(Main.instance(), () -> {
|
||||
ItemStack afterStack = view.getItem(rawSlot);
|
||||
if(afterStack == null || afterStack.getType() != Material.BUNDLE) return;
|
||||
|
||||
List<ItemStack> after = this.getBundleContents(afterStack);
|
||||
int removedSlotIndex = this.findRemoved(before, after);
|
||||
|
||||
if(removedSlotIndex >= visibleSlotsInBundle) {
|
||||
Main.instance().getAppliance(AcInform.class).notifyAdmins(
|
||||
"internal",
|
||||
player.getName(),
|
||||
"illegalBundlePick",
|
||||
(float) removedSlotIndex
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private int findRemoved(@NotNull List<ItemStack> before, @NotNull List<ItemStack> after) {
|
||||
for (int i = 0; i < Math.max(before.size(), after.size()); i++) {
|
||||
ItemStack a = i < after.size() ? after.get(i) : null;
|
||||
ItemStack b = i < before.size() ? before.get(i) : null;
|
||||
|
||||
if (b == null && a == null) continue;
|
||||
if (b == null) throw new IllegalStateException("Size of bundle was smaller before pickup Action");
|
||||
|
||||
if (a == null) return i;
|
||||
if (!a.isSimilar(b)) return i;
|
||||
if (a.getAmount() != b.getAmount()) return i;
|
||||
}
|
||||
throw new IllegalStateException("Failed to find picked Item in bundle");
|
||||
}
|
||||
|
||||
private List<ItemStack> getBundleContents(@NotNull ItemStack bundle) {
|
||||
if (bundle.getType() != Material.BUNDLE)
|
||||
throw new IllegalStateException("ItemStack is not a bundle");
|
||||
|
||||
BundleMeta meta = (BundleMeta) bundle.getItemMeta();
|
||||
return meta.getItems().stream()
|
||||
.map(ItemStack::clone)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new OnBundlePickListener()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.security.antiIllegalBundlePicker;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
class OnBundlePickListener extends ApplianceListener<AntiIllegalBundlePicker> {
|
||||
@EventHandler
|
||||
public void onBundlePick(InventoryClickEvent event) {
|
||||
if(!event.getAction().equals(InventoryAction.PICKUP_FROM_BUNDLE)) return;
|
||||
final ItemStack bundle = event.getCurrentItem();
|
||||
if (bundle == null || bundle.getType() != Material.BUNDLE) return;
|
||||
this.getAppliance().trackBundle(event);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user