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
2019-11-23 21:36:49 +01:00

118 Zeilen
4.4 KiB
Java

package de.steamwar.bausystem;
import de.steamwar.bausystem.commands.*;
import de.steamwar.bausystem.world.ArenaSection;
import de.steamwar.bausystem.world.RegionListener;
import de.steamwar.bausystem.world.TNTListener;
import de.steamwar.core.CommandRemover;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
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.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
public class BauSystem extends JavaPlugin implements Listener {
private static BauSystem plugin;
private static UUID owner;
private static List<ArenaSection> sections;
public static final String PREFIX = "§eBauSystem§8» §7";
public static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/";
@Override
public void onEnable() {
plugin = this;
try{
owner = UUID.fromString(Bukkit.getWorlds().get(0).getName());
}catch(IllegalArgumentException e){
getLogger().log(Level.SEVERE, "owner is no UUID", e);
Bukkit.shutdown();
return;
}
try {
CommandRemover.removeAll("tp", "gamemode", "time");
CommandInjector.injectCommand(new CommandTeleport());
CommandInjector.injectCommand(new CommandGamemode());
CommandInjector.injectCommand(new CommandTime());
} catch (Exception e) {
getLogger().log(Level.SEVERE, "Failed to replace commands", e);
Bukkit.shutdown();
return;
}
try {
sections = ArenaSection.loadFromFile(new File(Bukkit.getWorldContainer().getPath() + '/' + owner.toString() + "/sections.yml"));
} catch (IOException | InvalidConfigurationException e) {
getLogger().log(Level.SEVERE, "Failed to load sections.yml", e);
Bukkit.shutdown();
return;
}
getCommand("trace").setExecutor(new CommandTrace());
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());
Bukkit.getPluginManager().registerEvents(this, this);
Bukkit.getPluginManager().registerEvents(new RegionListener(), this);
Bukkit.getPluginManager().registerEvents(new TNTListener(), this);
}
public static BauSystem getPlugin(){
return plugin;
}
public static UUID getOwner(){
return owner;
}
public static List<ArenaSection> getSections(){
return sections;
}
public static int getOwnerID(){
return SteamwarUser.get(owner).getId();
}
@EventHandler
public void onDeath(PlayerDeathEvent e) {
e.setDeathMessage(null);
}
@EventHandler
public void onJoin(PlayerLoginEvent e) {
Player p = e.getPlayer();
PermissionAttachment attachment = p.addAttachment(this);
attachment.setPermission("F3NPerm.use", true);
attachment.setPermission("fawe.permpack.basic", true);
attachment.setPermission("worldedit.navigation.jumpto.tool", true);
attachment.setPermission("worldedit.navigation.thru.tool", true);
}
@EventHandler
public void onLeave(PlayerQuitEvent e){
if(Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(e.getPlayer())))
Bukkit.shutdown();
}
}