From a961f9c0a681fa756623b31a54574f01cfbd2dc0 Mon Sep 17 00:00:00 2001 From: ShakeforProtein Date: Fri, 11 Sep 2020 11:48:54 +1000 Subject: [PATCH] Updates to 1.16.2+ Removes tps based events Adds player count to hub menu --- pom.xml | 6 +- .../treeboteleport/Bungee/BungeeRecieve.java | 57 +++++++- .../treeboteleport/Bungee/BungeeSend.java | 39 +++++- .../Commands/SetPersonalWarp.java | 94 +++++++++++++ .../Listeners/PlayerJoinListener.java | 5 + .../Listeners/PlayerMoveListener.java | 49 +++++++ .../Listeners/PlayerTeleportListener.java | 13 ++ .../Methods/Guis/OpenHubMenu.java | 10 +- .../Methods/Guis/OpenPlayerWarpsMenu.java | 131 ++++++++++++++++++ .../Methods/Guis/OpenWarpsMenuOLD.java | 106 ++++++++++++++ .../treeboteleport/TreeboTeleport.java | 33 ++--- src/main/resources/config.yml | 17 ++- src/main/resources/plugin.yml | 6 +- 13 files changed, 531 insertions(+), 35 deletions(-) create mode 100644 src/main/java/me/shakeforprotein/treeboteleport/Commands/SetPersonalWarp.java create mode 100644 src/main/java/me/shakeforprotein/treeboteleport/Methods/Guis/OpenPlayerWarpsMenu.java create mode 100644 src/main/java/me/shakeforprotein/treeboteleport/Methods/Guis/OpenWarpsMenuOLD.java diff --git a/pom.xml b/pom.xml index 7a2992d..01d4b52 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.ShakeforProtein TreeboTeleport - 1.0.1 - SpMc1.16.1 + 1.1.0 - SpMc1.16.2 jar TreeboTeleport @@ -82,13 +82,13 @@ org.spigotmc spigot-api - 1.16.1-R0.1-SNAPSHOT + 1.16.2-R0.1-SNAPSHOT provided org.spigotmc spigot - 1.16.1-R0.1-SNAPSHOT + 1.16.2-R0.1-SNAPSHOT provided diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Bungee/BungeeRecieve.java b/src/main/java/me/shakeforprotein/treeboteleport/Bungee/BungeeRecieve.java index 5890819..a2277ae 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Bungee/BungeeRecieve.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Bungee/BungeeRecieve.java @@ -13,6 +13,7 @@ import java.io.IOException; import static me.shakeforprotein.treeboteleport.TreeboTeleport.fullPlayerList; +import static me.shakeforprotein.treeboteleport.TreeboTeleport.playerCounts; public class BungeeRecieve implements PluginMessageListener { @@ -35,6 +36,7 @@ public void onPluginMessageReceived(String channel, Player player, byte[] messag String subchannel = in.readUTF(); //System.out.println("Recieved message on 'subchannel' :" + subchannel); if (subchannel.startsWith(pl.getName() + "Channel-")) { + //Bukkit.broadcastMessage("Channel started with Channel-"); Short len = in.readShort(); byte[] msgbytes = new byte[len]; in.readFully(msgbytes); @@ -42,6 +44,7 @@ public void onPluginMessageReceived(String channel, Player player, byte[] messag DataInputStream msgin = new DataInputStream(new ByteArrayInputStream(msgbytes)); try { String msgData = msgin.readUTF(); // Read the data in the same way you wrote it + //Bukkit.broadcastMessage(msgData); if (subchannel.endsWith("CrossServerTeleport")) { for (Player targetPlayer : Bukkit.getOnlinePlayers()) { if (targetPlayer.getName().equalsIgnoreCase(msgData.split(",")[1])) { @@ -86,6 +89,45 @@ public void run() { } } } + else if (subchannel.contains("perWorldPlayersList")) { + String[] str = msgData.split("\\|"); + int totalPlayers = 0; + if(str.length > 0) { + if (str[0].equalsIgnoreCase("Sky")) { + int sb, ai, cb, ob; + sb = 0; + ai = 0; + cb = 0; + ob = 0; + for (int i = 1; i < str.length; i++) { + if (!str[0].equalsIgnoreCase("")) { + if (str[i].toLowerCase().startsWith("sky")){ + sb++; + } else if (str[i].toLowerCase().startsWith("one")){ + ob++; + } else if (str[i].toLowerCase().startsWith("cave")){ + cb++; + } else if (str[i].toLowerCase().startsWith("acid")){ + ai++; + } + } + } + playerCounts.put("Sky", (sb+ob+cb+ai)-1); + playerCounts.put("SkyBlock", (sb)-1); + playerCounts.put("OneBlock", (ob)-1); + playerCounts.put("CaveBlock", (cb)-1); + playerCounts.put("AcidIsland", (ai)-1); + + } else { + for (int i = 1; i < str.length; i++) { + if (!str[i].equalsIgnoreCase("")) { + totalPlayers++; + } + } + playerCounts.put(str[0].trim(), totalPlayers); + } + } + } else if (subchannel.endsWith("Jsaw")) { Bukkit.getScheduler().runTaskLater(pl, new Runnable() { @Override @@ -94,7 +136,6 @@ public void run() { } },40L); } - else if(subchannel.equals("GetServers")) { String[] serverList = in.readUTF().split(", "); for(String servers : serverList) { @@ -108,11 +149,17 @@ else if(subchannel.equals("GetServers")) { else if(subchannel.contains("PlayerList")){ String server = in.readUTF(); String[] playerList = in.readUTF().split(", "); - fullPlayerList.clear(); - for(String playa : playerList){ - if(playa != null) { - fullPlayerList.add(playa); + if(server.equalsIgnoreCase("ALL")) { + fullPlayerList.clear(); + for (String playa : playerList) { + if (playa != null) { + fullPlayerList.add(playa); + } } + } else { + if(!playerList[0].equalsIgnoreCase("")) { + pl.playerCounts.put(server, playerList.length); + } else {pl.playerCounts.put(server, 0);} } } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Bungee/BungeeSend.java b/src/main/java/me/shakeforprotein/treeboteleport/Bungee/BungeeSend.java index 8642824..164983c 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Bungee/BungeeSend.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Bungee/BungeeSend.java @@ -34,7 +34,7 @@ public void sendPluginMessage(String type, String server, String cmd){ DataOutputStream msgout = new DataOutputStream(msgbytes); try { String message = ""; - if(type.equalsIgnoreCase("CrossServerTeleport") || type.equalsIgnoreCase("CrossServerTPAHere") || type.equalsIgnoreCase("CrossServerTPA") || type.equalsIgnoreCase("Jsaw")){ + if(type.equalsIgnoreCase("CrossServerTeleport") || type.equalsIgnoreCase("CrossServerTPAHere") || type.equalsIgnoreCase("CrossServerTPA") || type.equalsIgnoreCase("perWorldPlayersList") || type.equalsIgnoreCase("Jsaw")){ message = cmd; } msgout.writeUTF(message); @@ -49,6 +49,36 @@ public void sendPluginMessage(String type, String server, String cmd){ player.sendPluginMessage(pl, "BungeeCord", out.toByteArray()); } + public void consoleSendPluginMessage(String type, String server, String cmd){ + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF("Forward"); //Type of message + out.writeUTF(server); // Server to send to + out.writeUTF(pl.getName() + "Channel-" + type); //Receiver Channel + + // If you don't care about the player + // Player player = Iterables.getFirst(Bukkit.getOnlinePlayers(), null); + // Else, specify them + // Player player = Iterables.getFirst(Bukkit.getOnlinePlayers(), null); + + ByteArrayOutputStream msgbytes = new ByteArrayOutputStream(); + DataOutputStream msgout = new DataOutputStream(msgbytes); + try { + String message = ""; + if(type.equalsIgnoreCase("CrossServerTeleport") || type.equalsIgnoreCase("CrossServerTPAHere") || type.equalsIgnoreCase("CrossServerTPA") || type.equalsIgnoreCase("perWorldPlayersList") || type.equalsIgnoreCase("Jsaw")){ + message = cmd; + } + msgout.writeUTF(message); + } catch (IOException exception){ + exception.printStackTrace(); + } + + out.writeShort(msgbytes.toByteArray().length); + out.write(msgbytes.toByteArray()); + + + Bukkit.getServer().sendPluginMessage(pl, "BungeeCord", out.toByteArray()); + } + public void sendConnectOther(String server, String playerName){ ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("ConnectOther"); //Type of message @@ -76,6 +106,13 @@ public void getPlayerList(String server){ } } + public void sendPerWorldPlayerList(String list){ + if(Bukkit.getOnlinePlayers().size() > 0) { + consoleSendPluginMessage("perWorldPlayersList", "ALL", list); + } + } + + public void getServers(){ ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("GetServers"); //Type of message diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetPersonalWarp.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetPersonalWarp.java new file mode 100644 index 0000000..220a480 --- /dev/null +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetPersonalWarp.java @@ -0,0 +1,94 @@ +package me.shakeforprotein.treeboteleport.Commands; + +import me.shakeforprotein.treeboteleport.TreeboTeleport; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.command.CommandSender; +import org.bukkit.command.defaults.BukkitCommand; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; + +public class SetPersonalWarp { + + private TreeboTeleport pl; + + public SetPersonalWarp(TreeboTeleport main) { + this.pl = main; + } + + public boolean register(String command) { + if (!pl.getConfig().getBoolean("disabledCommands." + command)) { + BukkitCommand item2 = new BukkitCommand(command.toLowerCase()) { + @Override + public boolean execute(CommandSender sender, String label, String[] args) { + this.setDescription("Creates a personal warp point with given name, that is accessible to all other players in this gamemode"); + this.setUsage("/SetPWarp - requires tbteleport.player.warps.setpersonalwarp"); + this.setPermission("tbteleport.player.warps.setpersonalwarp"); + if (sender.hasPermission(this.getPermission())) { + + File warpsYml = new File(pl.getDataFolder(), File.separator + "warps.yml"); + if (!warpsYml.exists()) { + sender.sendMessage(pl.err + "Warps data not found. Attempting to recover."); + try { + warpsYml.createNewFile(); + FileConfiguration warps = YamlConfiguration.loadConfiguration(warpsYml); + try { + warps.options().copyDefaults(); + warps.save(warpsYml); + } catch (FileNotFoundException e) { + pl.makeLog(e); + } + } catch (IOException e) { + pl.makeLog(e); + sender.sendMessage(pl.err + "Creating warps file failed"); + } + } + FileConfiguration warps = YamlConfiguration.loadConfiguration(warpsYml); + Player p = (Player) sender; + Location loc = p.getLocation(); + String world = loc.getWorld().getName(); + double x = loc.getX(); + double y = loc.getY(); + double z = loc.getZ(); + float pitch = loc.getPitch(); + float yaw = loc.getYaw(); + if (args.length == 0) { + p.sendMessage(pl.err + "You must provide a name for your new warp"); + } else if (args.length > 2) { + p.sendMessage(pl.err + "Too many arguments"); + } else { + String name = args[0]; + args[0] = args[0].toLowerCase(); + warps.set("playerWarps." + p.getUniqueId().toString() + ".name", name); + warps.set("playerWarps." + p.getUniqueId().toString() + ".world", world); + warps.set("playerWarps." + p.getUniqueId().toString() + ".x", x); + warps.set("playerWarps." + p.getUniqueId().toString() + ".y", y); + warps.set("playerWarps." + p.getUniqueId().toString() + ".z", z); + warps.set("playerWarps." + p.getUniqueId().toString() + ".pitch", pitch); + warps.set("playerWarps." + p.getUniqueId().toString() + ".yaw", yaw); + + try { + warps.save(warpsYml); + p.sendMessage(pl.badge + "Player Warp with name: " + ChatColor.GOLD + args[0] + ChatColor.RESET + " has been saved."); + p.sendMessage("If you choose to set a new PWarp, this warp will be overwritten."); + } catch (IOException e) { + pl.makeLog(e); + p.sendMessage(pl.err + "Saving warps file Unsuccessful"); + } + } + } else { + sender.sendMessage(ChatColor.RED + "You do not have access to this command. You require permission node " + ChatColor.GOLD + this.getPermission()); + } + return true; + } + }; + pl.registerNewCommand(pl.getDescription().getName(), item2); + } + return true; + } +} diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerJoinListener.java b/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerJoinListener.java index 4798433..86eebb6 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerJoinListener.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerJoinListener.java @@ -1,5 +1,6 @@ package me.shakeforprotein.treeboteleport.Listeners; +import me.shakeforprotein.treeboteleport.Bungee.BungeeSend; import me.shakeforprotein.treeboteleport.TreeboTeleport; import me.shakeforprotein.treeboteleport.UpdateChecker.UpdateChecker; import org.bukkit.Bukkit; @@ -12,6 +13,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -22,10 +24,12 @@ public class PlayerJoinListener implements Listener { private TreeboTeleport pl; private UpdateChecker uc; + private BungeeSend bungeeSend; public PlayerJoinListener(TreeboTeleport main) { this.pl = main; this.uc = new UpdateChecker(main); + this.bungeeSend = new BungeeSend(pl); } @EventHandler @@ -96,4 +100,5 @@ public boolean onPlayerChangeWorld(PlayerChangedWorldEvent e) { } return true; } + } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerMoveListener.java b/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerMoveListener.java index 4e9fce3..adcf6a5 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerMoveListener.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerMoveListener.java @@ -1,16 +1,30 @@ package me.shakeforprotein.treeboteleport.Listeners; +import me.shakeforprotein.treeboteleport.Bungee.BungeeSend; import me.shakeforprotein.treeboteleport.TreeboTeleport; +import net.minecraft.server.v1_16_R2.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.HashMap; +import java.util.concurrent.TimeUnit; public class PlayerMoveListener implements Listener { public TreeboTeleport pl; + private HashMap afkHash = new HashMap<>(); + private HashMap locationHash = new HashMap<>(); + private BungeeSend bungeeSend; public PlayerMoveListener(TreeboTeleport main){ this.pl = main; + bungeeSend = new BungeeSend(pl); } @EventHandler @@ -18,5 +32,40 @@ public void onPlayerMove(PlayerMoveEvent e){ if(pl.lockMove.containsKey(e.getPlayer().getUniqueId())){ e.setTo(e.getFrom()); } + + if(pl.getConfig().getBoolean("doAfkKick")){ + if(afkHash == null || !afkHash.containsKey(e.getPlayer())){ + afkHash.put(e.getPlayer(), System.currentTimeMillis()); + locationHash.put(e.getPlayer(), e.getTo()); + } else if(e.getPlayer().getWorld() != locationHash.get(e.getPlayer()).getWorld()){ + afkHash.replace(e.getPlayer(), System.currentTimeMillis()); + locationHash.replace(e.getPlayer(), e.getTo()); + } + else{ + Double x, z, x1, x2, z1, z2; + x1 = Math.floor(locationHash.get(e.getPlayer()).getX()); + x2 = Math.floor(e.getTo().getX()); + z1 = Math.floor(locationHash.get(e.getPlayer()).getZ()); + z2 = Math.floor(e.getTo().getZ()); + x = x2 - x1; + z = z1 - z2; + if(Math.abs(x*z) > 1000){ + afkHash.replace(e.getPlayer(), System.currentTimeMillis()); + locationHash.replace(e.getPlayer(), e.getTo()); + } + } + } + } + + @EventHandler + public void playerDisconnect(PlayerQuitEvent e){ + if(afkHash.containsKey(e.getPlayer())){afkHash.remove(e.getPlayer()); + locationHash.remove(e.getPlayer());} + } + + @EventHandler + public void playerChangeWorld(PlayerChangedWorldEvent e){ + afkHash.put(e.getPlayer(), System.currentTimeMillis()); + locationHash.put(e.getPlayer(), e.getPlayer().getLocation()); } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerTeleportListener.java b/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerTeleportListener.java index 3a5fea5..7379a1a 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerTeleportListener.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerTeleportListener.java @@ -6,7 +6,9 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.entity.Vehicle; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; @@ -28,6 +30,17 @@ public void playerTeleport(PlayerTeleportEvent e) { if (e.getCause().name().equalsIgnoreCase("PLUGIN")) { Player p = e.getPlayer(); + if(p.isInsideVehicle()){ + Entity v = p.getVehicle(); + v.eject(); + Bukkit.getScheduler().runTaskLater(pl, new Runnable() { + @Override + public void run() { + v.teleport(p.getLocation()); + v.addPassenger(e.getPlayer()); + } + },20L); + } //SAVE LAST LOCATION TO HASHMAP if (!(pl.lockMove.containsKey(p.getUniqueId()))) { diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Methods/Guis/OpenHubMenu.java b/src/main/java/me/shakeforprotein/treeboteleport/Methods/Guis/OpenHubMenu.java index f00677e..abf81c2 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Methods/Guis/OpenHubMenu.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Methods/Guis/OpenHubMenu.java @@ -1,5 +1,6 @@ package me.shakeforprotein.treeboteleport.Methods.Guis; +import me.shakeforprotein.treeboteleport.Bungee.BungeeRecieve; import me.shakeforprotein.treeboteleport.TreeboTeleport; import net.md_5.bungee.api.ChatColor; import org.bukkit.Bukkit; @@ -22,13 +23,14 @@ public class OpenHubMenu { private TreeboTeleport pl; + private BungeeRecieve bungeeRecieve; public OpenHubMenu(TreeboTeleport main){ this.pl = main; + this.bungeeRecieve = new BungeeRecieve(pl); } public boolean openHubMenu(Player p){ - File menuYml = new File(pl.getDataFolder(), File.separator + "hubMenu.yml"); FileConfiguration hubMenu = YamlConfiguration.loadConfiguration(menuYml); if(!menuYml.exists()) { @@ -74,6 +76,12 @@ public boolean openHubMenu(Player p){ itemLore.add(hubMenu.getString("hubmenu.menuItems." + item + ".lore." + newLore)); } } + + for(String srv : pl.getConfig().getStringList("ServerList")){ + if(ChatColor.stripColor(displayName).equalsIgnoreCase(srv)){ + itemLore.add(ChatColor.RED + "" + ChatColor.BOLD + "Playing Now: " + ChatColor.GREEN + "" + ChatColor.BOLD + pl.playerCounts.get(srv)); + } + } itemMeta.setLore(itemLore); newItem.setItemMeta(itemMeta); HubMenu.setItem(position, newItem); diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Methods/Guis/OpenPlayerWarpsMenu.java b/src/main/java/me/shakeforprotein/treeboteleport/Methods/Guis/OpenPlayerWarpsMenu.java new file mode 100644 index 0000000..901d901 --- /dev/null +++ b/src/main/java/me/shakeforprotein/treeboteleport/Methods/Guis/OpenPlayerWarpsMenu.java @@ -0,0 +1,131 @@ +package me.shakeforprotein.treeboteleport.Methods.Guis; + +import com.sun.org.apache.xerces.internal.xs.StringList; +import me.shakeforprotein.treeboteleport.TreeboTeleport; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +public class OpenPlayerWarpsMenu { + + private TreeboTeleport pl; + + public OpenPlayerWarpsMenu(TreeboTeleport main) { + this.pl = main; + } + + public void openWarpsMenu(Player p) { + File menuYml = new File(pl.getDataFolder(), "warps.yml"); + FileConfiguration warpsMenu = YamlConfiguration.loadConfiguration(menuYml); + if (!menuYml.exists()) { + try { + menuYml.createNewFile(); + try { + warpsMenu.options().copyDefaults(); + warpsMenu.save(menuYml); + } catch (FileNotFoundException e) { + pl.makeLog(e); + } + } catch (IOException e) { + pl.makeLog(e); + } + } + + String menuName = "Warps Interface"; + if(warpsMenu.get("menuName") != null){ + menuName = ChatColor.translateAlternateColorCodes('&',warpsMenu.getString("menuName")); + } + else{ + warpsMenu.set("menuName", "Warps Interface"); + } + + int invSize = 18; + + Set keys = warpsMenu.getConfigurationSection("playerWarps").getKeys(false); + + if(keys.size() > 9){ + invSize = 27; + } + + if(keys.size() > 18){ + invSize = 36; + } + + if(keys.size() > 27){ + invSize = 45; + } + + if(keys.size() > 36){ + invSize = 54; + } + + Inventory WarpsMenu = Bukkit.createInventory(null, invSize, menuName); + + for(String item : warpsMenu.getConfigurationSection("playerWarps").getKeys(false)){ + + String title = ""; + String icon = "ENDER_PEARL"; + String id = item; + + if(warpsMenu.getString("warps." + item + ".title") != null){ + title = ChatColor.translateAlternateColorCodes('&',warpsMenu.getString("warps." + item + ".title")); + } + else{ + title = "Warp " + item; + warpsMenu.set("playerWarps." + item + ".title", title); + } + if(warpsMenu.getString("playerWarps." + item + ".icon") != null){ + icon = warpsMenu.getString("playerWarps." + item + ".icon"); + } + else{ + warpsMenu.set("playerWarps." + item + ".icon", icon); + } + try{warpsMenu.save(menuYml);} + catch (IOException err){ + pl.makeLog(err); + System.out.println("Failed to update warps file"); + } + + ItemStack newItem = new ItemStack(Material.getMaterial(icon), 1); + ItemMeta iMeta = newItem.getItemMeta(); + List iLore = new ArrayList(); + + iMeta.setDisplayName(title); + iLore.add("ID: " + item); + + if(warpsMenu.getStringList("playerWarps." + item + ".lore").size() > 0){ + iLore.add(""); + for(String loreString : warpsMenu.getStringList("playerWarps." + item + ".lore")){ + iLore.add(ChatColor.translateAlternateColorCodes('&', loreString)); + } + } + + iMeta.setLore(iLore); + + newItem.setItemMeta(iMeta); + + if(warpsMenu.get("playerWarps." + item + ".requiredPermission") == null){ + WarpsMenu.addItem(newItem); + } + + else if (p.hasPermission(warpsMenu.getString("playerWarps." + item + ".requiredPermission"))){ + WarpsMenu.addItem(newItem); + } + } + p.openInventory(WarpsMenu); + } +} diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Methods/Guis/OpenWarpsMenuOLD.java b/src/main/java/me/shakeforprotein/treeboteleport/Methods/Guis/OpenWarpsMenuOLD.java new file mode 100644 index 0000000..a096560 --- /dev/null +++ b/src/main/java/me/shakeforprotein/treeboteleport/Methods/Guis/OpenWarpsMenuOLD.java @@ -0,0 +1,106 @@ +package me.shakeforprotein.treeboteleport.Methods.Guis; + +import me.shakeforprotein.treeboteleport.TreeboTeleport; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class OpenWarpsMenuOLD { + + private TreeboTeleport pl; + + public OpenWarpsMenuOLD(TreeboTeleport main) { + this.pl = main; + } + + public void openWarpsMenu(Player p) { + File menuYml = new File(pl.getDataFolder(), "warps.yml"); + FileConfiguration warpsMenu = YamlConfiguration.loadConfiguration(menuYml); + if (!menuYml.exists()) { + try { + menuYml.createNewFile(); + try { + warpsMenu.options().copyDefaults(); + warpsMenu.save(menuYml); + } catch (FileNotFoundException e) { + pl.makeLog(e); + } + } catch (IOException e) { + pl.makeLog(e); + } + } + + String menuName = "Warps Interface"; + if(warpsMenu.get("menuName") != null){ + menuName = ChatColor.translateAlternateColorCodes('&',warpsMenu.getString("menuName")); + } + else{ + warpsMenu.set("menuName", "Warps Interface"); + } + + int invSize = 18; + + if(warpsMenu.get("menuRows") != null){ + invSize = warpsMenu.getInt("menuRows") * 9; + } + Inventory WarpsMenu = Bukkit.createInventory(null, invSize, menuName); + + for(String item : warpsMenu.getConfigurationSection("warps").getKeys(false)){ + + String title = ""; + String icon = "ENDER_PEARL"; + String id = item; + + if(warpsMenu.getString("warps." + item + ".title") != null){ + title = ChatColor.translateAlternateColorCodes('&',warpsMenu.getString("warps." + item + ".title")); + } + else{ + title = "Warp " + item; + warpsMenu.set("warps." + item + ".title", title); + } + if(warpsMenu.getString("warps." + item + ".icon") != null){ + icon = warpsMenu.getString("warps." + item + ".icon"); + } + else{ + warpsMenu.set("warps." + item + ".icon", icon); + } + try{warpsMenu.save(menuYml);} + catch (IOException err){ + pl.makeLog(err); + System.out.println("Failed to update warps file"); + } + + ItemStack newItem = new ItemStack(Material.getMaterial(icon), 1); + ItemMeta iMeta = newItem.getItemMeta(); + List iLore = new ArrayList(); + + iMeta.setDisplayName(title); + iLore.add("ID: " + item); + + iMeta.setLore(iLore); + + newItem.setItemMeta(iMeta); + + if(warpsMenu.get("warps." + item + ".requiredPermission") == null){ + WarpsMenu.addItem(newItem); + } + + else if (p.hasPermission(warpsMenu.getString("warps." + item + ".requiredPermission"))){ + WarpsMenu.addItem(newItem); + } + } + p.openInventory(WarpsMenu); + } +} diff --git a/src/main/java/me/shakeforprotein/treeboteleport/TreeboTeleport.java b/src/main/java/me/shakeforprotein/treeboteleport/TreeboTeleport.java index ee2146a..2d6b43c 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/TreeboTeleport.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/TreeboTeleport.java @@ -9,12 +9,8 @@ import me.shakeforprotein.treeboteleport.Listeners.*; import me.shakeforprotein.treeboteleport.Methods.Teleports.ToWorld; import me.shakeforprotein.treeboteleport.UpdateChecker.UpdateChecker; -import net.minecraft.server.v1_16_R1.MinecraftServer; import org.bstats.bukkit.Metrics; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; +import org.bukkit.*; import org.bukkit.command.*; import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.configuration.file.FileConfiguration; @@ -47,6 +43,7 @@ public final class TreeboTeleport extends JavaPlugin { public HashMap lastLocConf = new HashMap(); public HashMap tpSafetyOff = new HashMap(); public List serverListNew = new ArrayList<>(); + public static HashMap playerCounts = new HashMap<>(); private AddMaxHomes addMaxHomes = new AddMaxHomes(this); private Bed bed = new Bed(this); @@ -275,31 +272,25 @@ public void onEnable() { File serverFile = new File(getDataFolder(), File.separator + "servers.yml"); FileConfiguration serverList = YamlConfiguration.loadConfiguration(serverFile); - getConfig().set("KillZombies", null); - getConfig().set("ReplacePhantomsWithPissedOffWolves", null); saveConfig(); + for(String srv : getConfig().getStringList("ServerList")){ + playerCounts.put(srv, 0); + } Bukkit.getScheduler().runTaskTimerAsynchronously(this, new Runnable() { @Override public void run() { bungeeSend.getPlayerList("ALL"); - } - }, 200, 40); - - Bukkit.getScheduler().runTaskTimer(this, new Runnable() { - @Override - public void run() { - double[] tps = MinecraftServer.getServer().recentTps; - if (tps[0] < 5) { - for(Player p : Bukkit.getOnlinePlayers()){ - p.sendMessage(badge + " Relocating you to hub due to unexplained server performance spike"); - bungeeSend.sendConnectOther("hub", p.getName()); - } + String playerString = ""; + playerString = playerString + getConfig().getString("general.serverName") + "|"; + for (Player p : Bukkit.getOnlinePlayers()) { + playerString = playerString + p.getWorld().getName() + "|"; } - + bungeeSend.sendPerWorldPlayerList(playerString); + playerString = null; } - }, 200, 2); + }, 200, 40); //createDefaultFile("", "homes", true); //createDefaultFile("", "servers.yml", false); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1de9954..746d35e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -16,8 +16,8 @@ useCooldown: false isHubServer: false -KillZombies: false -ReplacePhantomsWithPissedOffWolves: true +afkKickTimer: 120 +doAfkKick: true general: serverName: 'Test' @@ -92,4 +92,15 @@ wild: deathDocket: disable: false - toggle: \ No newline at end of file + +ServerList: + - Hub + - Survival + - Creative + - Sky + - Prison + - Hardcore + - Games + - SkyGrid + - Test + - Factions \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 69ea54b..f68c4f4 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -196,7 +196,11 @@ permissions: default: true tbteleport.player.givehubitem: default: true - tbteleport.player.warp: + tbteleport.player.warps.useserverwarps: + default: true + tbteleport.player.warps.useplayerwarps: + default: true + tbteleport.player.warps.setpersonalwarp: default: true tbteleport.player.home: default: true