Archiviert
13
0

Add FreezeCommand

Add FreezeListener
Dieser Commit ist enthalten in:
yoyosource 2021-12-24 23:31:20 +01:00
Ursprung 5d61ea2809
Commit 4be54d9b92
5 geänderte Dateien mit 234 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -20,10 +20,8 @@
package de.steamwar.teamserver;
import de.steamwar.message.Message;
import de.steamwar.teamserver.command.GamemodeCommand;
import de.steamwar.teamserver.command.MaterialCommand;
import de.steamwar.teamserver.command.SchemEqualityCommand;
import de.steamwar.teamserver.command.SpeedCommand;
import de.steamwar.teamserver.command.*;
import de.steamwar.teamserver.listener.FreezeListener;
import de.steamwar.teamserver.listener.WorldChange;
import lombok.Getter;
import org.bukkit.Bukkit;
@ -47,8 +45,10 @@ public final class Teamserver extends JavaPlugin {
new GamemodeCommand();
new SpeedCommand();
new SchemEqualityCommand();
new FreezeCommand();
Bukkit.getPluginManager().registerEvents(new WorldChange(), this);
Bukkit.getPluginManager().registerEvents(new FreezeListener(), this);
MaterialCommand materialCommand = new MaterialCommand();
Bukkit.getPluginManager().registerEvents(materialCommand, this);

Datei anzeigen

@ -23,8 +23,13 @@ TIME = HH:mm:ss
DATE=........
COMMAND_HELP_HEAD=§7---=== (§e{0}§7) ===---
# Material
# Freeze
REGION_FREEZE_HELP=§8/§efreeze §8- §7Toggle Freeze
REGION_FREEZE_NO_PERMS=§cDu darfst diese Welt nicht einfrieren
REGION_FREEZE_ENABLED=§cRegion eingefroren
REGION_FREEZE_DISABLED=§aRegion aufgetaut
# Material
MATERIAL_INV_NAME=§eMaterial {0}/{1}
MATERIAL_SEARCH=§eSuchen
MATERIAL_BACK=§eZurück
@ -35,6 +40,7 @@ MATERIAL_SEARCH_GRAVITY=
MATERIAL_SEARCH_OCCLUDING=§eOccluding
MATERIAL_SEARCH_INTERACTEABLE=§eInterargierbar
MATERIAL_SEARCH_FLAMMABLE=§eFlammbar
MATERIAL_SEARCH_BURNABLE=§eBrennbar
MATERIAL_SEARCH_WATERLOGGABLE=§eWasserspeicherbar
MATERIAL_SEARCH_BLASTRESISTANCE=§eBlast Resistance
MATERIAL_SEARCH_BLASTRESISTANCE_MIN=§eBlast Resistance mindestens
@ -51,4 +57,5 @@ MATERIAL_GRAVITY=
MATERIAL_OCCLUDING=§8- §eOccluding Block
MATERIAL_INTERACT-ABLE=§8- §eInterargierbarer Block
MATERIAL_FLAMMABLE=§8- §eFlammbarer Block
MATERIAL_BURNABLE=§8- §eBrennbarer Block
MATERIAL_WATERLOGGABLE=§8- §eWasserspeicherbarer Block

Datei anzeigen

@ -0,0 +1,80 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 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.teamserver.command;
import de.steamwar.command.GuardCheckType;
import de.steamwar.command.GuardChecker;
import de.steamwar.command.GuardResult;
import de.steamwar.command.SWCommand;
import de.steamwar.teamserver.Teamserver;
import de.steamwar.teamserver.listener.FreezeListener;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.entity.Player;
public class FreezeCommand extends SWCommand {
public FreezeCommand() {
super("freeze", "stoplag");
}
@Register(description = "REGION_FREEZE_HELP")
public void toggleCommand(@Guard Player p) {
if (toggle()) {
Teamserver.MESSAGE.send(getEnableMessage(), p, ChatMessageType.ACTION_BAR);
} else {
Teamserver.MESSAGE.send(getDisableMessage(), p, ChatMessageType.ACTION_BAR);
}
}
private String getNoPermMessage() {
return "REGION_FREEZE_NO_PERMS";
}
private String getEnableMessage(){
return "REGION_FREEZE_ENABLED";
}
private String getDisableMessage(){
return "REGION_FREEZE_DISABLED";
}
private boolean toggle() {
if (FreezeListener.freeze) {
FreezeListener.freeze = false;
} else {
FreezeListener.freeze = true;
}
return FreezeListener.freeze;
}
@ClassGuard(value = Player.class, local = true)
public GuardChecker guard() {
return (commandSender, guardCheckType, strings, s) -> {
Player player = (Player) commandSender;
if (!player.isOp()) {
if (guardCheckType != GuardCheckType.TAB_COMPLETE) {
Teamserver.MESSAGE.send(getNoPermMessage(), player);
}
return GuardResult.DENIED;
}
return GuardResult.ALLOWED;
};
}
}

Datei anzeigen

@ -76,6 +76,7 @@ public class MaterialCommand extends SWCommand implements Listener {
private boolean occluding;
private boolean interacteable;
private boolean flammable;
private boolean burnable;
private boolean waterloggable;
public MaterialData(Material material) {
@ -90,6 +91,7 @@ public class MaterialCommand extends SWCommand implements Listener {
occluding = material.isOccluding();
interacteable = material.isInteractable();
flammable = material.isFlammable();
burnable = material.isBurnable();
BlockData blockData = material.createBlockData();
waterloggable = blockData instanceof Waterlogged;
@ -123,6 +125,9 @@ public class MaterialCommand extends SWCommand implements Listener {
if (flammable) {
lore.add(Teamserver.MESSAGE.parse("MATERIAL_FLAMMABLE", p));
}
if (burnable) {
lore.add(Teamserver.MESSAGE.parse("MATERIAL_BURNABLE", p));
}
if (waterloggable) {
lore.add(Teamserver.MESSAGE.parse("MATERIAL_WATERLOGGABLE", p));
}
@ -150,6 +155,9 @@ public class MaterialCommand extends SWCommand implements Listener {
if (search.flammable) {
result &= flammable;
}
if (search.burnable) {
result &= burnable;
}
if (search.waterloggable) {
result &= waterloggable;
}
@ -175,6 +183,7 @@ public class MaterialCommand extends SWCommand implements Listener {
private boolean occluding = false;
private boolean interacteable = false;
private boolean flammable = false;
private boolean burnable = false;
private boolean waterloggable = false;
private double blastResistanceMin = 0;
@ -236,11 +245,15 @@ public class MaterialCommand extends SWCommand implements Listener {
search.flammable = !search.flammable;
searchGUI(p);
}));
swInventory.setItem(25, new SWItem(Material.WATER_BUCKET, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_WATERLOGGABLE", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.waterloggable), clickType -> {
swInventory.setItem(25, new SWItem(Material.LAVA_BUCKET, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_BURNABLE", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.burnable), clickType -> {
search.burnable = !search.burnable;
searchGUI(p);
}));
swInventory.setItem(28, new SWItem(Material.WATER_BUCKET, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_WATERLOGGABLE", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.waterloggable), clickType -> {
search.waterloggable = !search.waterloggable;
searchGUI(p);
}));
swInventory.setItem(28, new SWItem(Material.FIRE_CHARGE, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE_MIN", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.blastResistanceMin), clickType -> {
swInventory.setItem(30, new SWItem(Material.FIRE_CHARGE, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE_MIN", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.blastResistanceMin), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p), search.blastResistanceMin + "");
swAnvilInv.setCallback(s -> {
try {
@ -256,7 +269,7 @@ public class MaterialCommand extends SWCommand implements Listener {
});
swAnvilInv.open();
}));
swInventory.setItem(29, new SWItem(Material.TNT, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE_MAX", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.blastResistanceMax), clickType -> {
swInventory.setItem(31, new SWItem(Material.TNT, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE_MAX", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.blastResistanceMax), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p), search.blastResistanceMax + "");
swAnvilInv.setCallback(s -> {
try {
@ -272,7 +285,7 @@ public class MaterialCommand extends SWCommand implements Listener {
});
swAnvilInv.open();
}));
swInventory.setItem(31, new SWItem(Material.NETHER_BRICK, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE_EXACT", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.blastResistanceMin + "-" + search.blastResistanceMax), clickType -> {
swInventory.setItem(32, new SWItem(Material.NETHER_BRICK, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE_EXACT", p) + Teamserver.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.blastResistanceMin + "-" + search.blastResistanceMax), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, Teamserver.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p), search.blastResistanceMax + "");
swAnvilInv.setCallback(s -> {
try {

Datei anzeigen

@ -0,0 +1,125 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 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.teamserver.listener;
import de.steamwar.teamserver.Teamserver;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
public class FreezeListener implements Listener {
public static boolean freeze = true;
@EventHandler
public void onEntitySpawn(EntitySpawnEvent e) {
if (!freeze) {
return;
}
e.setCancelled(true);
if (e.getEntityType() == EntityType.PRIMED_TNT) {
Bukkit.getScheduler().runTaskLater(Teamserver.getInstance(), () -> {
e.getLocation().getBlock().setType(Material.TNT, false);
}, 1L);
}
}
@EventHandler
public void onBlockCanBuild(BlockCanBuildEvent e) {
if (!e.isBuildable()) return;
if (!freeze) {
return;
}
if (e.getMaterial() == Material.TNT) {
e.setBuildable(false);
e.getBlock().setType(Material.TNT, false);
}
}
@EventHandler
public void onEntityChangeBlock(EntityChangeBlockEvent e) {
if (!freeze) {
return;
}
e.setCancelled(true);
}
@EventHandler
public void onPhysicsEvent(BlockPhysicsEvent e) {
if (!freeze) {
return;
}
e.setCancelled(true);
}
@EventHandler
public void onPistonExtend(BlockPistonExtendEvent e) {
if (!freeze) {
return;
}
e.setCancelled(true);
}
@EventHandler
public void onPistonRetract(BlockPistonRetractEvent e) {
if (!freeze) {
return;
}
e.setCancelled(true);
}
@EventHandler
public void onBlockGrow(BlockGrowEvent e) {
if (!freeze) {
return;
}
e.setCancelled(true);
}
@EventHandler
public void onRedstoneEvent(BlockRedstoneEvent e) {
if (!freeze) {
return;
}
e.setNewCurrent(e.getOldCurrent());
}
@EventHandler
public void onBlockDispense(BlockDispenseEvent e) {
if (!freeze) {
return;
}
e.setCancelled(true);
}
@EventHandler
public void onInventoryMoveEvent(InventoryMoveItemEvent e) {
if (!freeze) {
return;
}
e.setCancelled(true);
}
}