Damage flag HOOZAH
Dieser Commit ist enthalten in:
Ursprung
758f9cd594
Commit
4dd79391c9
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* 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.bausystem.features.region;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.Permission;
|
||||||
|
import de.steamwar.bausystem.SWUtils;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.bausystem.region.Region;
|
||||||
|
import de.steamwar.bausystem.region.RegionUtils;
|
||||||
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
|
import de.steamwar.bausystem.region.flags.flagvalues.DamageMode;
|
||||||
|
import de.steamwar.command.SWCommand;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
|
@Linked(LinkageType.COMMAND)
|
||||||
|
public class DamageCommand extends SWCommand {
|
||||||
|
|
||||||
|
protected DamageCommand() {
|
||||||
|
super("damage", "dmg");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register(help = true)
|
||||||
|
public void genericHelp(Player p, String... args) {
|
||||||
|
p.sendMessage("§8/§edamage §8- §7Toggle Spielerschaden");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register
|
||||||
|
public void toggleCommand(Player p) {
|
||||||
|
if (!permissionCheck(p)) return;
|
||||||
|
Region region = Region.getRegion(p.getLocation());
|
||||||
|
if (toggle(region)) {
|
||||||
|
RegionUtils.actionBar(region, getEnableMessage());
|
||||||
|
} else {
|
||||||
|
RegionUtils.actionBar(region, getDisableMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getNoPermMessage() {
|
||||||
|
return "§cDu darfst hier nicht Spielerschaden (de-)aktivieren";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getEnableMessage() {
|
||||||
|
return "§cRegions Spielerschaden deaktiviert";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDisableMessage() {
|
||||||
|
return "§aRegions Spielerschaden aktiviert";
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean toggle(Region region) {
|
||||||
|
switch (region.getPlain(Flag.DAMAGE, DamageMode.class)) {
|
||||||
|
case ALLOW:
|
||||||
|
region.set(Flag.DAMAGE, DamageMode.DENY);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
case DENY:
|
||||||
|
region.set(Flag.DAMAGE, DamageMode.ALLOW);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean permissionCheck(Player player) {
|
||||||
|
if (!Permission.hasPermission(player, Permission.WORLD)) {
|
||||||
|
player.sendMessage(BauSystem.PREFIX + getNoPermMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* 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.bausystem.features.region;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.bausystem.region.Region;
|
||||||
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
|
import de.steamwar.bausystem.region.flags.flagvalues.DamageMode;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
|
||||||
|
|
||||||
|
@Linked(LinkageType.LISTENER)
|
||||||
|
public class DamageListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerDamage(EntityDamageEvent e) {
|
||||||
|
if (e.getEntity() instanceof Player && Region.getRegion(e.getEntity().getLocation()).get(Flag.DAMAGE) == DamageMode.DENY) e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
@ -32,6 +32,7 @@ public enum Flag implements EnumDisplay {
|
|||||||
COLOR("FLAG_COLOR", ColorMode.class, ColorMode.YELLOW),
|
COLOR("FLAG_COLOR", ColorMode.class, ColorMode.YELLOW),
|
||||||
TNT("FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB),
|
TNT("FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB),
|
||||||
FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW),
|
FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW),
|
||||||
|
DAMAGE("FLAG_DAMAGE", DamageMode.class, DamageMode.ALLOW),
|
||||||
FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE),
|
FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE),
|
||||||
PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.INACTIVE);
|
PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.INACTIVE);
|
||||||
|
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* 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.bausystem.region.flags.flagvalues;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum DamageMode implements Flag.Value<DamageMode> {
|
||||||
|
|
||||||
|
ALLOW("FLAG_DAMAGE_ALLOW"),
|
||||||
|
DENY("FLAG_DAMAGE_DENY");
|
||||||
|
|
||||||
|
private static DamageMode[] values;
|
||||||
|
private final String chatValue;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DamageMode[] getValues() {
|
||||||
|
if (DamageMode.values == null) {
|
||||||
|
DamageMode.values = DamageMode.values(); //NOSONAR
|
||||||
|
}
|
||||||
|
return DamageMode.values;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DamageMode getValue() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DamageMode getValueOf(final String name) {
|
||||||
|
try {
|
||||||
|
return DamageMode.valueOf(name);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
if (name.equalsIgnoreCase("false")) {
|
||||||
|
return DamageMode.DENY;
|
||||||
|
}
|
||||||
|
return DamageMode.ALLOW;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren