Merge remote-tracking branch 'origin/master'
# Conflicts: # BauSystem_Main/src/de/steamwar/bausystem/Permission.java # BauSystem_Main/src/de/steamwar/bausystem/features/util/NightVisionCommand.java # BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java
Dieser Commit ist enthalten in:
Commit
5bc1bc544a
@ -21,18 +21,31 @@ package de.steamwar.bausystem;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.config.BauServer;
|
import de.steamwar.bausystem.config.BauServer;
|
||||||
import de.steamwar.sql.BauweltMember;
|
import de.steamwar.sql.BauweltMember;
|
||||||
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@RequiredArgsConstructor
|
||||||
public enum Permission {
|
public enum Permission {
|
||||||
WORLD(BauweltMember::isWorld),
|
|
||||||
WORLDEDIT(BauweltMember::isWorldEdit),
|
WORLD(BauweltMember::isWorld, (player, target) -> {
|
||||||
|
target.setWorld(!target.isWorld());
|
||||||
|
sendMessages(player, target.isWorld(), target, "Einstellungen vornehmen");
|
||||||
|
}),
|
||||||
|
WORLDEDIT(BauweltMember::isWorldEdit, (player, target) -> {
|
||||||
|
target.setWorldEdit(!target.isWorldEdit());
|
||||||
|
sendMessages(player, target.isWorldEdit(), target, "WorldEdit verwenden");
|
||||||
|
}),
|
||||||
MEMBER(bauweltMember -> true);
|
MEMBER(bauweltMember -> true);
|
||||||
|
|
||||||
private Predicate<BauweltMember> permissionPredicate;
|
private final Predicate<BauweltMember> permissionPredicate;
|
||||||
|
private BiConsumer<Player, BauweltMember> permissionChange = (player, bauweltMember) -> {};
|
||||||
|
|
||||||
public boolean hasPermission(Player member) {
|
public boolean hasPermission(Player member) {
|
||||||
if (member.getUniqueId().equals(BauServer.getInstance().getOwner())) {
|
if (member.getUniqueId().equals(BauServer.getInstance().getOwner())) {
|
||||||
@ -50,4 +63,28 @@ public enum Permission {
|
|||||||
public static boolean hasPermission(Player member, Permission permission) {
|
public static boolean hasPermission(Player member, Permission permission) {
|
||||||
return permission.hasPermission(member);
|
return permission.hasPermission(member);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void sendMessages(Player player, boolean ableTo, BauweltMember target, String what) {
|
||||||
|
Player targetPlayer = Bukkit.getPlayer(SteamwarUser.get(target.getMemberID()).getUUID());
|
||||||
|
if (targetPlayer != null) {
|
||||||
|
if (ableTo) {
|
||||||
|
targetPlayer.sendMessage(BauSystem.PREFIX + "§aDu kannst nun auf der Welt von §6" + player.getName() + "§a " + what);
|
||||||
|
} else {
|
||||||
|
targetPlayer.sendMessage(BauSystem.PREFIX + "§cDu kannst nun nicht mehr auf der Welt von §6" + player.getName() + "§c " + what);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ableTo) {
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§aDer Spieler darf nun " + what);
|
||||||
|
} else {
|
||||||
|
player.sendMessage(BauSystem.PREFIX + "§cDer Spieler darf nun nicht mehr " + what);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggle(Player player, BauweltMember target) {
|
||||||
|
permissionChange.accept(player, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void toggle(Player player, BauweltMember target, Permission permission) {
|
||||||
|
permission.toggle(player, target);
|
||||||
|
}
|
||||||
}
|
}
|
133
BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauCommand.java
Normale Datei
133
BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauCommand.java
Normale Datei
@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
* 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.bau;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.Permission;
|
||||||
|
import de.steamwar.bausystem.config.BauServer;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.command.SWCommand;
|
||||||
|
import de.steamwar.command.SWCommandUtils;
|
||||||
|
import de.steamwar.command.TypeMapper;
|
||||||
|
import de.steamwar.sql.BauweltMember;
|
||||||
|
import de.steamwar.sql.SteamwarUser;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Linked(LinkageType.COMMAND)
|
||||||
|
public class BauCommand extends SWCommand {
|
||||||
|
|
||||||
|
public BauCommand() {
|
||||||
|
super("bau", "b", "gs");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register(help = true)
|
||||||
|
public void genericHelp(Player p, String... args) {
|
||||||
|
p.sendMessage("§8/§ebau togglewe §8[§7Player§8] §8- §7Editiere die WorldEdit Rechte eines Spielers");
|
||||||
|
p.sendMessage("§8/§ebau toggleworld §8[§7Player§8] §8- §7Editiere die Werlt Rechte eines Spielers");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register("info")
|
||||||
|
public void infoCommand(Player p) {
|
||||||
|
// TODO: Implement this
|
||||||
|
// CommandInfo.sendBauInfo(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register("togglewe")
|
||||||
|
public void toggleWECommand(Player p, SteamwarUser user) {
|
||||||
|
if (!permissionCheck(p)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onToggleWE(p, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register("toggleworld")
|
||||||
|
public void toggleWorldCommand(Player p, SteamwarUser user) {
|
||||||
|
if (!permissionCheck(p)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onToggleWorld(p, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onToggleWE(Player p, SteamwarUser id) {
|
||||||
|
if (negativeToggleCheck(p, id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BauweltMember target = BauweltMember.getBauMember(BauServer.getInstance().getOwnerID(), id.getId());
|
||||||
|
Permission.WORLDEDIT.toggle(p, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onToggleWorld(Player p, SteamwarUser id) {
|
||||||
|
if (negativeToggleCheck(p, id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BauweltMember target = BauweltMember.getBauMember(BauServer.getInstance().getOwnerID(), id.getId());
|
||||||
|
Permission.WORLD.toggle(p, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean negativeToggleCheck(Player p, SteamwarUser id) {
|
||||||
|
if (id == null) {
|
||||||
|
p.sendMessage(BauSystem.PREFIX + "§cUnbekannter Spieler");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
BauweltMember target = BauweltMember.getBauMember(BauServer.getInstance().getOwnerID(), id.getId());
|
||||||
|
if (target == null) {
|
||||||
|
p.sendMessage(BauSystem.PREFIX + "§cDer Spieler ist kein Mitglied deiner Welt!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean permissionCheck(Player p) {
|
||||||
|
if (!BauServer.getInstance().getOwner().equals(p.getUniqueId())) {
|
||||||
|
p.sendMessage(BauSystem.PREFIX + "§cDies ist nicht deine Welt!");
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ClassMapper(value = SteamwarUser.class, local = true)
|
||||||
|
private TypeMapper<SteamwarUser> steamwarUserTypeMapper() {
|
||||||
|
return SWCommandUtils.createMapper(s -> BauweltMember.getMembers(BauServer.getInstance().getOwnerID())
|
||||||
|
.stream()
|
||||||
|
.map(m -> SteamwarUser.get(m.getMemberID()))
|
||||||
|
.filter(u -> u.getUserName().equals(s))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null),
|
||||||
|
(c, s) -> {
|
||||||
|
if (!(c instanceof Player)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Player p = (Player) c;
|
||||||
|
return BauweltMember.getMembers(SteamwarUser.get(p.getUniqueId()).getId())
|
||||||
|
.stream()
|
||||||
|
.map(m -> SteamwarUser.get(m.getMemberID()).getUserName())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -31,7 +31,7 @@ import org.bukkit.potion.PotionEffectType;
|
|||||||
@Linked(LinkageType.COMMAND)
|
@Linked(LinkageType.COMMAND)
|
||||||
public class NightVisionCommand extends SWCommand {
|
public class NightVisionCommand extends SWCommand {
|
||||||
|
|
||||||
protected NightVisionCommand() {
|
public NightVisionCommand() {
|
||||||
super("nightvision", "nv", "light");
|
super("nightvision", "nv", "light");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* 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.world;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
|
||||||
|
@Linked(LinkageType.LISTENER)
|
||||||
|
public class AFKStopperListener implements Listener {
|
||||||
|
|
||||||
|
private static final String afkWarning = BauSystem.PREFIX + "§cDieser Server wird bei weiterer Inaktivität in einer Minute gestoppt";
|
||||||
|
|
||||||
|
private int minutesAfk;
|
||||||
|
|
||||||
|
public AFKStopperListener() {
|
||||||
|
minutesAfk = 0;
|
||||||
|
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
|
||||||
|
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
||||||
|
switch (minutesAfk) {
|
||||||
|
case 5:
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
|
p.kickPlayer("§cAuf diesem Server ist seit 5 Minuten nichts passiert.");
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
Bukkit.broadcastMessage(afkWarning);
|
||||||
|
default:
|
||||||
|
minutesAfk++;
|
||||||
|
}
|
||||||
|
}, 1200, 1200); //every minute
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
|
minutesAfk = 0;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* 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.world;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.core.Core;
|
||||||
|
import de.steamwar.scoreboard.SWScoreboard;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.GameRule;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
@Linked(LinkageType.LISTENER)
|
||||||
|
public class AutoShutdownListener implements Listener {
|
||||||
|
|
||||||
|
private BukkitTask autoShutdown;
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onJoin(PlayerLoginEvent e) {
|
||||||
|
if (autoShutdown != null) {
|
||||||
|
autoShutdown.cancel();
|
||||||
|
autoShutdown = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player p = e.getPlayer();
|
||||||
|
p.setOp(true);
|
||||||
|
|
||||||
|
if (Core.getVersion() == 15) {
|
||||||
|
Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onLeave(PlayerQuitEvent e) {
|
||||||
|
Player p = e.getPlayer();
|
||||||
|
SWScoreboard.removeScoreboard(p);
|
||||||
|
if (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(p))) {
|
||||||
|
if (autoShutdown != null) {
|
||||||
|
autoShutdown.cancel();
|
||||||
|
}
|
||||||
|
TPSLimitUtils.setTPS(20.0);
|
||||||
|
autoShutdown = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), new Runnable() {
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (count >= 300) {
|
||||||
|
Bukkit.shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
try {
|
||||||
|
if (RamUsage.getUsage() > 0.8) {
|
||||||
|
Bukkit.shutdown();
|
||||||
|
}
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
Bukkit.getLogger().log(Level.WARNING, throwable.getMessage(), throwable);
|
||||||
|
Bukkit.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 20, 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* 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.world;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.sql.Schematic;
|
||||||
|
import de.steamwar.sql.SchematicType;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Linked(LinkageType.LISTENER)
|
||||||
|
public class ClipboardListener implements Listener {
|
||||||
|
|
||||||
|
private static final String CLIPBOARD_SCHEMNAME = "//copy";
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onLogin(PlayerJoinEvent e) {
|
||||||
|
try {
|
||||||
|
Schematic schematic = Schematic.getSchemFromDB(CLIPBOARD_SCHEMNAME, e.getPlayer().getUniqueId());
|
||||||
|
if (schematic != null) {
|
||||||
|
schematic.loadToPlayer(e.getPlayer());
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
// ignore cause players do all kind of stuff with schematics.... like massively oversized schems
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onLogout(PlayerQuitEvent e) {
|
||||||
|
UUID playerUUID = e.getPlayer().getUniqueId();
|
||||||
|
Schematic schematic = Schematic.getSchemFromDB(CLIPBOARD_SCHEMNAME, playerUUID);
|
||||||
|
boolean newSchem = false;
|
||||||
|
if (schematic == null) {
|
||||||
|
Schematic.createSchem(CLIPBOARD_SCHEMNAME, playerUUID, "", SchematicType.Normal);
|
||||||
|
schematic = Schematic.getSchemFromDB(CLIPBOARD_SCHEMNAME, playerUUID);
|
||||||
|
newSchem = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
schematic.saveFromPlayer(e.getPlayer());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (newSchem) {
|
||||||
|
schematic.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* 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.world;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.core.Core;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
@Linked(LinkageType.LISTENER)
|
||||||
|
public class InventoryListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryClick(InventoryClickEvent e) {
|
||||||
|
ItemStack stack = e.getCursor();
|
||||||
|
if (stack == null || !stack.hasItemMeta()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
assert stack.getItemMeta() != null;
|
||||||
|
if (stack.getItemMeta().hasEnchants()) {
|
||||||
|
for (Enchantment en : Enchantment.values()) {
|
||||||
|
if (stack.getEnchantmentLevel(en) > en.getMaxLevel()) {
|
||||||
|
stack.removeEnchantment(en);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Material material = stack.getType();
|
||||||
|
if (material == Material.POTION || material == Material.SPLASH_POTION || material == Material.LINGERING_POTION) {
|
||||||
|
stack.setType(Material.MILK_BUCKET);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Core.getVersion() < 15) {
|
||||||
|
e.setCurrentItem(stack);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stack.getItemMeta().hasAttributeModifiers()) {
|
||||||
|
ItemMeta meta = stack.getItemMeta();
|
||||||
|
for (Attribute a : Attribute.values()) {
|
||||||
|
meta.removeAttributeModifier(a);
|
||||||
|
}
|
||||||
|
stack.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
e.setCurrentItem(stack);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* 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.world;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.SWUtils;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.ItemFrame;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
@Linked(LinkageType.LISTENER)
|
||||||
|
public class ItemFrameListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||||
|
if (!(event.getDamager() instanceof Player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!(event.getEntity() instanceof ItemFrame)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.setCancelled(true);
|
||||||
|
ItemFrame itemFrame = (ItemFrame) event.getEntity();
|
||||||
|
ItemStack itemStack = itemFrame.getItem();
|
||||||
|
if (itemStack.getType() != Material.AIR) {
|
||||||
|
SWUtils.giveItemToPlayer((Player) event.getDamager(), itemFrame.getItem());
|
||||||
|
itemFrame.setItem(null);
|
||||||
|
} else {
|
||||||
|
itemFrame.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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.world;
|
||||||
|
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class RamUsage {
|
||||||
|
|
||||||
|
public double getUsage() {
|
||||||
|
try {
|
||||||
|
long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize();
|
||||||
|
long freeMemory = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getFreePhysicalMemorySize();
|
||||||
|
return (memorySize - freeMemory) / (double) memorySize;
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
Bukkit.getLogger().log(Level.WARNING, throwable.getMessage(), throwable);
|
||||||
|
return 1D;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -59,7 +59,7 @@ public class LinkageUtils {
|
|||||||
Set<LinkageType> linkageTypeSet = new HashSet<>();
|
Set<LinkageType> linkageTypeSet = new HashSet<>();
|
||||||
for (Linked linked : linkages) {
|
for (Linked linked : linkages) {
|
||||||
if (linked == null) {
|
if (linked == null) {
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
LinkageType linkageType = linked.value();
|
LinkageType linkageType = linked.value();
|
||||||
if (linkageType.getLinkagePredicate().test(clazz)) {
|
if (linkageType.getLinkagePredicate().test(clazz)) {
|
||||||
|
@ -24,13 +24,13 @@ import org.atteo.classindex.IndexAnnotated;
|
|||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
@IndexAnnotated
|
@IndexAnnotated
|
||||||
@Retention(RetentionPolicy.CLASS)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ElementType.TYPE})
|
@Target({ElementType.TYPE})
|
||||||
@Repeatable(Linked.Linkages.class)
|
@Repeatable(Linked.Linkages.class)
|
||||||
public @interface Linked {
|
public @interface Linked {
|
||||||
LinkageType value();
|
LinkageType value();
|
||||||
|
|
||||||
@Retention(RetentionPolicy.CLASS)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ElementType.TYPE})
|
@Target({ElementType.TYPE})
|
||||||
@interface Linkages {
|
@interface Linkages {
|
||||||
@SuppressWarnings("unused") Linked[] value() default {};
|
@SuppressWarnings("unused") Linked[] value() default {};
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren