From c304fc034f2ef07b09e0257f5c9494b4006cf60e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 29 Jul 2022 22:30:17 +0200 Subject: [PATCH] Fix FreezeListener again Signed-off-by: yoyosource --- .../features/region/FreezeListener.java | 14 +++ .../features/techhider/TechHiderCommand.java | 98 +++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java index 94708b4c..98021658 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java @@ -115,4 +115,18 @@ public class FreezeListener implements Listener { e.setCancelled(true); } } + + @EventHandler + public void onBlockSpread(BlockSpreadEvent e) { + if (Region.getRegion(e.getBlock().getLocation()).get(Flag.FREEZE) == FreezeMode.ACTIVE) { + e.setCancelled(true); + } + } + + @EventHandler + public void onBlockFromTo(BlockFromToEvent event) { + if (Region.getRegion(event.getBlock().getLocation()).get(Flag.FREEZE) == FreezeMode.ACTIVE) { + event.setCancelled(true); + } + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java new file mode 100644 index 00000000..b9d857b4 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java @@ -0,0 +1,98 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 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 . + */ + +package de.steamwar.bausystem.features.techhider; + +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.region.Region; +import de.steamwar.command.SWCommand; +import de.steamwar.core.CraftbukkitWrapper; +import de.steamwar.techhider.TechHider; +import org.bukkit.Material; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.io.File; +import java.util.*; +import java.util.stream.Collectors; + +@Linked(LinkageType.COMMAND) +@Linked(LinkageType.LISTENER) +public class TechHiderCommand extends SWCommand implements Listener { + + public TechHiderCommand() { + super("techhider", "hider", "obfuscate", "hide", "hide-tech"); + } + + private Map> techHiders = new HashMap<>(); + private Map> hidden = new HashMap<>(); + + @Register + public void toggleHider(Player player) { + Region region = Region.getRegion(player.getLocation()); + if (region.isGlobal()) { + return; + } + + Optional techHider = techHiders.computeIfAbsent(region, rg -> { + File file = rg.gameModeConfig(); + + FileConfiguration config = YamlConfiguration.loadConfiguration(file); + if (!config.getBoolean("Techhider.Active", false)) { + return Optional.empty(); + } + + hidden.put(rg, new HashSet<>()); + + String obfuscateWith = config.getString("Techhider.ObfuscateWith", "end_stone"); + Set hiddenBlocks = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlocks"))); + Set hiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlockEntities"))); + + TechHider current = new TechHider((p, cX, cY) -> { + if (rg.chunkOutside(cX, cY)) return true; + return !hidden.get(rg).contains(p); + }, Material.valueOf(obfuscateWith.toUpperCase()), hiddenBlocks.stream().map(String::toUpperCase).map(Material::valueOf).collect(Collectors.toSet()), hiddenBlockEntities); + current.enable(); + + return Optional.of(current); + }); + if (!techHider.isPresent()) { + return; + } + + if (hidden.get(region).contains(player)) { + hidden.get(region).remove(player); + } else { + hidden.get(region).add(player); + } + region.forEachChunk((x, z) -> { + CraftbukkitWrapper.impl.sendChunk(player, x, z); + }); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + hidden.forEach((rg, players) -> players.remove(event.getPlayer())); + } +}