From 4b1f15afc55fc3754c6c010b905107cc84840922 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Apr 2021 15:31:16 +0200 Subject: [PATCH 1/9] Add TimeCommand Add BauSystem.PREFIX Add Permission.hasPermission --- .../src/de/steamwar/bausystem/BauSystem.java | 2 +- .../src/de/steamwar/bausystem/Permission.java | 32 +++++- .../bausystem/features/other/TimeCommand.java | 103 ++++++++++++++++++ 3 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index aca76667..210d5d08 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -30,7 +30,7 @@ public class BauSystem extends JavaPlugin implements Listener { @Getter private static BauSystem instance; - // public static final String PREFIX = "§eBauSystem§8» §7"; + public static final String PREFIX = "§eBauSystem§8» §7"; @Override public void onEnable() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java index 200af31a..48c026cd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java @@ -19,8 +19,34 @@ package de.steamwar.bausystem; +import de.steamwar.bausystem.config.BauServer; +import de.steamwar.sql.BauweltMember; +import lombok.AllArgsConstructor; +import org.bukkit.entity.Player; + +import java.util.function.Predicate; + +@AllArgsConstructor public enum Permission { - WORLD, - WORLDEDIT, - MEMBER + WORLD(BauweltMember::isWorld), + WORLDEDIT(BauweltMember::isWorldEdit), + MEMBER(bauweltMember -> true); + + private Predicate permissionPredicate; + + public boolean hasPermission(Player member) { + if (member.getUniqueId().equals(BauServer.getInstance().getOwner())) + return true; + + BauweltMember bauMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), member.getUniqueId()); + if (bauMember == null) { + return false; + } + + return permissionPredicate.test(bauMember); + } + + public static boolean hasPermission(Player member, Permission permission) { + return permission.hasPermission(member); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java new file mode 100644 index 00000000..b9253d8d --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java @@ -0,0 +1,103 @@ +/* + * 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 . + */ + +package de.steamwar.bausystem.features.other; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +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 org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.List; + +@Linked(LinkageType.COMMAND) +public class TimeCommand extends SWCommand { + + private static List tabCompletions = Arrays.asList("0", "6000", "12000", "18000"); + + public TimeCommand() { + super("time"); + } + + @Register(help = true) + public void genericHelp(Player p, String... args) { + p.sendMessage("§8/§etime §8<§7Zeit 0=Morgen§8, §76000=Mittag§8, §718000=Mitternacht§8> §8- §7Setzt die Zeit auf dem Bau"); + } + + @Register + public void genericCommand(Player p, int time) { + if (!Permission.hasPermission(p, Permission.WORLD)) { + p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht die Zeit ändern"); + return; + } + if (time < 0 || time > 24000) { + p.sendMessage(BauSystem.PREFIX + "§cBitte gib eine Zahl zwischen 0 und 24000 an"); + return; + } + Bukkit.getWorlds().get(0).setTime(time); + } + + @Register + public void genericCommand(Player p, Time time) { + if (!Permission.hasPermission(p, Permission.WORLD)) { + p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht die Zeit ändern"); + return; + } + Bukkit.getWorlds().get(0).setTime(time.getValue()); + } + + @ClassMapper(value = int.class, local = true) + public TypeMapper doubleTypeMapper() { + return SWCommandUtils.createMapper(s -> { + try { + return Integer.parseInt(s); + } catch (NumberFormatException e) { + return 0; + } + }, s -> tabCompletions); + } + + public enum Time { + NIGHT(18000), + DAY(6000), + DAWN(0), + SUNSET(12000), + NACHT(18000), + TAG(6000), + MORGEN(0), + ABEND(12000); + + private int value; + + private Time(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + } + +} From 5e4538023a07281365837ba428a2bdcbba3032b6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Apr 2021 15:32:30 +0200 Subject: [PATCH 2/9] Fix Permission code convention --- BauSystem_Main/src/de/steamwar/bausystem/Permission.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java index 48c026cd..271cfd49 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java @@ -35,8 +35,9 @@ public enum Permission { private Predicate permissionPredicate; public boolean hasPermission(Player member) { - if (member.getUniqueId().equals(BauServer.getInstance().getOwner())) + if (member.getUniqueId().equals(BauServer.getInstance().getOwner())) { return true; + } BauweltMember bauMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), member.getUniqueId()); if (bauMember == null) { From 8548edcebef41f570b662208862b8ae482b0d5bd Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Apr 2021 15:32:47 +0200 Subject: [PATCH 3/9] Fix TimeCommand code convention --- .../src/de/steamwar/bausystem/features/other/TimeCommand.java | 1 - 1 file changed, 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java index b9253d8d..ae0a85b0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java @@ -99,5 +99,4 @@ public class TimeCommand extends SWCommand { return value; } } - } From 829201c5095696b35ccdbe222dec6f22879fcd8a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Apr 2021 15:35:12 +0200 Subject: [PATCH 4/9] Add TeleportCommand --- .../features/other/TeleportCommand.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/other/TeleportCommand.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/TeleportCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/TeleportCommand.java new file mode 100644 index 00000000..ea04c8fd --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/TeleportCommand.java @@ -0,0 +1,49 @@ +/* + * 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 . + */ + +package de.steamwar.bausystem.features.other; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.command.SWCommand; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerTeleportEvent; + +@Linked(LinkageType.COMMAND) +public class TeleportCommand extends SWCommand { + + public TeleportCommand() { + super("teleport", "tp"); + } + + @Register(help = true) + public void genericHelp(Player p, String... args) { + p.sendMessage("§8/§etp §8[§7Player§8] §8- §7Teleportiere dich zu einem Spieler"); + } + + @Register + public void genericCommand(Player p, Player target) { + if (p.getUniqueId().equals(target.getUniqueId())) { + p.sendMessage(BauSystem.PREFIX + "§cSei eins mit dir selbst!"); + return; + } + p.teleport(target, PlayerTeleportEvent.TeleportCause.COMMAND); + } +} From f39572d176153ee01887225847df3e080e45e41d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Apr 2021 15:36:26 +0200 Subject: [PATCH 5/9] Add WorldSpawnCommand --- .../features/other/WorldSpawnCommand.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/other/WorldSpawnCommand.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/WorldSpawnCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/WorldSpawnCommand.java new file mode 100644 index 00000000..0988fd94 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/WorldSpawnCommand.java @@ -0,0 +1,48 @@ +/* + * 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 . + */ + +package de.steamwar.bausystem.features.other; + +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.command.SWCommand; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerTeleportEvent; + +@Linked(LinkageType.COMMAND) +public class WorldSpawnCommand extends SWCommand { + + private final World WORLD = Bukkit.getWorlds().get(0); + + public WorldSpawnCommand() { + super("worldspawn"); + } + + @Register(help = true) + public void genericHelp(Player p, String... args) { + p.sendMessage("§8/§eworldspawn §8- §7Teleportiere dich zum Spawn"); + } + + @Register + public void genericCommand(Player p) { + p.teleport(WORLD.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.COMMAND); + } +} From a7fbefbef487b0e257ecd71573efa412eeb68b87 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 17 Apr 2021 15:37:51 +0200 Subject: [PATCH 6/9] Add SpeedCommand.java --- .../bausystem/features/util/SpeedCommand.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java new file mode 100644 index 00000000..7fe2a530 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java @@ -0,0 +1,37 @@ +package de.steamwar.bausystem.features.util; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.command.SWCommand; +import org.bukkit.entity.Player; + +@Linked(LinkageType.COMMAND) +public class SpeedCommand extends SWCommand { + + public SpeedCommand() { + super("speed"); + } + + @Register(help = true) + public void genericHelp(Player p, String[] args) { + p.sendMessage("§8/§espeed §8[§e1§8-§e10§8] §8- §7Setzte deine Flug- und Laufgeschindigkeit."); + p.sendMessage(BauSystem.PREFIX + "Aktuelle geschwindigkeit: §e" + p.getFlySpeed() * 10F); + } + + @Register + public void speedCommand(Player p, float speed) { + speed = speed / 10F; + if(speed < -1F) { + p.sendMessage(BauSystem.PREFIX + "§c" + speed + " ist zu klein"); + return; + } else if(speed > 1F) { + p.sendMessage(BauSystem.PREFIX + "§c" + speed + " ist zu hoch"); + return; + } else { + p.setFlySpeed(speed); + p.setWalkSpeed(speed); + p.sendMessage(BauSystem.PREFIX + "Aktuelle geschwindigkeit: §e" + p.getFlySpeed() * 10F); + } + } +} From cce79ebd52adb2fafeacaecf5185dac075ceeb04 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 17 Apr 2021 15:38:12 +0200 Subject: [PATCH 7/9] Simplify If --- .../src/de/steamwar/bausystem/features/util/SpeedCommand.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java index 7fe2a530..d8e851e0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java @@ -24,10 +24,8 @@ public class SpeedCommand extends SWCommand { speed = speed / 10F; if(speed < -1F) { p.sendMessage(BauSystem.PREFIX + "§c" + speed + " ist zu klein"); - return; } else if(speed > 1F) { p.sendMessage(BauSystem.PREFIX + "§c" + speed + " ist zu hoch"); - return; } else { p.setFlySpeed(speed); p.setWalkSpeed(speed); From b9801d4a94026e1f4308eca0eaa10f9cc60c0820 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 17 Apr 2021 15:40:58 +0200 Subject: [PATCH 8/9] Fix SpeedCommand copyright --- .../bausystem/features/util/SpeedCommand.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java index d8e851e0..7c2e42e6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java @@ -1,3 +1,22 @@ +/* + * 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 . + */ + package de.steamwar.bausystem.features.util; import de.steamwar.bausystem.BauSystem; @@ -22,9 +41,9 @@ public class SpeedCommand extends SWCommand { @Register public void speedCommand(Player p, float speed) { speed = speed / 10F; - if(speed < -1F) { + if (speed < -1F) { p.sendMessage(BauSystem.PREFIX + "§c" + speed + " ist zu klein"); - } else if(speed > 1F) { + } else if (speed > 1F) { p.sendMessage(BauSystem.PREFIX + "§c" + speed + " ist zu hoch"); } else { p.setFlySpeed(speed); From 0ddcc398ccc940b018501287f831f940d586711e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 17 Apr 2021 15:43:28 +0200 Subject: [PATCH 9/9] Add Copyright to SpeedCommand.java --- .../bausystem/features/util/SpeedCommand.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java index d8e851e0..7c2e42e6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SpeedCommand.java @@ -1,3 +1,22 @@ +/* + * 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 . + */ + package de.steamwar.bausystem.features.util; import de.steamwar.bausystem.BauSystem; @@ -22,9 +41,9 @@ public class SpeedCommand extends SWCommand { @Register public void speedCommand(Player p, float speed) { speed = speed / 10F; - if(speed < -1F) { + if (speed < -1F) { p.sendMessage(BauSystem.PREFIX + "§c" + speed + " ist zu klein"); - } else if(speed > 1F) { + } else if (speed > 1F) { p.sendMessage(BauSystem.PREFIX + "§c" + speed + " ist zu hoch"); } else { p.setFlySpeed(speed);