Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main extends JavaPlugin {
- private static Main instance;
- private Thread thread;
- public String prefix = "§3QSG §8» §7";
- public String trackerMeta;
- public GameStateManager gameManager;
- public ChestManager chestManager;
- public Map normalMap;
- public Map dmMap;
- public String table;
- public boolean edit;
- public java.util.Map<UUID, Integer> ranking;
- public boolean teams = false;
- public boolean qsg = false;
- public int minplayers = 2;
- public int maxplayers = 12;
- @Override
- public void onEnable() {
- File file = new File(Main.getInstance().getDataFolder(),"config.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- if(!file.exists()){
- cfg.set("qsg", true);
- cfg.set("teams", true);
- cfg.set("minplayers", 2);
- cfg.set("maxplayers", 12);
- cfg.set("motd.lobby", "&aLobby");
- cfg.set("motd.lobbyfull", "&6Lobby");
- cfg.set("motd.warmup", "&9Warmup");
- cfg.set("motd.shield", "&bShield");
- cfg.set("motd.ingame", "&3Ingame");
- cfg.set("motd.deathmatch", "&cDeathMatch");
- cfg.set("motd.end", "&7End");
- for(World w : Bukkit.getWorlds()){
- String wo = w.toString();
- Bukkit.createWorld(new WorldCreator(wo).type(WorldType.NORMAL));
- System.out.println(wo+" geladen!");
- }
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- teams = cfg.getBoolean("teams");
- minplayers = cfg.getInt("minplayers");
- maxplayers = cfg.getInt("maxplayers");
- qsg = cfg.getBoolean("qsg");
- this.gameManager = new GameStateManager();
- this.edit = false;
- this.table = "sgstats";
- this.getCommand("createmap").setExecutor(new CreateMap());
- this.getCommand("setlobby").setExecutor(new SetLobby());
- this.getCommand("addspawn").setExecutor(new AddSpawn());
- this.getCommand("deletespawn").setExecutor(new DeleteSpawn());
- this.getCommand("setspectator").setExecutor(new SetSpectator());
- this.getCommand("forcemap").setExecutor(new Forcemap());
- this.getCommand("start").setExecutor(new Start());
- this.getCommand("edit").setExecutor(new Edit());
- this.getCommand("stats").setExecutor(new Stats());
- this.getCommand("sethead").setExecutor(new SetHead());
- this.getCommand("setsign").setExecutor(new SetSign());
- this.getCommand("removerank").setExecutor(new RemoveRank());
- this.loadMap();
- this.loadChestManager();
- this.loadBlocks();
- this.startMinutesThread();
- this.trackerMeta = "§6Tracker";
- this.ranking = new HashMap<>();
- this.loadMySQL();
- this.updateRanks();
- PluginManager pm = Bukkit.getPluginManager();
- pm.registerEvents(new PlayerJoin(), this);
- pm.registerEvents(new AsyncPlayerChat(), this);
- pm.registerEvents(new PlayerQuit(), this);
- pm.registerEvents(new PlayerInteract(), this);
- pm.registerEvents(new PlayerLogin(), this);
- pm.registerEvents(new ServerListPing(), this);
- pm.registerEvents(new BlockPlace(), this);
- pm.registerEvents(new EntityExplode(), this);
- pm.registerEvents(new InventoryClick(), this);
- pm.registerEvents(new PlayerMove(), this);
- pm.registerEvents(new BlockBreak(), this);
- pm.registerEvents(new EntityDamage(), this);
- pm.registerEvents(new EntityDamageByEntity(), this);
- pm.registerEvents(new PlayerDropItem(), this);
- pm.registerEvents(new BlockBurn(), this);
- pm.registerEvents(new BlockIgnite(), this);
- pm.registerEvents(new CreatureSpawn(), this);
- pm.registerEvents(new PlayerDeath(), this);
- pm.registerEvents(new PlayerRespawn(), this);
- pm.registerEvents(new FoodLevelChange(), this);
- pm.registerEvents(new LeavesDecay(), this);
- pm.registerEvents(new PlayerInteractEntity(), this);
- pm.registerEvents(new PlayerAchievementAwarded(), this);
- pm.registerEvents(new PlayerBedEnter(), this);
- pm.registerEvents(new PlayerExpChange(), this);
- pm.registerEvents(new PlayerLevelChange(), this);
- pm.registerEvents(new PlayerPickUpItem(), this);
- pm.registerEvents(new WeatherChange(), this);
- pm.registerEvents(new InventoryClose(), this);
- pm.registerEvents(new ItemEnchant(), this);
- pm.registerEvents(new PlayerToggleSprint(), this);
- }
- @Override
- public void onDisable() {
- this.thread.interrupt();
- if (this.normalMap != null) {
- Bukkit.unloadWorld(this.normalMap.getWorld(), false);
- }
- if (this.dmMap != null) {
- Bukkit.unloadWorld(this.dmMap.getWorld(), false);
- }
- if(GameStateShield.getThread() != null){
- GameStateShield.getThread().interrupt();
- }
- MySQL.getInstance().closeConnection();
- }
- @Override
- public void onLoad() {
- instance= this;
- }
- @SuppressWarnings("deprecation")
- private void loadChestManager() {
- File file = new File(this.getDataFolder(), "items.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<String> defaults = new ArrayList<>();
- // id:damage,min-max,prop. (Wahrscheinlichkeit)
- // Waffen
- defaults.add("267:0,1-1,2");
- defaults.add("268:0,1-1,20");
- defaults.add("272:0,1-1,15");
- defaults.add("261:0,1-1,30");
- defaults.add("262:0,10-1,50");
- defaults.add("279:0,1-1,28");
- defaults.add("271:0,1-1,23");
- defaults.add("346:0,1-1,13");
- // Rüstung
- defaults.add("298,1-1,13");
- defaults.add("299,1-1,17");
- defaults.add("300,1-1,15");
- defaults.add("301,1-1,19");
- defaults.add("302,1-1,14");
- defaults.add("303,1-1,34");
- defaults.add("304,1-1,18");
- defaults.add("305,1-1,14");
- defaults.add("306,1-1,17");
- defaults.add("307,1-1,16");
- defaults.add("308,1-1,15");
- defaults.add("309,1-1,11");
- defaults.add("314,1-1,19");
- defaults.add("315,1-1,16");
- defaults.add("316,1-1,15");
- defaults.add("317,1-1,21");
- // Essen
- defaults.add("260,10-1,31");
- defaults.add("297,7-1,35");
- defaults.add("320,5-1,28");
- defaults.add("322,5-1,13");
- defaults.add("363,7-1,16");
- defaults.add("349:3,1-1,1");
- defaults.add("393,7-1,19");
- // TODO More Defaults
- cfg.addDefault("items", defaults);
- cfg.options().copyDefaults(true);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- List<ChestItem> chestItems = new ArrayList<ChestItem>();
- List<String> items = cfg.getStringList("items");
- int i = 1;
- for (String item : items) {
- try {
- String[] split = item.split(",");
- String[] itemStack = split[0].split(":");
- String[] count = split[1].split("-");
- ItemStack stack = null;
- int id = Integer.parseInt(itemStack[0]);
- if (itemStack.length == 1) {
- stack = new ItemStack(id);
- } else {
- short damage = Short.parseShort(itemStack[1]);
- stack = new ItemStack(id, 0, damage);
- }
- int min = Integer.parseInt(count[0]);
- int max = Integer.parseInt(count[1]);
- int probability = Integer.parseInt(split[2]);
- chestItems.add(new ChestItem(stack, probability, min, max));
- } catch (Exception ex) {
- this.getLogger().log(Level.WARNING, "Das Item an der Stelle " + i + " benutzt einen falschen Syntax!");
- ex.printStackTrace();
- continue;
- } finally {
- i++;
- }
- }
- //for(ChestItem item : this.getSpecialItems()){
- // chestItems.add(item);
- // }
- this.chestManager = new ChestManager("§8Truhe", chestItems, 5, 2, 27);
- }
- public List<ChestItem> getSpecialItems(){
- List<ChestItem> items = new ArrayList<>();
- items.add(new ChestItem(this.getItem(Material.COMPASS, this.trackerMeta), 2, 1, 1));
- return items;
- }
- public ItemStack getItem(Material mat,String name){
- ItemStack stack = new ItemStack(mat);
- ItemMeta meta = stack.getItemMeta();
- meta.setDisplayName(name);
- stack.setItemMeta(meta);
- return stack;
- }
- public static Main getInstance() {
- return instance;
- }
- private void loadMySQL(){
- File file = new File(this.getDataFolder(), "MySQL.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- cfg.addDefault("MySQL.host", "host");
- cfg.addDefault("MySQL.database", "datenbank");
- cfg.addDefault("MySQL.user", "username");
- cfg.addDefault("MySQL.password", "passwort");
- cfg.addDefault("MySQL.port", 3306);
- cfg.options().copyDefaults(true);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- String host = cfg.getString("MySQL.host");
- String database = cfg.getString("MySQL.database");
- String user = cfg.getString("MySQL.user");
- String password = cfg.getString("MySQL.password");
- int port = cfg.getInt("MySQL.port");
- new MySQL(this, host, database, user, password, port);
- MySQL.getInstance().connect();
- MySQL.getInstance().update("CREATE TABLE IF NOT EXISTS "+this.table+" (id INT(16) AUTO_INCREMENT PRIMARY KEY, uuid VARCHAR(50), kills INT(16), deaths INT(16), points INT, minutes INT,games INT, wins INT, achievements VARCHAR(500), name VARCHAR(50))");
- }
- private void startMinutesThread() {
- this.thread = new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- Thread.sleep(1000 * 60);
- } catch (InterruptedException e) {}
- for(Player all : PlayerUtility.getLivingPlayers()){
- MySQL.getInstance().update("UPDATE " + Main.getInstance().table + " SET minutes = minutes+1 WHERE uuid = '"+all.getUniqueId().toString()+"'");
- }
- }
- });
- this.thread.start();
- }
- private void updateRanks(){
- MySQL.getInstance().query("SELECT uuid ,points ,wins FROM " +this.table + " ORDER BY points DESC",t->{
- try {
- File file = new File(Main.getInstance().getDataFolder(),"locs.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- int rank = 0;
- java.util.Map<Integer, UUID> top = new HashMap<Integer,UUID>();
- while (t.next()) {
- rank++;
- this.ranking.put(UUID.fromString(t.getString("uuid")), rank);
- top.put(rank, UUID.fromString(t.getString("uuid")));
- }
- if(cfg.isConfigurationSection("head")){
- for(String s : cfg.getConfigurationSection("head").getKeys(false)){
- int i = Integer.parseInt(s);
- if(top.containsKey(i)){
- UUID uuid = top.get(i);
- Location loc = FileHelper.getLocation(file,"head."+s);
- if(loc.getBlock().getState() instanceof Skull){
- Skull skull = (Skull) loc.getBlock().getState();
- // if(!skull.getOwner().equals(Bukkit.getOfflinePlayer(uuid).getName())){
- skull.setOwner(Bukkit.getOfflinePlayer(uuid).getName());
- skull.update();
- // }
- }
- }}
- }
- if(cfg.isConfigurationSection("sign")){
- for(String s : cfg.getConfigurationSection("sign").getKeys(false)){
- int i = Integer.parseInt(s);
- if(top.containsKey(i)){
- UUID uuid = top.get(i);
- Location loc = FileHelper.getLocation(file, "sign." + s);
- if(loc.getBlock().getState() instanceof Sign){
- t.absolute(rank);
- Sign sign = (Sign) loc.getBlock().getState();
- sign.setLine(0, "#"+s);
- sign.setLine(1, Bukkit.getOfflinePlayer(uuid).getName());
- sign.setLine(2, t.getInt("points") + " Punkte");
- sign.setLine(3, t.getInt("wins") + " Siege");
- sign.update();
- }
- }
- }
- }
- t.close();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- });
- }
- private void loadMap() {
- this.normalMap = this.getRandomMap("normal");
- this.dmMap = this.getRandomMap("deathmatch");
- if (this.normalMap != null) {
- this.getLogger().log(Level.INFO, "Als normale Map wird " + this.normalMap.getName() + " gespielt");
- }
- if (this.dmMap != null) {
- this.getLogger().log(Level.INFO, "Als Deathmatch Map wird " + this.dmMap.getName() + " gespielt");
- }
- }
- private void loadBlocks(){
- File file = new File(this.getDataFolder(),"items.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<String> build = new ArrayList<String>();
- build.add("92");
- cfg.addDefault("build", build);
- List<String> breaks = new ArrayList<String>();
- breaks.add("18");
- cfg.addDefault("break", breaks);
- cfg.options().copyDefaults(true);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public List<Integer> getBuildBlocks(){
- File file = new File(this.getDataFolder(),"items.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<Integer> ints = new ArrayList<Integer>();
- int i = 1;
- for(String s : cfg.getStringList("build")){
- try{
- ints.add(Integer.parseInt(s));
- }catch(NumberFormatException ex){
- this.getLogger().log(Level.WARNING, "Build ID "+ i + " hat nicht den richtigen Syntax!");
- }finally{
- i++;
- }
- }
- return ints;
- }
- public List<Integer> getBreakBlocks(){
- File file = new File(this.getDataFolder(),"items.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<Integer> ints = new ArrayList<Integer>();
- int i = 1;
- for(String s : cfg.getStringList("break")){
- try{
- ints.add(Integer.parseInt(s));
- }catch(NumberFormatException ex){
- this.getLogger().log(Level.WARNING, "Break ID "+ i + " hat nicht den richtigen Syntax!");
- }finally{
- i++;
- }
- }
- return ints;
- }
- private Map getRandomMap(String type) {
- File file = new File(this.getDataFolder(), "maps.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<String> mapNames = new ArrayList<String>();
- if (cfg.isConfigurationSection("")) {
- for (String mapName : cfg.getConfigurationSection("").getKeys(false)) {
- if (cfg.getString(mapName + ".type").equals(type)) {
- mapNames.add(mapName);
- }
- }
- }
- if (!mapNames.isEmpty()) {
- String mapName = mapNames.get(new Random().nextInt(mapNames.size()));
- return this.getByName(mapName);
- }
- this.getLogger().log(Level.WARNING, "Es ist keine Map vorhanden");
- return null;
- }
- public Map getByName(String mapName) {
- File file = new File(this.getDataFolder(), "maps.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- final String world = cfg.getString(mapName + ".world");
- List<Location> locs = new ArrayList<>();
- if (cfg.isConfigurationSection(mapName + ".spawns")) {
- for (String location : cfg.getConfigurationSection(mapName + ".spawns").getKeys(false)) {
- locs.add(FileHelper.getLocation(file, mapName + ".spawns." + location));
- }
- }
- Location spectator = null;
- if (cfg.contains(mapName + ".spectator")) {
- spectator = FileHelper.getLocation(file, mapName + ".spectator");
- }
- for (World w : Bukkit.getWorlds()) {
- if (w.getName().equals(world)) {
- this.getLogger().log(Level.INFO, "Welt wurde geladen");
- w.setAutoSave(false);
- w.setGameRuleValue("doDaylightCycle", "false");
- w.setStorm(false);
- w.setTime(2000);
- w.setThundering(false);
- return new Map(mapName, world, spectator, locs);
- }
- }
- new Thread(new Runnable() {
- @Override
- public void run() {
- Bukkit.getScheduler().runTask(Main.getInstance(), new Runnable() {
- @Override
- public void run() {
- World w = Bukkit.getWorld(world);
- w.setAutoSave(false);
- w.setGameRuleValue("doDaylightCycle", "false");
- w.setStorm(false);
- w.setTime(2000);
- w.setThundering(false);
- Main.getInstance().getLogger().log(Level.INFO, "Welt wurde geladen");
- }
- });
- }
- });
- return new Map(mapName, world, spectator, locs);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement