SteamWar/BauSystem2.0
Archiviert
12
0

Fix FreezeListener again
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-07-29 22:30:17 +02:00
Ursprung bb3ac6c515
Commit c304fc034f
2 geänderte Dateien mit 112 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -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);
}
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Region, Optional<TechHider>> techHiders = new HashMap<>();
private Map<Region, Set<Player>> hidden = new HashMap<>();
@Register
public void toggleHider(Player player) {
Region region = Region.getRegion(player.getLocation());
if (region.isGlobal()) {
return;
}
Optional<TechHider> 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<String> hiddenBlocks = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlocks")));
Set<String> 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()));
}
}