SteamWar/BauSystem2.0
Archiviert
12
0

Add NoGravityCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2024-07-17 14:19:19 +02:00
Ursprung 94958de2da
Commit 820e7fcbb2
6 geänderte Dateien mit 200 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -48,6 +48,7 @@ FLAG_FIRE=Fire
FLAG_FREEZE=Freeze
FLAG_PROTECT=Protect
FLAG_ITEMS=Items
FLAG_NO_GRAVITY = No Gravity
FLAG_TESTBLOCK=Testblock
FLAG_CHANGED=Changed
FLAG_FIRE_ALLOW=§con
@ -56,6 +57,8 @@ FLAG_FREEZE_ACTIVE=§aon
FLAG_FREEZE_INACTIVE=§coff
FLAG_PROTECT_ACTIVE=§aon
FLAG_PROTECT_INACTIVE=§coff
FLAG_NO_GRAVITY_ACTIVE = §aon
FLAG_NO_GRAVITY_INACTIVE = §coff
FLAG_TNT_ALLOW=§aon
FLAG_TNT_DENY=§coff
FLAG_TNT_ONLY_TB=§7no §ebuild area
@ -747,6 +750,9 @@ REGION_PROTECT_HELP=§8/§eprotect §8- §7Protect the region
REGION_PROTECT_DISABLE=§cProtection disabled
REGION_PROTECT_ENABLE=§aProtection enabled
REGION_PROTECT_FALSE_REGION=§cYou are not currently in a (M)WG-region
REGION_NO_GRAVITY_HELP = §8/§enogravity §8- §7Toggle NoGravity
REGION_NO_GRAVITY_ENABLED = §aNoGravity enabled in this region
REGION_NO_GRAVITY_DISABLED = §cNoGravity disabled in this region
REGION_REGION_HELP_UNDO=§8/§eregion undo §8- §7undo the last 20 /testblock or /reset
REGION_REGION_HELP_REDO=§8/§eregion redo §8- §7redo the last 20 §8/§7rg undo
REGION_REGION_HELP_RESTORE=§8/§eregion restore §8- §7Resets the region, without removing your builds

Datei anzeigen

@ -698,6 +698,9 @@ REGION_PROTECT_HELP=§8/§eprotect §8- §7Schütze die Region
REGION_PROTECT_DISABLE=§cBoden Schutz aufgehoben
REGION_PROTECT_ENABLE=§aBoden geschützt
REGION_PROTECT_FALSE_REGION=§cDu befindest dich derzeit in keiner (M)WG-Region
REGION_NO_GRAVITY_HELP = §8/§enogravity §8- §7Toggle NoGravity
REGION_NO_GRAVITY_ENABLED = §aNoGravity aktiviert in dieser Region
REGION_NO_GRAVITY_DISABLED = §cNoGravity deaktiviert in dieser Region
REGION_REGION_HELP_UNDO=§8/§eregion undo §8- §7Mache die letzten 20 /testblock oder /reset rückgängig
REGION_REGION_HELP_REDO=§8/§eregion redo §8- §7Wiederhole die letzten 20 §8/§7rg undo
REGION_REGION_HELP_RESTORE=§8/§eregion restore §8- §7Setzte die Region zurück, ohne das Gebaute zu löschen

Datei anzeigen

@ -0,0 +1,66 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.region.Region;
import de.steamwar.bausystem.region.RegionUtils;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.NoGravityMode;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
@Linked
public class NoGravityCommand extends SWCommand {
public NoGravityCommand() {
super("nogravity");
}
@Register(description = "REGION_NO_GRAVITY_HELP")
public void toggleCommand(@Validator Player p) {
Region region = Region.getRegion(p.getLocation());
if (toggle(region)) {
RegionUtils.actionBar(region, getEnableMessage());
} else {
RegionUtils.actionBar(region, getDisableMessage());
}
}
private String getEnableMessage() {
return "REGION_NO_GRAVITY_ENABLED";
}
private String getDisableMessage() {
return "REGION_NO_GRAVITY_DISABLED";
}
private boolean toggle(Region region) {
switch (region.getPlain(Flag.NO_GRAVITY, NoGravityMode.class)) {
case ACTIVE:
region.set(Flag.NO_GRAVITY, NoGravityMode.INACTIVE);
return false;
default:
case INACTIVE:
region.set(Flag.NO_GRAVITY, NoGravityMode.ACTIVE);
return true;
}
}
}

Datei anzeigen

@ -0,0 +1,64 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.region.Region;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.NoGravityMode;
import de.steamwar.bausystem.utils.ScoreboardElement;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntitySpawnEvent;
@Linked
public class NoGravityListener implements Listener, ScoreboardElement {
private static NoGravityMode getMode(Region region) {
return region.getPlain(Flag.NO_GRAVITY, NoGravityMode.class);
}
@EventHandler
public void onEntitySpawn(EntitySpawnEvent event) {
if (event.getEntityType() != EntityType.PRIMED_TNT) return;
if (getMode(Region.getRegion(event.getLocation())) == NoGravityMode.ACTIVE) {
event.getEntity().setGravity(false);
}
}
@Override
public ScoreboardGroup getGroup() {
return ScoreboardGroup.REGION;
}
@Override
public int order() {
return 4;
}
@Override
public String get(Region region, Player p) {
if (region.get(Flag.NO_GRAVITY) == Flag.NO_GRAVITY.getDefaultValue()) return null;
return "§e" + BauSystem.MESSAGE.parse(Flag.NO_GRAVITY.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.NO_GRAVITY).getChatValue(), p);
}
}

Datei anzeigen

@ -35,6 +35,7 @@ public enum Flag implements EnumDisplay {
FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE),
PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE),
ITEMS("FLAG_ITEMS", ItemMode.class, ItemMode.INACTIVE),
NO_GRAVITY("FLAG_NO_GRAVITY", NoGravityMode.class, NoGravityMode.INACTIVE),
;
@Getter

Datei anzeigen

@ -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 NoGravityMode implements Flag.Value<NoGravityMode> {
ACTIVE("FLAG_NO_GRAVITY_ACTIVE"),
INACTIVE("FLAG_NO_GRAVITY_INACTIVE");
private static NoGravityMode[] values;
private final String chatValue;
@Override
public NoGravityMode[] getValues() {
if (NoGravityMode.values == null) {
NoGravityMode.values = NoGravityMode.values(); //NOSONAR
}
return NoGravityMode.values;
}
@Override
public NoGravityMode getValue() {
return this;
}
@Override
public NoGravityMode getValueOf(final String name) {
try {
return NoGravityMode.valueOf(name.toUpperCase());
} catch (IllegalArgumentException e) {
if (name.equalsIgnoreCase("false")) {
return NoGravityMode.INACTIVE;
}
return NoGravityMode.ACTIVE;
}
}
}