2020-08-26 18:48:57 +02:00
|
|
|
/*
|
|
|
|
This file is a part of the SteamWar software.
|
|
|
|
|
|
|
|
Copyright (C) 2020 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/>.
|
|
|
|
*/
|
|
|
|
|
2019-06-11 07:05:05 +02:00
|
|
|
package de.steamwar.bausystem;
|
|
|
|
|
|
|
|
import de.steamwar.bausystem.commands.*;
|
2020-09-06 01:52:19 +02:00
|
|
|
import de.steamwar.bausystem.world.*;
|
2019-11-10 17:29:01 +01:00
|
|
|
import de.steamwar.core.CommandRemover;
|
2020-04-08 17:06:01 +02:00
|
|
|
import de.steamwar.core.Core;
|
2020-01-08 23:50:07 +01:00
|
|
|
import de.steamwar.scoreboard.SWScoreboard;
|
2019-11-10 17:29:01 +01:00
|
|
|
import de.steamwar.sql.SteamwarUser;
|
2019-06-11 07:05:05 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2020-07-26 23:00:03 +02:00
|
|
|
import org.bukkit.GameRule;
|
2020-03-21 20:01:00 +01:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.attribute.Attribute;
|
|
|
|
import org.bukkit.enchantments.Enchantment;
|
2019-06-11 07:05:05 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
2020-03-21 20:01:00 +01:00
|
|
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
2019-09-18 19:19:54 +02:00
|
|
|
import org.bukkit.event.player.PlayerLoginEvent;
|
2019-06-13 10:22:07 +02:00
|
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
2020-03-21 20:01:00 +01:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
2019-06-11 07:05:05 +02:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2020-01-19 07:01:07 +01:00
|
|
|
import org.bukkit.scheduler.BukkitTask;
|
2019-06-11 07:05:05 +02:00
|
|
|
|
|
|
|
import java.util.UUID;
|
2019-09-03 19:56:41 +02:00
|
|
|
import java.util.logging.Level;
|
2019-06-11 07:05:05 +02:00
|
|
|
|
|
|
|
public class BauSystem extends JavaPlugin implements Listener {
|
|
|
|
private static BauSystem plugin;
|
|
|
|
private static UUID owner;
|
|
|
|
public static final String PREFIX = "§eBauSystem§8» §7";
|
|
|
|
|
2020-01-19 07:01:07 +01:00
|
|
|
private BukkitTask autoShutdown;
|
|
|
|
|
2019-06-11 07:05:05 +02:00
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
|
|
|
plugin = this;
|
|
|
|
|
2020-11-17 09:39:03 +01:00
|
|
|
try {
|
2020-12-11 14:33:00 +01:00
|
|
|
owner = UUID.fromString(Bukkit.getWorlds().get(0).getName());
|
2020-11-17 09:39:03 +01:00
|
|
|
} catch (IllegalArgumentException e) {
|
2020-12-11 14:33:00 +01:00
|
|
|
owner = null;
|
2019-06-11 07:05:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2020-01-07 16:38:45 +01:00
|
|
|
CommandRemover.removeAll("tp", "gamemode", "time", "clear");
|
2019-11-10 17:29:01 +01:00
|
|
|
CommandInjector.injectCommand(new CommandTeleport());
|
|
|
|
CommandInjector.injectCommand(new CommandGamemode());
|
|
|
|
CommandInjector.injectCommand(new CommandTime());
|
2020-01-07 16:38:45 +01:00
|
|
|
CommandInjector.injectCommand(new CommandClear());
|
2019-06-11 07:05:05 +02:00
|
|
|
} catch (Exception e) {
|
2019-09-03 19:56:41 +02:00
|
|
|
getLogger().log(Level.SEVERE, "Failed to replace commands", e);
|
2019-06-11 07:05:05 +02:00
|
|
|
Bukkit.shutdown();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
getCommand("trace").setExecutor(new CommandTrace());
|
2020-07-18 23:01:50 +02:00
|
|
|
getCommand("trace").setTabCompleter(new CommandTraceTabCompleter());
|
2020-11-15 13:12:52 +01:00
|
|
|
getCommand("tpslimit").setExecutor(new CommandTPSLimiter());
|
|
|
|
getCommand("tpslimit").setTabCompleter(new CommandTPSLimiterTabComplete());
|
2019-06-11 07:05:05 +02:00
|
|
|
getCommand("nightvision").setExecutor(new CommandNV());
|
|
|
|
getCommand("reset").setExecutor(new CommandReset());
|
|
|
|
getCommand("speed").setExecutor(new CommandSpeed());
|
|
|
|
getCommand("tnt").setExecutor(new CommandTNT());
|
|
|
|
getCommand("fire").setExecutor(new CommandFire());
|
2019-10-24 18:47:23 +02:00
|
|
|
getCommand("freeze").setExecutor(new CommandFreeze());
|
2019-06-11 07:05:05 +02:00
|
|
|
getCommand("testblock").setExecutor(new CommandTestblock());
|
2019-06-13 10:22:07 +02:00
|
|
|
getCommand("bau").setExecutor(new CommandBau());
|
2019-06-14 08:43:40 +02:00
|
|
|
getCommand("bauinfo").setExecutor(new CommandInfo());
|
2019-07-11 18:27:46 +02:00
|
|
|
getCommand("protect").setExecutor(new CommandProtect());
|
2019-07-14 20:07:46 +02:00
|
|
|
getCommand("skull").setExecutor(new CommandSkull());
|
2019-09-03 19:56:41 +02:00
|
|
|
getCommand("loader").setExecutor(new CommandLoader());
|
2019-11-23 21:36:49 +01:00
|
|
|
getCommand("lockschem").setExecutor(new CommandLockschem());
|
2020-07-04 09:29:04 +02:00
|
|
|
getCommand("debugstick").setExecutor(new CommandDebugStick());
|
2020-06-30 07:34:19 +02:00
|
|
|
getCommand("watervision").setExecutor(new CommandGills());
|
2020-09-06 01:52:19 +02:00
|
|
|
getCommand("detonator").setExecutor(new CommandDetonator());
|
|
|
|
getCommand("detonator").setTabCompleter(new CommandDetonatorTabCompleter());
|
2020-12-30 12:13:14 +01:00
|
|
|
getCommand("script").setExecutor(new CommandScript());
|
2019-06-11 07:05:05 +02:00
|
|
|
|
|
|
|
Bukkit.getPluginManager().registerEvents(this, this);
|
|
|
|
Bukkit.getPluginManager().registerEvents(new RegionListener(), this);
|
2020-12-10 20:16:07 +01:00
|
|
|
Bukkit.getPluginManager().registerEvents(new ScriptListener(), this);
|
2020-01-07 23:22:31 +01:00
|
|
|
Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this);
|
2020-09-06 21:04:07 +02:00
|
|
|
Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this);
|
2020-01-27 07:04:47 +01:00
|
|
|
new AFKStopper();
|
2020-01-19 07:01:07 +01:00
|
|
|
|
|
|
|
autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200);
|
2019-06-11 07:05:05 +02:00
|
|
|
}
|
|
|
|
|
2020-11-17 09:39:03 +01:00
|
|
|
public static BauSystem getPlugin() {
|
2019-06-11 07:05:05 +02:00
|
|
|
return plugin;
|
|
|
|
}
|
2020-11-17 09:39:03 +01:00
|
|
|
|
|
|
|
public static UUID getOwner() {
|
2020-09-22 17:40:43 +02:00
|
|
|
//Lazy loading to improve startup time of the server in 1.15
|
2020-11-17 09:39:03 +01:00
|
|
|
if (owner == null) {
|
|
|
|
try {
|
2020-09-22 17:40:43 +02:00
|
|
|
owner = SteamwarUser.get(Integer.parseInt(Bukkit.getWorlds().get(0).getName())).getUUID();
|
2020-11-17 09:39:03 +01:00
|
|
|
} catch (NumberFormatException e) {
|
2020-09-22 17:40:43 +02:00
|
|
|
Bukkit.shutdown();
|
|
|
|
throw new SecurityException("owner is not a UserID", e);
|
|
|
|
}
|
|
|
|
}
|
2019-06-11 07:05:05 +02:00
|
|
|
return owner;
|
|
|
|
}
|
2020-11-17 09:39:03 +01:00
|
|
|
|
|
|
|
public static int getOwnerID() {
|
2020-09-22 17:40:43 +02:00
|
|
|
return SteamwarUser.get(getOwner()).getId();
|
2019-06-13 10:22:07 +02:00
|
|
|
}
|
2019-06-11 07:05:05 +02:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void onDeath(PlayerDeathEvent e) {
|
|
|
|
e.setDeathMessage(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
2019-09-18 19:19:54 +02:00
|
|
|
public void onJoin(PlayerLoginEvent e) {
|
2020-11-17 09:39:03 +01:00
|
|
|
if (autoShutdown != null) {
|
2020-01-19 07:01:07 +01:00
|
|
|
autoShutdown.cancel();
|
|
|
|
autoShutdown = null;
|
|
|
|
}
|
|
|
|
|
2019-06-11 07:05:05 +02:00
|
|
|
Player p = e.getPlayer();
|
2020-02-25 18:04:38 +01:00
|
|
|
p.setOp(true);
|
2020-07-07 21:21:00 +02:00
|
|
|
|
2020-08-30 07:13:11 +02:00
|
|
|
if (Core.getVersion() == 15)
|
2020-07-27 06:53:08 +02:00
|
|
|
Bukkit.getWorlds().get(0).setGameRule(GameRule.REDUCED_DEBUG_INFO, false);
|
2019-06-11 07:05:05 +02:00
|
|
|
}
|
2019-06-13 10:22:07 +02:00
|
|
|
|
|
|
|
@EventHandler
|
2020-01-07 23:22:31 +01:00
|
|
|
public void onLeave(PlayerQuitEvent e) {
|
2020-07-26 16:29:16 +02:00
|
|
|
Player p = e.getPlayer();
|
|
|
|
SWScoreboard.removeScoreboard(p);
|
|
|
|
if (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(p))) {
|
2019-06-13 10:22:07 +02:00
|
|
|
Bukkit.shutdown();
|
2020-07-07 21:21:00 +02:00
|
|
|
}
|
2019-06-13 10:22:07 +02:00
|
|
|
}
|
2020-11-17 09:39:03 +01:00
|
|
|
|
2020-03-21 20:01:00 +01:00
|
|
|
@EventHandler
|
2020-11-17 09:39:03 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2020-04-08 17:06:01 +02:00
|
|
|
|
|
|
|
Material material = stack.getType();
|
2020-07-26 16:29:16 +02:00
|
|
|
if (material == Material.POTION || material == Material.SPLASH_POTION || material == Material.LINGERING_POTION) {
|
2020-04-08 17:06:01 +02:00
|
|
|
stack.setType(Material.MILK_BUCKET);
|
2020-07-26 16:29:16 +02:00
|
|
|
}
|
2020-04-08 17:06:01 +02:00
|
|
|
|
2020-11-17 09:39:03 +01:00
|
|
|
if (Core.getVersion() < 14) {
|
2020-04-08 17:06:01 +02:00
|
|
|
e.setCurrentItem(stack);
|
2020-11-17 09:39:03 +01:00
|
|
|
return;
|
2020-04-08 17:06:01 +02:00
|
|
|
}
|
|
|
|
|
2020-11-17 09:39:03 +01:00
|
|
|
if (stack.getItemMeta().hasAttributeModifiers()) {
|
|
|
|
ItemMeta meta = stack.getItemMeta();
|
|
|
|
for (Attribute a : Attribute.values()) {
|
2020-07-26 16:29:16 +02:00
|
|
|
meta.removeAttributeModifier(a);
|
|
|
|
}
|
2020-11-17 09:39:03 +01:00
|
|
|
stack.setItemMeta(meta);
|
|
|
|
}
|
|
|
|
e.setCurrentItem(stack);
|
|
|
|
}
|
2019-06-11 07:05:05 +02:00
|
|
|
}
|