SteamWar/BauSystem
Archiviert
13
0
Dieses Repository wurde am 2024-08-04 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java

192 Zeilen
7.1 KiB
Java

/*
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/>.
*/
package de.steamwar.bausystem;
import de.steamwar.bausystem.commands.*;
import de.steamwar.bausystem.world.*;
import de.steamwar.core.CommandRemover;
import de.steamwar.core.Core;
import de.steamwar.scoreboard.SWScoreboard;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import org.bukkit.GameRule;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import java.util.UUID;
import java.util.logging.Level;
public class BauSystem extends JavaPlugin implements Listener {
private static BauSystem plugin;
private static UUID owner;
public static final String PREFIX = "§eBauSystem§8» §7";
private BukkitTask autoShutdown;
@Override
public void onEnable() {
plugin = this;
try {
owner = UUID.fromString(Bukkit.getWorlds().get(0).getName());
} catch (IllegalArgumentException e) {
owner = null;
}
try {
CommandRemover.removeAll("tp", "gamemode", "time", "clear");
CommandInjector.injectCommand(new CommandTeleport());
CommandInjector.injectCommand(new CommandGamemode());
CommandInjector.injectCommand(new CommandTime());
CommandInjector.injectCommand(new CommandClear());
} catch (Exception e) {
getLogger().log(Level.SEVERE, "Failed to replace commands", e);
Bukkit.shutdown();
return;
}
getCommand("trace").setExecutor(new CommandTrace());
getCommand("trace").setTabCompleter(new CommandTraceTabCompleter());
getCommand("tpslimit").setExecutor(new CommandTPSLimiter());
getCommand("tpslimit").setTabCompleter(new CommandTPSLimiterTabComplete());
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());
getCommand("freeze").setExecutor(new CommandFreeze());
getCommand("testblock").setExecutor(new CommandTestblock());
getCommand("bau").setExecutor(new CommandBau());
getCommand("bauinfo").setExecutor(new CommandInfo());
getCommand("protect").setExecutor(new CommandProtect());
getCommand("skull").setExecutor(new CommandSkull());
getCommand("loader").setExecutor(new CommandLoader());
getCommand("lockschem").setExecutor(new CommandLockschem());
getCommand("debugstick").setExecutor(new CommandDebugStick());
getCommand("watervision").setExecutor(new CommandGills());
getCommand("detonator").setExecutor(new CommandDetonator());
getCommand("detonator").setTabCompleter(new CommandDetonatorTabCompleter());
getCommand("script").setExecutor(new CommandScript());
Bukkit.getPluginManager().registerEvents(this, this);
Bukkit.getPluginManager().registerEvents(new RegionListener(), this);
Bukkit.getPluginManager().registerEvents(new ScriptListener(), this);
Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this);
Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this);
new AFKStopper();
autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200);
}
public static BauSystem getPlugin() {
return plugin;
}
public static UUID getOwner() {
//Lazy loading to improve startup time of the server in 1.15
if (owner == null) {
try {
owner = SteamwarUser.get(Integer.parseInt(Bukkit.getWorlds().get(0).getName())).getUUID();
} catch (NumberFormatException e) {
Bukkit.shutdown();
throw new SecurityException("owner is not a UserID", e);
}
}
return owner;
}
public static int getOwnerID() {
return SteamwarUser.get(getOwner()).getId();
}
@EventHandler
public void onDeath(PlayerDeathEvent e) {
e.setDeathMessage(null);
}
@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))) {
Bukkit.shutdown();
}
}
@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() < 14) {
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);
}
}