2019-06-11 07:05:05 +02:00
|
|
|
package de.steamwar.bausystem;
|
|
|
|
|
|
|
|
import de.steamwar.bausystem.commands.*;
|
2019-06-13 10:22:07 +02:00
|
|
|
import de.steamwar.bausystem.world.ArenaSection;
|
2020-01-07 23:22:31 +01:00
|
|
|
import de.steamwar.bausystem.world.BauScoreboard;
|
2019-06-13 10:22:07 +02:00
|
|
|
import de.steamwar.bausystem.world.RegionListener;
|
2019-09-03 19:56:41 +02:00
|
|
|
import de.steamwar.bausystem.world.TNTListener;
|
2019-11-10 17:29:01 +01:00
|
|
|
import de.steamwar.core.CommandRemover;
|
|
|
|
import de.steamwar.sql.SteamwarUser;
|
2019-06-11 07:05:05 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2019-06-13 10:22:07 +02:00
|
|
|
import org.bukkit.configuration.InvalidConfigurationException;
|
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;
|
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;
|
2019-06-11 07:05:05 +02:00
|
|
|
import org.bukkit.permissions.PermissionAttachment;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2019-06-13 10:22:07 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.List;
|
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;
|
2019-06-13 10:22:07 +02:00
|
|
|
private static List<ArenaSection> sections;
|
2019-06-11 07:05:05 +02:00
|
|
|
public static final String PREFIX = "§eBauSystem§8» §7";
|
2019-06-20 12:13:30 +02:00
|
|
|
public static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/";
|
2019-06-11 07:05:05 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
|
|
|
plugin = this;
|
|
|
|
|
2019-12-31 12:58:55 +01:00
|
|
|
String worldName = Bukkit.getWorlds().get(0).getName();
|
2019-06-11 07:05:05 +02:00
|
|
|
try{
|
2019-12-31 12:58:55 +01:00
|
|
|
owner = UUID.fromString(worldName);
|
2019-12-31 13:02:15 +01:00
|
|
|
sections = ArenaSection.loadFromFile(new File(Bukkit.getWorldContainer().getPath() + '/' + owner.toString() + "/sections.yml"));
|
2019-06-11 07:05:05 +02:00
|
|
|
}catch(IllegalArgumentException e){
|
2019-12-31 12:58:55 +01:00
|
|
|
try{
|
2019-12-31 13:02:15 +01:00
|
|
|
int ownerID = Integer.parseInt(worldName);
|
|
|
|
owner = SteamwarUser.get(ownerID).getUUID();
|
|
|
|
sections = ArenaSection.loadFromFile(new File(Bukkit.getWorldContainer().getPath() + '/' + ownerID + "/sections.yml"));
|
|
|
|
}catch(NumberFormatException | IOException | InvalidConfigurationException ex){
|
|
|
|
getLogger().log(Level.SEVERE, "owner is no UUID / failed to load sections.yml", e);
|
2019-12-31 12:58:55 +01:00
|
|
|
Bukkit.shutdown();
|
|
|
|
return;
|
|
|
|
}
|
2019-12-31 13:02:15 +01:00
|
|
|
} catch (InvalidConfigurationException | IOException e) {
|
|
|
|
getLogger().log(Level.SEVERE, "Failed to load sections.yml", e);
|
|
|
|
Bukkit.shutdown();
|
|
|
|
return;
|
2019-06-11 07:05:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2019-10-24 18:47:23 +02:00
|
|
|
CommandRemover.removeAll("tp", "gamemode", "time");
|
2019-11-10 17:29:01 +01:00
|
|
|
CommandInjector.injectCommand(new CommandTeleport());
|
|
|
|
CommandInjector.injectCommand(new CommandGamemode());
|
|
|
|
CommandInjector.injectCommand(new CommandTime());
|
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());
|
|
|
|
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());
|
2019-06-11 07:05:05 +02:00
|
|
|
|
|
|
|
Bukkit.getPluginManager().registerEvents(this, this);
|
|
|
|
Bukkit.getPluginManager().registerEvents(new RegionListener(), this);
|
2019-09-03 19:56:41 +02:00
|
|
|
Bukkit.getPluginManager().registerEvents(new TNTListener(), this);
|
2020-01-07 23:22:31 +01:00
|
|
|
Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this);
|
2019-06-11 07:05:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static BauSystem getPlugin(){
|
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
public static UUID getOwner(){
|
|
|
|
return owner;
|
|
|
|
}
|
2019-06-13 10:22:07 +02:00
|
|
|
public static List<ArenaSection> getSections(){
|
|
|
|
return sections;
|
|
|
|
}
|
|
|
|
public static int getOwnerID(){
|
2019-11-10 17:29:01 +01:00
|
|
|
return SteamwarUser.get(owner).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) {
|
2019-06-11 07:05:05 +02:00
|
|
|
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);
|
|
|
|
}
|
2019-06-13 10:22:07 +02:00
|
|
|
|
|
|
|
@EventHandler
|
2020-01-07 23:22:31 +01:00
|
|
|
public void onLeave(PlayerQuitEvent e) {
|
2019-06-13 21:06:59 +02:00
|
|
|
if(Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(e.getPlayer())))
|
2019-06-13 10:22:07 +02:00
|
|
|
Bukkit.shutdown();
|
|
|
|
}
|
2019-06-11 07:05:05 +02:00
|
|
|
}
|