+
+
+
+
+
+
\ No newline at end of file
diff --git a/LobbyAPI.iml b/LobbyAPI.iml
new file mode 100644
index 0000000..74f3f13
--- /dev/null
+++ b/LobbyAPI.iml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 9d68e49..097d133 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,57 +1,67 @@
-
- 4.0.0
- me.zombie_striker
- LobbyAPI
- 3.7.86
-
-
- spigot-repo
- https://hub.spigotmc.org/nexus/content/groups/public/
-
-
-
- ${project.name}
- install
-
-
-
- ${basedir}/resources
- true
-
- plugin.yml
- config.yml
-
-
-
- src
-
-
- maven-compiler-plugin
- 3.7.0
-
-
- 1.7
-
-
-
-
-
-
-
- org.spigotmc
- spigot
- 1.14.1-R0.1-SNAPSHOT
- provided
-
-
-
- me.zombie_striker
- pluginconstructor
- 1.0.50
- system
- ${project.basedir}/libs/PluginConstructorAPI.jar
-
-
+
+ 4.0.0
+ me.zombie_striker
+ LobbyAPI
+ 3.7.88
+
+
+
+ spigot-repo
+ https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
+
+
+ ${project.name}
+ install
+
+
+
+ ${basedir}/resources
+ true
+
+ plugin.yml
+ config.yml
+
+
+
+ src
+
+
+ maven-compiler-plugin
+ 3.7.0
+
+
+ 1.7
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 8
+
+
+
+
+
+
+
+
+ org.spigotmc
+ spigot
+ 1.14.2-R0.1-SNAPSHOT
+ provided
+
+
+
+ me.zombie_striker
+ pluginconstructor
+ 1.0.50
+ system
+ ${project.basedir}/libs/PluginConstructorAPI.jar
+
+
\ No newline at end of file
diff --git a/resources/changelog.txt b/resources/changelog.txt
index acdd8ea..f57b91c 100644
--- a/resources/changelog.txt
+++ b/resources/changelog.txt
@@ -1,3 +1,16 @@
+3.7.88
+ Added potion effects, saturation, bedspawns, compass, allowflight, air, and fireticks to the player's data per world.
+ Fixed xp levels not being saved correctly
+ Changed nether/end system to reduce memory since most of the values should be duplicated from the main world.
+ Cleaned up config. It should now be close to half the size as in previous updates
+ Code cleanup
+ Import cleanup
+
+3.7.87
+ Fixed portal XZ offset for nether portals
+ Added "Any" as an option for the default gamemode
+ Fixed issue where gamemodes change across netherportal/endportal teleportation.
+
3.7.86
Fixed 1.13.
Fixed portals not giving items for some nether portals
diff --git a/resources/plugin.yml b/resources/plugin.yml
index 5ae4116..24870a4 100644
--- a/resources/plugin.yml
+++ b/resources/plugin.yml
@@ -3,22 +3,22 @@ version: ${project.version}
api-version: 1.13
name: LobbyAPI
commands:
- Lobby:
+ Lobby:
description: Opens the world menu
aliases: [hub]
- LobbyAPI:
+ LobbyAPI:
description: Get access to all lobbyAPI commands
permissions:
- lobbyapi.*:
- description: Gives access to all LobbyAPI features
- children:
- lobbyapi.commands: true
- lobbyapi.user: true
- lobbyapi.bypassworldlimits: true
- lobbyapi.user:
- default: true
- description: Gives access that only a user should have, which is to access the hub command
- children:
- lobbyapi.hub: true
+ lobbyapi.*:
+ description: Gives access to all LobbyAPI features
+ children:
+ lobbyapi.commands: true
+ lobbyapi.user: true
+ lobbyapi.bypassworldlimits: true
+ lobbyapi.user:
+ default: true
+ description: Gives access that only a user should have, which is to access the hub command
+ children:
+ lobbyapi.hub: true
author:
- Zombie_Striker
\ No newline at end of file
+ Zombie_Striker
\ No newline at end of file
diff --git a/src/me/zombie_striker/lobbyapi/BungeeMessager.java b/src/me/zombie_striker/lobbyapi/BungeeMessager.java
index 1ce2536..dfe204f 100644
--- a/src/me/zombie_striker/lobbyapi/BungeeMessager.java
+++ b/src/me/zombie_striker/lobbyapi/BungeeMessager.java
@@ -1,10 +1,9 @@
package me.zombie_striker.lobbyapi;
-import org.bukkit.entity.Player;
-import org.bukkit.plugin.messaging.PluginMessageListener;
-
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.messaging.PluginMessageListener;
public class BungeeMessager implements PluginMessageListener {
diff --git a/src/me/zombie_striker/lobbyapi/LobbyAPI.java b/src/me/zombie_striker/lobbyapi/LobbyAPI.java
index d93dc22..887d199 100644
--- a/src/me/zombie_striker/lobbyapi/LobbyAPI.java
+++ b/src/me/zombie_striker/lobbyapi/LobbyAPI.java
@@ -12,24 +12,20 @@
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
- */package me.zombie_striker.lobbyapi;
+ */
+package me.zombie_striker.lobbyapi;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.UUID;
-
-import org.bukkit.Bukkit;
-import org.bukkit.GameMode;
-import org.bukkit.Location;
-import org.bukkit.Material;
-import org.bukkit.World;
+import com.google.common.io.ByteArrayDataOutput;
+import com.google.common.io.ByteStreams;
+import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
-import com.google.common.io.ByteArrayDataOutput;
-import com.google.common.io.ByteStreams;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
public class LobbyAPI {
@@ -41,10 +37,11 @@ public LobbyAPI(Main mll) {
public static void updateServerCount(Player player) {
- for(LobbyServer ls : ml.getBungeeServers()) {
+ for (LobbyServer ls : ml.getBungeeServers()) {
updateServerCount(player, ls);
}
}
+
public static void updateServerCount(Player player, LobbyServer ls) {
ByteArrayDataOutput baos = ByteStreams.newDataOutput();
try {
@@ -58,9 +55,7 @@ public static void updateServerCount(Player player, LobbyServer ls) {
/**
* returns if the world has a max amount of players for the world
- *
- * @param the
- * world
+ *
* @return if it was successful.
*/
public static boolean hasMaxPlayers(World wo) {
@@ -69,9 +64,7 @@ public static boolean hasMaxPlayers(World wo) {
/**
* Returns the max amount of players
- *
- * @param the
- * world
+ *
* @return the max amount of players
*/
public static int getMaxPlayers(World wo) {
@@ -83,34 +76,30 @@ public static int getMaxPlayers(World wo) {
/**
* Adds a new lobbyworld
- *
+ *
* NOTE: You should use registerWorld instead if you want to create a new
* lobby world.
- *
+ *
* @param lobby
*/
public static void addLobbyWorld(LobbyWorld lobby) {
- ml.getWorlds().add(lobby);
+ LobbyWorld.getLobbyWorlds().add(lobby);
}
/**
* Removes a lobby world
- *
+ *
* NOTE: You should use unregisterWorld if you want to unregister a world
- *
+ *
* @param lobby
*/
public static void removeLobbyWorld(LobbyWorld lobby) {
- ml.getWorlds().remove(lobby);
+ LobbyWorld.getLobbyWorlds().remove(lobby);
}
/**
* Sets the max players for a world
- *
- * @param the
- * world
- * @param the
- * maxvalue
+ *
*/
public static void setMaxPlayers(World wo, int maxvalue) {
getLobbyWorld(wo).setMaxPlayers(maxvalue < 0, maxvalue);
@@ -119,7 +108,7 @@ public static void setMaxPlayers(World wo, int maxvalue) {
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
+ *
* @param wo
* @param material
*/
@@ -131,9 +120,8 @@ public static void setWorldMaterial(World wo, Material material) {
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
+ *
* @param wo
- * @param material
*/
@Deprecated
public static Material getWorldMaterial(World wo) {
@@ -143,9 +131,8 @@ public static Material getWorldMaterial(World wo) {
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
+ *
* @param wo
- * @param material
*/
@Deprecated
public static void setIsWorldPrivate(boolean b, World wo) {
@@ -155,9 +142,8 @@ public static void setIsWorldPrivate(boolean b, World wo) {
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
+ *
* @param wo
- * @param material
*/
@Deprecated
public static boolean isWorldPrivate(World wo) {
@@ -167,9 +153,8 @@ public static boolean isWorldPrivate(World wo) {
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
+ *
* @param wo
- * @param material
*/
@Deprecated
public static boolean hasNoEnderChestRules(World wo) {
@@ -179,9 +164,8 @@ public static boolean hasNoEnderChestRules(World wo) {
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
+ *
* @param wo
- * @param material
*/
@Deprecated
public static void setNoEnderChests(World wo, boolean b) {
@@ -190,7 +174,7 @@ public static void setNoEnderChests(World wo, boolean b) {
/**
* Whitelists a UUID for a specific worlds
- *
+ *
* @param uuid
* @param wo
* @return if it was successful
@@ -202,7 +186,7 @@ public static boolean whitelistContainsPlayer(UUID uuid, World wo) {
/**
* Whitelists a player's name for the wortd
- *
+ *
* @param name
* @param wo
* @return if it was successful
@@ -215,7 +199,7 @@ public static boolean whitelistContainsPlayer(String name, World wo) {
/**
* Whitelists a player through there name.
- *
+ *
* @param name
* @param wo
*/
@@ -227,12 +211,12 @@ public static void addWhitelistPlayer(String name, World wo) {
return;
}
getLobbyWorld(wo).addWhitelistedPlayer(
- (Player) Bukkit.getOfflinePlayer(name));
+ Bukkit.getOfflinePlayer(name));
}
/**
* Whitelists a player through their UUID
- *
+ *
* @param uuid
* @param wo
*/
@@ -243,12 +227,12 @@ public static void addWhitelistPlayer(UUID uuid, World wo) {
return;
}
getLobbyWorld(wo).addWhitelistedPlayer(
- (Player) Bukkit.getOfflinePlayer(uuid));
+ Bukkit.getOfflinePlayer(uuid));
}
/**
* Whitelits a group of players through their names
- *
+ *
* @param name
* @param wo
*/
@@ -261,13 +245,13 @@ public static void addWhitelistPlayerArray(ArrayList name, World wo) {
}
for (String s : name) {
getLobbyWorld(wo).addWhitelistedPlayer(
- (Player) Bukkit.getOfflinePlayer(s));
+ Bukkit.getOfflinePlayer(s));
}
}
/**
* Whitelists a group of players through their UUIDs
- *
+ *
* @param uuid
* @param wo
*/
@@ -279,33 +263,17 @@ public static void addWhitelistPlayer(ArrayList uuid, World wo) {
}
for (UUID s : uuid) {
getLobbyWorld(wo).addWhitelistedPlayer(
- (Player) Bukkit.getOfflinePlayer(s));
+ Bukkit.getOfflinePlayer(s));
}
}
/**
* Use this to register your world
- *
- * @param The
- * world instance
- * @param The
- * spawn location
- * @param The
- * address you will save all the inventories to (E.g. "world1" or
- * "minigame")
- * @param The
- * description of the world
- * @param The
- * material's duribility
- * @param The
- * slot in the menu the item will be in. Note: If that slot was
- * already taken, it will find an open one.
- * @param The
- * Dafault gamemode
+ *
*/
public static LobbyWorld registerWorld(World world, Location spawn,
- String saveLetter, String worldDescription, Integer woolColor,
- int menuSlot, GameMode gamemode) {
+ String saveLetter, String worldDescription, Integer woolColor,
+ int menuSlot, GameMode gamemode) {
LobbyWorld lw = new LobbyWorld(false, world.getName(), menuSlot, 1,
Short.parseShort(woolColor + ""), spawn, saveLetter, gamemode);
addLobbyWorld(lw);
@@ -315,19 +283,10 @@ public static LobbyWorld registerWorld(World world, Location spawn,
/**
* Registers a "hidden" world (a world not seen in the menu)
- *
- * @param The
- * world instance
- * @param The
- * spawn location
- * @param The
- * address you will save all the inventories to (E.g. "world1" or
- * "minigame")
- * @param The
- * dafault gamemode
+ *
*/
public static LobbyWorld registerHiddenWorld(World world, Location spawn,
- String saveLetter, GameMode gamemode) {
+ String saveLetter, GameMode gamemode) {
LobbyWorld lw = new LobbyWorld(false, world.getName(),
getOpenSlot(10), 1, (short) 0, spawn, saveLetter, gamemode);
addLobbyWorld(lw);
@@ -337,21 +296,11 @@ public static LobbyWorld registerHiddenWorld(World world, Location spawn,
/**
* Registers a "Hidden" world (a world not awwn in the menu)
- *
- * @param The
- * world instance
- * @param The
- * spawn location
- * @param The
- * address you will save all the inventories to (E.g. "world1" or
- * "minigame")
- * @param The
- * world description
- * @param
+ *
* @param gamemode
*/
public static LobbyWorld registerHiddenWorld(World world, Location spawn,
- String saveLetter, String worldDescription, GameMode gamemode) {
+ String saveLetter, String worldDescription, GameMode gamemode) {
LobbyWorld lw = new LobbyWorld(false, world.getName(), getOpenSlot(0), 1,
(short) 0, spawn, saveLetter, gamemode);
addLobbyWorld(lw);
@@ -362,7 +311,7 @@ public static LobbyWorld registerHiddenWorld(World world, Location spawn,
/**
* USED ONLY IF REGISTERING WORLDS FROM THE LOBBYAPI CONFIG
- *
+ *
* @param world
* @param spawn
* @param saveLetter
@@ -374,8 +323,8 @@ public static LobbyWorld registerHiddenWorld(World world, Location spawn,
*/
@Deprecated
public static LobbyWorld registerWorldFromConfig(World world, Location spawn,
- String saveLetter, String worldDescription, Integer woolColor,
- Material worldMaterial, int menuSlot, GameMode gamemode) {
+ String saveLetter, String worldDescription, Integer woolColor,
+ Material worldMaterial, int menuSlot, GameMode gamemode) {
LobbyWorld lw = new LobbyWorld(true, world.getName(), menuSlot, 1,
Short.parseShort(woolColor + ""), spawn, saveLetter, gamemode);
addLobbyWorld(lw);
@@ -383,9 +332,10 @@ public static LobbyWorld registerWorldFromConfig(World world, Location spawn,
setWorldMaterial(world, worldMaterial);
return lw;
}
+
/**
* USED ONLY IF LOADING WORLDS FROM LOBBYAPI CONFIG
- *
+ *
* @param world
* @param spawn
* @param saveLetter
@@ -396,20 +346,20 @@ public static LobbyWorld registerWorldFromConfig(World world, Location spawn,
*/
@Deprecated
public static LobbyWorld registerWorldFromConfig(World world, Location spawn,
- String saveLetter, String worldDescription, Integer woolColor,
- int menuSlot, GameMode gamemode,boolean hidden) {
+ String saveLetter, String worldDescription, Integer woolColor,
+ int menuSlot, GameMode gamemode, boolean hidden) {
LobbyWorld lw = new LobbyWorld(true, world.getName(), menuSlot, 1,
Short.parseShort(woolColor + ""), spawn, saveLetter, gamemode);
addLobbyWorld(lw);
addWorldDescriptionLine(world, worldDescription);
- if(hidden)
+ if (hidden)
hideWorld(world, true);
return lw;
}
/**
* Unregisters a world
- *
+ *
* @param world
*/
@Deprecated
@@ -419,7 +369,7 @@ public static void unregisterWorld(World world) {
/**
* Unregisters a bungee server
- *
+ *
* @param server
*/
@Deprecated
@@ -429,14 +379,14 @@ public static void unregisterBungeeServer(String server) {
/**
* Registers a bungee server
- *
+ *
* @param server
* @param slot
* @param amount
* @param woolColor
*/
public static void registerBungeeServer(String server, int slot,
- int amount, Integer woolColor) {
+ int amount, Integer woolColor) {
LobbyServer lw = new LobbyServer(false, server, slot, amount,
Short.parseShort(woolColor + ""));
addBungeeServer(lw);
@@ -444,14 +394,14 @@ public static void registerBungeeServer(String server, int slot,
/**
* ONLY TO BE USED IF REIGSTERING A SERVER FROM LOBBYAPI CONFIG
- *
+ *
* @param server
* @param slot
* @param woolColor
*/
@Deprecated
public static void registerBungeeServerFromConfig(String server, int slot,
- Integer woolColor) {
+ Integer woolColor) {
LobbyServer lw = new LobbyServer(true, server, slot, 1,
Short.parseShort(woolColor + ""));
addBungeeServer(lw);
@@ -459,7 +409,7 @@ public static void registerBungeeServerFromConfig(String server, int slot,
/**
* Adds a bungee server NOTE: instead use registerBungeeServer
- *
+ *
* @param ls
*/
public static void addBungeeServer(LobbyServer ls) {
@@ -468,7 +418,7 @@ public static void addBungeeServer(LobbyServer ls) {
/**
* Return the LobbyServer instance
- *
+ *
* @param name
* @return the LobbyServer instance
*/
@@ -482,7 +432,7 @@ public static LobbyServer getServer(String name) {
/**
* Removes a BungeeServer
- *
+ *
* @param name
* @return
*/
@@ -493,16 +443,12 @@ public static boolean removeBungeeServer(String name) {
/**
* Creates a custom itemstack
- *
- * @param Displayname
- * @param Amount
- * @param Material
- * @param Lore
+ *
* @return the custom itemstack
*/
@SuppressWarnings("deprecation")
public static ItemStack setName(String name, int numb, Material mat,
- List lore) {
+ List lore) {
ItemStack is = new ItemStack(mat, 1);
ItemMeta im = is.getItemMeta();
im.setDisplayName(name);
@@ -514,7 +460,7 @@ public static ItemStack setName(String name, int numb, Material mat,
/**
* Hides the LobbyWorld from the menu
- *
+ *
* @param wo
* @param hidden
*/
@@ -524,7 +470,7 @@ public static void hideWorld(World wo, boolean hidden) {
/**
* Returns if the world is hidden from the menu
- *
+ *
* @param wo
* @return
*/
@@ -534,7 +480,7 @@ public static boolean isHidden(World wo) {
/**
* Creates a custom itemstack
- *
+ *
* @param name
* @param numb
* @param mat
@@ -553,13 +499,13 @@ public static ItemStack setName(String name, int numb, Material mat) {
/*
* public static void addBungeeServer(String server) {
* ml.bungeeServers.add(server); }
- *
+ *
* public static void setBungeeDescription(String server, String message) {
* ml.ServerDescription.put(server, message); }
- *
+ *
* public static void setBungeeMenuColor(String server, Integer color) {
* ml.ServerWoolColor.put(server, color); }
- *
+ *
* public static void setBungeeMenuAmount(String server, Integer amount) {
* ml.ServerWoolAmount.put(server, amount); }
*/
@@ -567,9 +513,7 @@ public static ItemStack setName(String name, int numb, Material mat) {
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
- * @param wo
- * @param material
+ *
*/
@Deprecated
public static void setWorldSpawn(World world, Location location) {
@@ -579,9 +523,7 @@ public static void setWorldSpawn(World world, Location location) {
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
- * @param wo
- * @param material
+ *
*/
@Deprecated
public static void setWorldsStaticTime(World world, int time) {
@@ -591,9 +533,7 @@ public static void setWorldsStaticTime(World world, int time) {
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
- * @param wo
- * @param material
+ *
*/
@Deprecated
public static void setWorldDescription(World world, List message) {
@@ -602,7 +542,7 @@ public static void setWorldDescription(World world, List message) {
/**
* Adds one line to the world's description in the menu.
- *
+ *
* @param world
* @param message
*/
@@ -615,9 +555,7 @@ public static void addWorldDescriptionLine(World world, String message) {
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
- * @param wo
- * @param material
+ *
*/
@Deprecated
public static void setWorldMenuColor(World world, Integer color) {
@@ -627,9 +565,7 @@ public static void setWorldMenuColor(World world, Integer color) {
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
- * @param wo
- * @param material
+ *
*/
@Deprecated
public static void setWorldMenuAmount(World world, Integer amount) {
@@ -640,7 +576,7 @@ public static void setWorldMenuAmount(World world, Integer amount) {
* Sets the speific world to be the "Mainworld" (E.g. inputting
* "world_nether", "world" would mean that anytime the player teleports to
* "world_nether" through the menu, it will redirect them to "world")
- *
+ *
* @param world
* @param main
*/
@@ -650,28 +586,26 @@ public static void setMainWorld(World world, World main) {
/**
* Removes a world from menu.
- *
+ *
* @param world
*/
public static void removeWorld(World world) {
LobbyWorld Rwo = null;
- for (LobbyWorld wo : ml.getWorlds()) {
+ for (LobbyWorld wo : LobbyWorld.getLobbyWorlds()) {
if (wo.getWorldName().equals(world.getName())) {
Rwo = wo;
break;
}
}
if (Rwo != null) {
- ml.getWorlds().remove(Rwo);
+ LobbyWorld.getLobbyWorlds().remove(Rwo);
}
}
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
- * @param wo
- * @param material
+ *
*/
@Deprecated
public static void addWorldThatCantUsePortals(World world) {
@@ -681,9 +615,7 @@ public static void addWorldThatCantUsePortals(World world) {
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
- * @param wo
- * @param material
+ *
*/
@Deprecated
public static void removeWorldThatCantUsePortals(World world) {
@@ -693,9 +625,7 @@ public static void removeWorldThatCantUsePortals(World world) {
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
- * @param wo
- * @param material
+ *
*/
@Deprecated
public static void setWorldThatCantUsePortals(World world, boolean b) {
@@ -705,9 +635,7 @@ public static void setWorldThatCantUsePortals(World world, boolean b) {
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
- * @param wo
- * @param material
+ *
*/
@Deprecated
public static void setWorldItems(World world, List items) {
@@ -717,9 +645,7 @@ public static void setWorldItems(World world, List items) {
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
- * @param wo
- * @param material
+ *
*/
@Deprecated
public static void setWorldGameMode(World world, GameMode gm) {
@@ -729,9 +655,7 @@ public static void setWorldGameMode(World world, GameMode gm) {
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
- * @param wo
- * @param material
+ *
*/
@Deprecated
public static void setWorldMenuSlot(World world, Integer slot) {
@@ -739,12 +663,12 @@ public static void setWorldMenuSlot(World world, Integer slot) {
/**
* Checks if a world has already been registers
- *
+ *
* @param world
* @return if the world has been registered
*/
public static boolean isRegistered(World world) {
- for (LobbyWorld wo : ml.getWorlds()) {
+ for (LobbyWorld wo : LobbyWorld.getLobbyWorlds()) {
if (wo.getWorldName().equals(world.getName()))
return true;
}
@@ -753,52 +677,38 @@ public static boolean isRegistered(World world) {
/**
* Checks if the world has been registered
- *
+ *
* @param world
* @return if the world has been registered (Most cases, it will return
- * true)
+ * true)
*/
public static boolean isRegistered(LobbyWorld world) {
- return ml.getWorlds().contains(world);
+ return LobbyWorld.getLobbyWorlds().contains(world);
}
/**
* Use the methods from LobbyWorld instead of this. (Use
* LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
- * @param wo
- * @param material
+ *
*/
@Deprecated
public static Location getWorldSpawn(World world) {
return getLobbyWorld(world).getSpawn();
}
- /**
- * Use the methods from LobbyWorld instead of this. (Use
- * LobbyAPI.getLobbyWorld(World instance) to get the LobbyWorld instance)
- *
- * @param wo
- * @param material
- */
- @Deprecated
- public static void setWorldToTeleportToOnDeath(World world,
- World worldToTeleportTo) {
- getLobbyWorld(world).setRespawnWorld(worldToTeleportTo);
- }
/**
* Returns all the LobbyWorlds on the server
- *
+ *
* @return
*/
public static Set getWorlds() {
- return ml.getWorlds();
+ return LobbyWorld.getLobbyWorlds();
}
/**
* Gets the first open slot (after the specified slot) in thew menu
- *
+ *
* @param slot
* @return the first open slot (after the specified slot)
*/
@@ -807,7 +717,7 @@ public static int getOpenSlot(int slot) {
int times = 1;
for (int i = 0; i < times; i++) {
boolean isTaken = false;
- for (LobbyWorld lw : ml.getWorlds()) {
+ for (LobbyWorld lw : LobbyWorld.getLobbyWorlds()) {
if (openslot == lw.getSlot()) {
isTaken = true;
break;
@@ -831,13 +741,13 @@ public static int getOpenSlot(int slot) {
/**
* Returns the LobbbyWorld instance of the world
- *
+ *
* @param name
* @return
*/
public static LobbyWorld getLobbyWorld(String name) {
- for (LobbyWorld w : ml.getWorlds()) {
- if (w.getWorldName().equals(name))
+ for (LobbyWorld w : LobbyWorld.getLobbyWorlds()) {
+ if(w.getWorldName().equalsIgnoreCase(name) || (w.getNether()!=null && w.getNether().getName().equalsIgnoreCase(name)) || (w.getEnd()!=null && w.getEnd().getName().equalsIgnoreCase(name)))
return w;
}
return null;
@@ -845,31 +755,23 @@ public static LobbyWorld getLobbyWorld(String name) {
/**
* Returns thelobbyWorld instance of the world
- *
+ *
* @param wo
* @return
*/
public static LobbyWorld getLobbyWorld(World wo) {
- for (LobbyWorld w : ml.getWorlds()) {
- if (wo == null) {
- System.out.println(Main.getPrefix() + "The world provided is null +");
- break;
- }
- if (w.getWorldName().equals(wo.getName()))
- return w;
- }
- return null;
+ return LobbyWorld.getLobbyWorldFromWorld(wo);
}
/**
* Gets the "Main lobby" (the default world the player will be teleported
* to)
- *
+ *
* @return the default world
*/
public static LobbyWorld getLobby() {
LobbyWorld lobby = null;
- for (LobbyWorld w : ml.getWorlds()) {
+ for (LobbyWorld w : LobbyWorld.getLobbyWorlds()) {
if (w.isLobby())
return w;
if (lobby == null || lobby.getSlot() > w.getSlot()) {
@@ -882,12 +784,12 @@ public static LobbyWorld getLobby() {
/**
* Returns all of the save names for every world on the server (if multiple
* worlds share the same savename, the savename will only be added once)
- *
+ *
* @return
*/
public static List getSaveNames() {
List savenames = new ArrayList();
- for (LobbyWorld wo : ml.getWorlds()) {
+ for (LobbyWorld wo : LobbyWorld.getLobbyWorlds()) {
if (!savenames.contains(wo.getSaveName()))
savenames.add(wo.getSaveName());
}
@@ -897,13 +799,13 @@ public static List getSaveNames() {
/**
* Returns all of the LobbyWorlds that share the same name as the one
* provided
- *
+ *
* @param savename
* @return
*/
public static List getWorldsBySaveNameAsLobby(String savename) {
List worlds = new ArrayList();
- for (LobbyWorld wo : ml.getWorlds()) {
+ for (LobbyWorld wo : LobbyWorld.getLobbyWorlds()) {
if (wo.getSaveName().equals(savename)) {
worlds.add(wo);
}
@@ -914,13 +816,13 @@ public static List getWorldsBySaveNameAsLobby(String savename) {
/**
* Returns all of the worlds that share the same save name as the one
* provided
- *
+ *
* @param savename
* @return
*/
public static List getWorldsBySaveName(String savename) {
List worlds = new ArrayList();
- for (LobbyWorld wo : ml.getWorlds()) {
+ for (LobbyWorld wo : LobbyWorld.getLobbyWorlds()) {
if (wo.getSaveName().equals(savename)) {
worlds.add(Bukkit.getWorld(wo.getWorldName()));
}
@@ -930,27 +832,30 @@ public static List getWorldsBySaveName(String savename) {
/**
* Returns all of the LobbyWorlds that share the same material as the one provided
+ *
* @param material
* @return
*/
public static List getWorldsWithMaterialAsLobby(
Material material) {
List worlds = new ArrayList();
- for (LobbyWorld wo : ml.getWorlds()) {
+ for (LobbyWorld wo :LobbyWorld.getLobbyWorlds()) {
if (wo.getMaterial() == material) {
worlds.add(wo);
}
}
return worlds;
}
+
/**
* Returns all of the worlds that shre the same materials as the one provided
+ *
* @param material
* @return
*/
public static List getWorldsWithMaterial(Material material) {
List worlds = new ArrayList();
- for (LobbyWorld wo : ml.getWorlds()) {
+ for (LobbyWorld wo : LobbyWorld.getLobbyWorlds()) {
if (wo.getMaterial() == material) {
worlds.add(Bukkit.getWorld(wo.getWorldName()));
}
diff --git a/src/me/zombie_striker/lobbyapi/LobbyCommands.java b/src/me/zombie_striker/lobbyapi/LobbyCommands.java
index 8eed6c9..a19109d 100644
--- a/src/me/zombie_striker/lobbyapi/LobbyCommands.java
+++ b/src/me/zombie_striker/lobbyapi/LobbyCommands.java
@@ -1,30 +1,28 @@
package me.zombie_striker.lobbyapi;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Set;
-import java.util.UUID;
-
import me.zombie_striker.lobbyapi.LobbyWorld.WeatherState;
import me.zombie_striker.lobbyapi.utils.ConfigHandler;
import me.zombie_striker.lobbyapi.utils.ConfigHandler.ConfigKeys;
import me.zombie_striker.pluginconstructor.PluginConstructorAPI;
-
import org.bukkit.*;
import org.bukkit.World.Environment;
-import org.bukkit.command.*;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
+import java.util.*;
+
public class LobbyCommands implements CommandExecutor, TabCompleter {
private Main m;
private String prefix;
private HashMap usages = new HashMap<>();
- public LobbyCommands(Main mm) {
+ protected LobbyCommands(Main mm) {
this.m = mm;
this.prefix = Main.getPrefix();
addUsages();
@@ -43,7 +41,7 @@ private void bWorld(List tab, String arg) {
private void bLW(List tab, String arg) {
if ("~".toLowerCase().startsWith(arg.toLowerCase()))
tab.add("~");
- for (LobbyWorld wo : m.worlds) {
+ for (LobbyWorld wo : LobbyWorld.getLobbyWorlds()) {
if (wo.getWorldName().toLowerCase().startsWith(arg.toLowerCase()))
tab.add(wo.getWorldName());
}
@@ -168,6 +166,8 @@ public List onTabComplete(CommandSender sender, Command command, String
} else if (args.length == 3) {
if ("~".toLowerCase().startsWith(args[2].toLowerCase()))
tab.add("~");
+ if ("Any".toLowerCase().startsWith(args[2].toLowerCase()))
+ tab.add("Any");
for (GameMode gm : GameMode.values()) {
if (gm.name().toLowerCase().startsWith(args[2].toLowerCase()))
tab.add(gm.name());
@@ -202,7 +202,7 @@ public List onTabComplete(CommandSender sender, Command command, String
}
if (args.length == 8) {
- for (LobbyWorld wo : m.worlds)
+ for (LobbyWorld wo : LobbyWorld.getLobbyWorlds())
if (!tab.contains(wo.getSaveName()))
tab.add(wo.getSaveName());
}
@@ -232,7 +232,7 @@ public List onTabComplete(CommandSender sender, Command command, String
@SuppressWarnings("deprecation")
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
-
+
if (cmd.getName().equalsIgnoreCase("lobbyapi")) {
if (args.length > 0 && args[0].equalsIgnoreCase("version")) {
sender.sendMessage(prefix + " Current version :" + ChatColor.GRAY + m.getDescription().getVersion());
@@ -256,8 +256,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
for (int i = page * msgPerPage; i < (page * msgPerPage) + msgPerPage; i++) {
if (i >= usages.size())
break;
- sender.sendMessage(ChatColor.GOLD + "/LobbyAPI " + ((String) usages.keySet().toArray()[i]));
- sender.sendMessage(ChatColor.WHITE + usages.get((String) usages.keySet().toArray()[i]));
+ sender.sendMessage(ChatColor.GOLD + "/LobbyAPI " + usages.keySet().toArray()[i]);
+ sender.sendMessage(ChatColor.WHITE + usages.get(usages.keySet().toArray()[i]));
}
return true;
}
@@ -393,7 +393,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
for (int i = 3; i < args.length; i++)
display.append(args[i] + (i < args.length ? " " : ""));
- for (LobbyWorld lw : this.m.worlds)
+ for (LobbyWorld lw : LobbyWorld.getLobbyWorlds())
if (lw.getSlot() == slot) {
sender.sendMessage(prefix + " There is already a world at slot " + slot + "!");
return true;
@@ -1026,21 +1026,31 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
if (lw == null)
return false;
GameMode change = GameMode.SURVIVAL;
- try {
- change = GameMode.valueOf(args[2].toUpperCase());
- } catch (Exception e) {
+ String name = null;
+ String save = null;
+ if (args[2].equalsIgnoreCase("Any")) {
+ change = null;
+ name = "Any";
+ save = null;
+ } else {
try {
- change = GameMode.getByValue(Integer.parseInt(args[2]));
- } catch (Exception e2) {
- e.printStackTrace();
+ change = GameMode.valueOf(args[2].toUpperCase());
+ } catch (Exception e) {
+ try {
+ change = GameMode.getByValue(Integer.parseInt(args[2]));
+ } catch (Exception e2) {
+ e.printStackTrace();
+ }
}
+
+ name = change.name();
+ save = change.toString();
}
lw.setGameMode(change);
- m.getConfig().set("Worlds." + lw.getWorldName() + ".gamemode", change.toString());
+ m.getConfig().set("Worlds." + lw.getWorldName() + ".gamemode", save);
m.saveConfig();
- sender.sendMessage(
- prefix + "Changed gamemode for \"" + lw.getWorldName() + "\" to " + change.name() + ".");
+ sender.sendMessage(prefix + "Changed gamemode for \"" + lw.getWorldName() + "\" to " + name + ".");
} else {
sender.sendMessage(
prefix + " Usage:" + ChatColor.BOLD + " /LobbyAPI setGameMode [name] [gamemode]");
@@ -1122,7 +1132,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
LobbyAPI.unregisterWorld(wo);
sender.sendMessage(prefix + "Removed world \"" + wo.getName() + "\"");
m.loadLocalWorlds();
- //ConfigHandler.setWorldVariable(wo.getName(), ConfigKeys.CustomAddedWorlds_Seed, null);
+ // ConfigHandler.setWorldVariable(wo.getName(),
+ // ConfigKeys.CustomAddedWorlds_Seed, null);
Bukkit.unloadWorld(wo, true);
} else {
@@ -1329,16 +1340,14 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
for (int i = page * msgPerPage; i < (page * msgPerPage) + msgPerPage; i++) {
if (i >= usages.size())
break;
- sender.sendMessage(ChatColor.GOLD + "/lobbyAPI " + ((String) usages.keySet().toArray()[i]));
- sender.sendMessage(ChatColor.WHITE + usages.get((String) usages.keySet().toArray()[i]));
+ sender.sendMessage(ChatColor.GOLD + "/lobbyAPI " + usages.keySet().toArray()[i]);
+ sender.sendMessage(ChatColor.WHITE + usages.get(usages.keySet().toArray()[i]));
}
return true;
}
}
- if (cmd.getName().equalsIgnoreCase("Lobby") || cmd.getName().equalsIgnoreCase("hub"))
-
- {
+ if (cmd.getName().equalsIgnoreCase("Lobby") || cmd.getName().equalsIgnoreCase("hub")) {
if (sender instanceof Player) {
Player player = (Player) sender;
@@ -1351,10 +1360,9 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
}
m.setInventorySize(false);
- m.inventory = m.getServer().createInventory(null, m.inventorySize,
- m.title);
+ m.inventory = m.getServer().createInventory(null, m.inventorySize, m.title);
- for (LobbyWorld wo : m.worlds) {
+ for (LobbyWorld wo : LobbyWorld.getLobbyWorlds()) {
if (wo != null) {
if (wo.isHidden())
continue;
@@ -1364,9 +1372,9 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
ls.add(ChatColor.BOLD + "" + ChatColor.YELLOW + "Main World");
ls.addAll(wo.getDescription());
Set players = wo.getPlayers();
- if(wo.getNether()!=null)
+ if (wo.getNether() != null)
players.addAll(wo.getNether().getPlayers());
- if(wo.getEnd()!=null)
+ if (wo.getEnd() != null)
players.addAll(wo.getEnd().getPlayers());
String players2 = ChatColor.GOLD + "" + players.size() + " Players ";
@@ -1506,10 +1514,10 @@ public void generateConnctingWorlds(LobbyWorld mainWorld) {
.generator(Bukkit.getWorlds().get(2).getGenerator()).seed(mainWorld.getWorld().getSeed()));
end = Bukkit.getWorld(wo.getName() + "_the_end");
}
- int netherid = LobbyAPI.getOpenSlot(10);
- int endid = LobbyAPI.getOpenSlot(10);
+ //int netherid = LobbyAPI.getOpenSlot(10);
+ //int endid = LobbyAPI.getOpenSlot(10);
- @SuppressWarnings("deprecation")
+ /*@SuppressWarnings("deprecation")
LobbyWorld n = LobbyAPI.registerWorldFromConfig(nether, nether.getSpawnLocation(), mainWorld.getSaveName(),
null, 0, netherid, mainWorld.getGameMode(), true);
@SuppressWarnings("deprecation")
@@ -1518,24 +1526,24 @@ public void generateConnctingWorlds(LobbyWorld mainWorld) {
saveWorld(mainWorld.getSaveName(), nether, nether.getSpawnLocation(), 0, netherid, true, true,
mainWorld.getWorldName());
- saveWorld(mainWorld.getSaveName(), end, end.getSpawnLocation(), 0, endid, true, true, mainWorld.getWorldName());
+ saveWorld(mainWorld.getSaveName(), end, end.getSpawnLocation(), 0, endid, true, true, mainWorld.getWorldName());*/
mainWorld.setNether(nether);
mainWorld.setEnd(end);
- n.setNether(wo);
- e.setEnd(wo);
+ //n.setNether(wo);
+ //e.setEnd(wo);
mainWorld.setPortal(true);
m.getConfig().set("Worlds." + wo.getName() + "." + ConfigKeys.CanUsePortals, true);
- m.getConfig().set("Worlds." + nether.getName() + "." + ConfigKeys.WORLDENVIROMENT, Environment.NETHER.name());
- m.getConfig().set("Worlds." + end.getName() + "." + ConfigKeys.WORLDENVIROMENT, Environment.THE_END.name());
+ //m.getConfig().set("Worlds." + nether.getName() + "." + ConfigKeys.WORLDENVIROMENT, Environment.NETHER.name());
+ //m.getConfig().set("Worlds." + end.getName() + "." + ConfigKeys.WORLDENVIROMENT, Environment.THE_END.name());
m.getConfig().set("Worlds." + wo.getName() + "." + ConfigKeys.LINKED_NETHER, nether.getName());
- m.getConfig().set("Worlds." + nether.getName() + "." + ConfigKeys.LINKED_NETHER, wo.getName());
+ // m.getConfig().set("Worlds." + nether.getName() + "." + ConfigKeys.LINKED_NETHER, wo.getName());
m.getConfig().set("Worlds." + wo.getName() + "." + ConfigKeys.LINKED_END, end.getName());
- m.getConfig().set("Worlds." + end.getName() + "." + ConfigKeys.LINKED_END, wo.getName());
+ //m.getConfig().set("Worlds." + end.getName() + "." + ConfigKeys.LINKED_END, wo.getName());
m.saveConfig();
}
- public void saveWorld(String fi, String savename, World wo, Location l, int color, int i, boolean hidden) {
+ private void saveWorld(String fi, String savename, World wo, Location l, int color, int i, boolean hidden) {
boolean k = false;
String j = null;
if (wo == Bukkit.getWorlds().get(1) || wo == Bukkit.getWorlds().get(2)) {
@@ -1549,10 +1557,10 @@ public void saveWorld(String fi, String savename, World wo, Location l, int colo
}
- public void saveWorld(String savename, World wo, Location l, int color, int i, boolean hidden,
- boolean canUsePortals, String connectedTo) {
+ private void saveWorld(String savename, World wo, Location l, int color, int i, boolean hidden,
+ boolean canUsePortals, String connectedTo) {
m.getConfig().set("Worlds." + wo.getName() + ".name", wo.getName());
- //m.getConfig().set("Worlds." + wo.getName() + ".displayname", wo.getName());
+ // m.getConfig().set("Worlds." + wo.getName() + ".displayname", wo.getName());
m.getConfig().set("Worlds." + wo.getName() + ".spawnLoc.x", l.getX());
m.getConfig().set("Worlds." + wo.getName() + ".spawnLoc.y", l.getY());
m.getConfig().set("Worlds." + wo.getName() + ".spawnLoc.z", l.getZ());
@@ -1561,19 +1569,18 @@ public void saveWorld(String savename, World wo, Location l, int color, int i, b
m.getConfig().set("Worlds." + wo.getName() + ".spawnLoc.w", l.getWorld().getName());
m.getConfig().set("Worlds." + wo.getName() + ".weatherstate", WeatherState.NORMAL.name());
m.getConfig().set("Worlds." + wo.getName() + ".i", i);
- if(wo.getName() != savename)
- m.getConfig().set("Worlds." + wo.getName() + ".save", savename);
-
- //m.getConfig().set("Worlds." + wo.getName() + ".desc", "");
+ if (wo.getName() != savename)
+ m.getConfig().set("Worlds." + wo.getName() + ".save", savename);
+
+ // m.getConfig().set("Worlds." + wo.getName() + ".desc", "");
m.getConfig().set("Worlds." + wo.getName() + ".gamemode", GameMode.SURVIVAL.name());
m.getConfig().set("Worlds." + wo.getName() + ".color", color);
m.getConfig().set("Worlds." + wo.getName() + "." + ConfigKeys.isHidden, hidden);
m.getConfig().set("Worlds." + wo.getName() + ".canuseportals", canUsePortals);
- m.getConfig().set("Worlds." + wo.getName() + ".respawnWorld", connectedTo);
- m.getConfig().set("CustomWorlds." + wo.getName() + "."+ConfigKeys.CustomAddedWorlds_Seed, connectedTo);
-
- //m.getConfig().set("Worlds." + wo.getName() + ".maxPlayers", -1);
+ m.getConfig().set("CustomWorlds." + wo.getName() + "." + ConfigKeys.CustomAddedWorlds_Seed, connectedTo);
+
+ // m.getConfig().set("Worlds." + wo.getName() + ".maxPlayers", -1);
m.saveConfig();
}
diff --git a/src/me/zombie_striker/lobbyapi/LobbyDecor.java b/src/me/zombie_striker/lobbyapi/LobbyDecor.java
index 77f9880..b521bb6 100644
--- a/src/me/zombie_striker/lobbyapi/LobbyDecor.java
+++ b/src/me/zombie_striker/lobbyapi/LobbyDecor.java
@@ -1,13 +1,13 @@
package me.zombie_striker.lobbyapi;
-import java.util.List;
-
import org.bukkit.Material;
+import java.util.List;
+
public class LobbyDecor {
private int ID;
- private int amount=1;
+ private int amount = 1;
//private short color;
private Material material = Material.GRASS;
private short data = 0;
@@ -22,10 +22,11 @@ public LobbyDecor(int slot, String name, String displayname) {
this.displayname = displayname;
this.name = name;
}
-
+
public short getData() {
return data;
}
+
public void setData(short d) {
this.data = d;
}
diff --git a/src/me/zombie_striker/lobbyapi/LobbyIcon.java b/src/me/zombie_striker/lobbyapi/LobbyIcon.java
index cf4f348..65f2ae1 100644
--- a/src/me/zombie_striker/lobbyapi/LobbyIcon.java
+++ b/src/me/zombie_striker/lobbyapi/LobbyIcon.java
@@ -15,11 +15,11 @@
*/
package me.zombie_striker.lobbyapi;
+import org.bukkit.Material;
+
import java.util.ArrayList;
import java.util.List;
-import org.bukkit.Material;
-
public class LobbyIcon {
private String name;
@@ -44,14 +44,14 @@ public LobbyIcon(boolean loadedFC, String iconName, int ID, int amount, short co
this.color = color;
}
- public void setHidden(boolean b) {
- this.isHidden = b;
- }
-
public boolean isHidden() {
return this.isHidden;
}
+ public void setHidden(boolean b) {
+ this.isHidden = b;
+ }
+
public boolean loadedFromConfig() {
return this.loadedFromConfig;
}
@@ -59,7 +59,7 @@ public boolean loadedFromConfig() {
public int getSlot() {
return ID;
}
-
+
public void setSlot(int slot) {
this.ID = slot;
}
@@ -71,6 +71,7 @@ public String getName() {
public short getColor() {
return this.color;
}
+
public void setColor(short color) {
this.color = color;
}
@@ -79,6 +80,10 @@ public Material getMaterial() {
return this.material;
}
+ public void setMaterial(Material m) {
+ this.material = m;
+ }
+
public int getAmount() {
return this.amount;
}
@@ -87,24 +92,20 @@ public void setAmount(int amount) {
this.amount = amount;
}
- public void setMaterial(Material m) {
- this.material = m;
+ public List getLore() {
+ return lore;
}
public void setLore(List lore) {
this.lore = lore;
}
- public List getLore() {
- return lore;
+ public String getDisplayName() {
+ return displayname;
}
public void setDisplayName(String displayname) {
this.displayname = displayname;
}
- public String getDisplayName() {
- return displayname;
- }
-
}
diff --git a/src/me/zombie_striker/lobbyapi/LobbyServer.java b/src/me/zombie_striker/lobbyapi/LobbyServer.java
index 43552cf..0a22130 100644
--- a/src/me/zombie_striker/lobbyapi/LobbyServer.java
+++ b/src/me/zombie_striker/lobbyapi/LobbyServer.java
@@ -23,11 +23,11 @@ public LobbyServer(boolean loadedFC, String servername, int ID, int amount, shor
super(loadedFC, servername, ID, amount, color);
}
- public void setPlayerCount(int a) {
- this.playerCount = a;
- }
-
public int getPlayerCount() {
return playerCount;
}
+
+ public void setPlayerCount(int a) {
+ this.playerCount = a;
+ }
}
diff --git a/src/me/zombie_striker/lobbyapi/LobbyWorld.java b/src/me/zombie_striker/lobbyapi/LobbyWorld.java
index 74eea73..6017aef 100644
--- a/src/me/zombie_striker/lobbyapi/LobbyWorld.java
+++ b/src/me/zombie_striker/lobbyapi/LobbyWorld.java
@@ -15,29 +15,16 @@
*/
package me.zombie_striker.lobbyapi;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.UUID;
-
-import org.bukkit.Bukkit;
-import org.bukkit.GameMode;
-import org.bukkit.Location;
-import org.bukkit.OfflinePlayer;
-import org.bukkit.World;
-import org.bukkit.WorldCreator;
+import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
+import java.util.*;
+
public class LobbyWorld extends LobbyIcon {
private static LobbyWorld MAIN_LOBBY = null;
-
- public static LobbyWorld getMainLobby() {
- return MAIN_LOBBY;
- }
-
+ private static Set worlds = new HashSet();
private Location spawn;
private boolean canUsePortal = false;
private boolean canUseEnderChest;
@@ -46,63 +33,85 @@ public static LobbyWorld getMainLobby() {
private boolean disableVoidDeath;
private int staticTime;
private WeatherState weatherState = WeatherState.NORMAL;
-
private boolean hasMaxPlayers;
private int maxPlayers;
-
private World mainWorld;
-
private World nether;
private World end;
- private World respawnWorld;
-
private boolean isPrivate;
private Set allowedPlayersUUID = new HashSet();
- // private Set allowedPlayersString = new HashSet();
-
private List commandsIssed = new ArrayList<>();
-
private List portalLocations = new ArrayList();
-
private boolean shouldSavePlayerLocation = false;
-
private List worldItems;
private GameMode gamemode = null;
-
private List worldDescription = new ArrayList();
private String saveName;
-
private boolean isLobby = false;
- public void setNether(World nether) {
- this.nether = nether;
+ public LobbyWorld(boolean loadedFC, String worldname, int ID, int amount, short color, Location spawn,
+ String saveName, GameMode gm) {
+ super(loadedFC, worldname, ID, amount, color);
+ this.mainWorld = Bukkit.getWorld(worldname.toLowerCase());
+ this.spawn = spawn;
+ this.saveName = saveName;
+ this.gamemode = gm;
}
- public void setEnd(World end) {
- this.end = end;
+ public static LobbyWorld getLobbyWorldFromWorld(World world) {
+ for (LobbyWorld lw : worlds) {
+ if (lw.getWorld() == world || (lw.getNether() != null && lw.getNether() == world) || (lw.getEnd() != null && lw.getEnd() == world))
+ return lw;
+ }
+ return null;
+ }
+
+ public static Set getLobbyWorlds() {
+ return worlds;
+ }
+
+ public static LobbyWorld getMainLobby() {
+ return MAIN_LOBBY;
+ }
+
+ /**
+ * Changes the Main lobby world.
+ *
+ * @param lw
+ */
+ public static void setMainLobby(LobbyWorld lw) {
+ MAIN_LOBBY = lw;
+ }
+
+ /**
+ * Removes main lobby world.
+ *
+ * @param lw
+ */
+ public static void removeMainLobby() {
+ MAIN_LOBBY = null;
}
public World getNether() {
return nether;
}
- public World getEnd() {
- return end;
+ public void setNether(World nether) {
+ this.nether = nether;
}
- public List getPortalLocations() {
- return portalLocations;
+ public World getEnd() {
+ return end;
}
- public void setPortalLocations(List loc) {
- portalLocations = loc;
+ public void setEnd(World end) {
+ this.end = end;
}
/**
* Sets whether a world should save the location of a world.
- *
- * @param should
- * save the location for a world
+ *
+ * @param should save the location for a world
* @return
*/
public void setWorldShouldSavePlayerLocation(boolean b) {
@@ -111,9 +120,8 @@ public void setWorldShouldSavePlayerLocation(boolean b) {
/**
* Sets whether a world should save the location of a world.
- *
- * @param should
- * save the location for a world
+ *
+ * @param should save the location for a world
* @return
*/
public boolean shouldWorldShouldSavePlayerLocation() {
@@ -123,7 +131,7 @@ public boolean shouldWorldShouldSavePlayerLocation() {
/**
* Returns if a world has food and health disabled. Useful for worlds where you
* don't want players to die.
- *
+ *
* @return
*/
public boolean hasDisabledHungerAndHealth() {
@@ -132,7 +140,7 @@ public boolean hasDisabledHungerAndHealth() {
/**
* Sets if a world will disable food and health
- *
+ *
* @param b
*/
public void setDisableHungerAndHealth(boolean b) {
@@ -141,7 +149,7 @@ public void setDisableHungerAndHealth(boolean b) {
/**
* Returns if a world has the void disabled. Useful for lobby worlds
- *
+ *
* @return
*/
public boolean hasVoidDisable() {
@@ -150,90 +158,22 @@ public boolean hasVoidDisable() {
/**
* Sets if a world will disable food and health
- *
+ *
* @param b
*/
public void setVoidDisable(boolean b) {
this.disableVoidDeath = b;
}
- /**
- * Changes the Main lobby world.
- *
- * @param lw
- */
- public static void setMainLobby(LobbyWorld lw) {
- MAIN_LOBBY = lw;
- }
-
/**
* Sets the Main lobby world to be equal to this world.
- *
+ *
* @param lw
*/
public void setAsMainLobby() {
MAIN_LOBBY = this;
}
- /**
- * Removes main lobby world.
- *
- * @param lw
- */
- public static void removeMainLobby() {
- MAIN_LOBBY = null;
- }
-
- public LobbyWorld(boolean loadedFC, String worldname, int ID, int amount, short color, Location spawn,
- String saveName, GameMode gm) {
- super(loadedFC, worldname, ID, amount, color);
- this.mainWorld = Bukkit.getWorld(worldname.toLowerCase());
- this.spawn = spawn;
- this.saveName = saveName;
- this.gamemode = gm;
-
- // this.canUsePortal =
- // ((mainWorld!=null&&Bukkit.getWorlds().get(0).equals(mainWorld))||worldname.equals("world_nether"));
- }
-
- public enum WeatherState {
- NORMAL(0), NO_RAIN(1), ALWAYS_RAIN(2);
-
- int data;
-
- private WeatherState(int data) {
- this.data = data;
- }
-
- public static WeatherState getWeatherStateByName(String name) {
- if (name == null)
- return null;
-
- if (name.equalsIgnoreCase("normal"))
- return NORMAL;
- if (name.equalsIgnoreCase("always_rain"))
- return ALWAYS_RAIN;
- if (name.equalsIgnoreCase("no_rain"))
- return NO_RAIN;
- return null;
- }
-
- public String toString() {
- if (data == 0)
- return "NORMAL";
- if (data == 1)
- return "NO_RAIN";
- if (data == 2)
- return "ALWAYS_RAIN";
- return "null";
- }
-
- public int getRawValue() {
- return data;
- }
-
- }
-
public void addCommand(String commands) {
this.commandsIssed.add(commands);
}
@@ -242,33 +182,26 @@ public List getCommandsOnJoin() {
return this.commandsIssed;
}
- public void setSaveName(String savename) {
- this.saveName = savename;
+ public WeatherState getWeatherState() {
+ return this.weatherState;
}
public void setWeatherState(WeatherState weatherstate) {
this.weatherState = weatherstate;
}
- public WeatherState getWeatherState() {
- return this.weatherState;
+ public boolean isLobby() {
+ return this.isLobby;
}
public void setLobby(boolean b) {
this.isLobby = b;
}
- public boolean isLobby() {
- return this.isLobby;
- }
-
public String getWorldName() {
return getName();
}
- public World getRespawnWorld() {
- return respawnWorld;
- }
public Location getSpawn() {
if (spawn.getWorld() == null) {
@@ -284,6 +217,10 @@ public Location getSpawn() {
return spawn;
}
+ public void setSpawn(Location l) {
+ spawn = l;
+ }
+
public boolean hasPortal() {
return canUsePortal;
}
@@ -303,6 +240,17 @@ public int getStaticTime() {
return 0;
}
+ /**
+ * @param i is the time the world is set to. Will
+ */
+ public void setStaticTime(int i) {
+ if (i < 0)
+ this.isStaticTime = false;
+ else
+ this.isStaticTime = false;
+ this.staticTime = i;
+ }
+
public boolean hasMainWorld() {
return this.mainWorld != null;
}
@@ -312,6 +260,10 @@ public World getMainWorld() {
return getWorld();
}
+ public void setMainWorld(World w) {
+ this.mainWorld = w;
+ }
+
public World getWorld() {
return this.mainWorld;
}
@@ -356,24 +308,32 @@ public List getSpawnItems() {
return worldItems;
}
+ public void setSpawnItems(List i) {
+ worldItems = i;
+ }
+
public String getSaveName() {
return saveName;
}
+ public void setSaveName(String savename) {
+ this.saveName = savename;
+ }
+
public List getDescription() {
return worldDescription;
}
- public GameMode getGameMode() {
- return this.gamemode;
+ public void setDescription(List l) {
+ worldDescription = l;
}
- public void setRespawnWorld(World world) {
- respawnWorld = world;
+ public GameMode getGameMode() {
+ return this.gamemode;
}
- public void setSpawn(Location l) {
- spawn = l;
+ public void setGameMode(GameMode g) {
+ this.gamemode = g;
}
public void setPortal(boolean b) {
@@ -384,23 +344,6 @@ public void setEnderChest(boolean b) {
canUseEnderChest = b;
}
- /**
- *
- * @param i
- * is the time the world is set to. Will
- */
- public void setStaticTime(int i) {
- if (i < 0)
- this.isStaticTime = false;
- else
- this.isStaticTime = false;
- this.staticTime = i;
- }
-
- public void setMainWorld(World w) {
- this.mainWorld = w;
- }
-
public void setStaticTime(boolean b, int i) {
this.isStaticTime = b;
this.staticTime = i;
@@ -411,10 +354,6 @@ public void setMaxPlayers(boolean b, int max) {
this.maxPlayers = max;
}
- public void setGameMode(GameMode g) {
- this.gamemode = g;
- }
-
public void setIsPrivate(boolean b) {
isPrivate = b;
}
@@ -445,11 +384,41 @@ public List whitelistToString() {
return list;
}
- public void setSpawnItems(List i) {
- worldItems = i;
- }
+ public enum WeatherState {
+ NORMAL(0), NO_RAIN(1), ALWAYS_RAIN(2);
+
+ int data;
+
+ WeatherState(int data) {
+ this.data = data;
+ }
+
+ public static WeatherState getWeatherStateByName(String name) {
+ if (name == null)
+ return null;
+
+ if (name.equalsIgnoreCase("normal"))
+ return NORMAL;
+ if (name.equalsIgnoreCase("always_rain"))
+ return ALWAYS_RAIN;
+ if (name.equalsIgnoreCase("no_rain"))
+ return NO_RAIN;
+ return null;
+ }
+
+ public String toString() {
+ if (data == 0)
+ return "NORMAL";
+ if (data == 1)
+ return "NO_RAIN";
+ if (data == 2)
+ return "ALWAYS_RAIN";
+ return "null";
+ }
+
+ public int getRawValue() {
+ return data;
+ }
- public void setDescription(List l) {
- worldDescription = l;
}
}
diff --git a/src/me/zombie_striker/lobbyapi/Main.java b/src/me/zombie_striker/lobbyapi/Main.java
index c3481ff..a3eef51 100644
--- a/src/me/zombie_striker/lobbyapi/Main.java
+++ b/src/me/zombie_striker/lobbyapi/Main.java
@@ -15,20 +15,19 @@
*/
package me.zombie_striker.lobbyapi;
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.util.*;
-import java.util.concurrent.ThreadLocalRandom;
-
+import com.google.common.io.ByteArrayDataOutput;
+import com.google.common.io.ByteStreams;
import me.zombie_striker.lobbyapi.LobbyWorld.WeatherState;
-import me.zombie_striker.lobbyapi.utils.*;
+import me.zombie_striker.lobbyapi.utils.ConfigHandler;
import me.zombie_striker.lobbyapi.utils.ConfigHandler.ConfigKeys;
-
+import me.zombie_striker.lobbyapi.utils.GithubUpdater;
+import me.zombie_striker.lobbyapi.utils.Metrics;
+import me.zombie_striker.lobbyapi.utils.UpdateAnouncer;
import org.bukkit.*;
import org.bukkit.World.Environment;
import org.bukkit.configuration.file.FileConfiguration;
-import org.bukkit.entity.*;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
import org.bukkit.event.*;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageEvent;
@@ -40,37 +39,41 @@
import org.bukkit.event.player.*;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.event.weather.WeatherChangeEvent;
-import org.bukkit.inventory.*;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
-import org.bukkit.potion.*;
+import org.bukkit.potion.PotionEffect;
+import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
-import com.google.common.io.ByteArrayDataOutput;
-import com.google.common.io.ByteStreams;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.*;
+import java.util.concurrent.ThreadLocalRandom;
public class Main extends JavaPlugin implements Listener {
- private HashMap lastWorld = new HashMap();
- Set worlds = new HashSet();
+ private static String prefix = ChatColor.GOLD + "[" + ChatColor.WHITE + "LobbyAPI" + ChatColor.GOLD + "]"
+ + ChatColor.WHITE;
Set bungeeServers = new HashSet();
Set decor = new HashSet();
Random random = ThreadLocalRandom.current();
int inventorySize = 9;
Inventory inventory;
-
+ String title = ChatColor.GOLD + "LobbyAPI " + ChatColor.WHITE + "- World selector";
+ private HashMap lastWorld = new HashMap();
@SuppressWarnings("unused")
private LobbyAPI la = new LobbyAPI(this);
-
- String title = ChatColor.GOLD + "LobbyAPI " + ChatColor.WHITE + "- World selector";
-
private boolean enablePWI = true;
-
private ItemStack worldSelector = null;
- private static String prefix = ChatColor.GOLD + "[" + ChatColor.WHITE + "LobbyAPI" + ChatColor.GOLD + "]"
- + ChatColor.WHITE;
+ public static String getPrefix() {
+ return prefix;
+ }
@EventHandler
public void event(WeatherChangeEvent e) {
@@ -115,15 +118,6 @@ public void onEnable() {
if (getConfig().contains("CustomWorlds")) {
try {
- /*
- * for (String w : ConfigHandler.getCustomWorldKeys()) Bukkit.createWorld(new
- * WorldCreator(w.toLowerCase())
- * .environment(ConfigHandler.containsWorldVariable(w,
- * ConfigKeys.WORLDENVIROMENT) ? Environment.valueOf((String)
- * ConfigHandler.getWorldVariableObject(w, ConfigKeys.WORLDENVIROMENT)) :
- * Environment.NORMAL) .seed(ConfigHandler.getCustomWorldInt(w,
- * ConfigKeys.CustomAddedWorlds_Seed)));
- */
for (String w : getConfig().getConfigurationSection("CustomWorlds").getKeys(false)) {
if (getConfig().contains("CustomWorlds." + w + ".Seeds")) {
getConfig().set("Worlds." + w + "." + ConfigKeys.CustomAddedWorlds_Seed,
@@ -147,7 +141,7 @@ public void onEnable() {
*/
Environment env = ConfigHandler.containsWorldVariable(name, ConfigKeys.WORLDENVIROMENT)
? Environment.valueOf(
- (String) ConfigHandler.getWorldVariableObject(name, ConfigKeys.WORLDENVIROMENT))
+ (String) ConfigHandler.getWorldVariableObject(name, ConfigKeys.WORLDENVIROMENT))
: Environment.NORMAL;
WorldCreator wc = new WorldCreator(name.toLowerCase()).environment(env)
.seed(ConfigHandler.getWorldVariableInt(name, ConfigKeys.CustomAddedWorlds_Seed));
@@ -170,14 +164,15 @@ public void onEnable() {
}
enablePWI = ConfigHandler.getLobbyAPIVariableBoolean(ConfigKeys.ENABLE_PER_WORLD_INVENTORIES);
-
- if (Bukkit.getPluginManager().getPlugin("Multiverse-Inventories") != null) {
- Bukkit.getPluginManager().disablePlugin(Bukkit.getPluginManager().getPlugin("Multiverse-Inventories"));
+ Plugin minv = Bukkit.getPluginManager().getPlugin("Multiverse-Inventories");
+ if (minv != null) {
+ Bukkit.getPluginManager().disablePlugin(minv);
Bukkit.broadcastMessage(prefix
+ " LobbyAPI is incompatible with Multiverse-Inventories. Remove Multiverse-Inventories, as LobbyAPI should handle multiple inventories");
}
- if (Bukkit.getPluginManager().getPlugin("PerWorldInventory") != null) {
- Bukkit.getPluginManager().disablePlugin(Bukkit.getPluginManager().getPlugin("PerWorldInventory"));
+ Plugin pwi = Bukkit.getPluginManager().getPlugin("PerWorldInventory");
+ if (pwi != null) {
+ Bukkit.getPluginManager().disablePlugin(pwi);
Bukkit.broadcastMessage(prefix
+ " LobbyAPI is incompatible with PerWorldInventory. Remove PerWorldInventory, as LobbyAPI should handle multiple inventories");
}
@@ -191,7 +186,7 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
new BukkitRunnable() {
public void run() {
- for (LobbyWorld lb : getWorlds()) {
+ for (LobbyWorld lb : LobbyWorld.getLobbyWorlds()) {
if (lb.hasVoidDisable()) {
for (Player p : lb.getWorld().getPlayers()) {
if (p.getLocation().getY() < -2) {
@@ -204,13 +199,6 @@ public void run() {
}
}.runTaskTimer(this, 0, 20);
- // Time Check
- /*
- * new BukkitRunnable() { public void run() { for (LobbyWorld wo : worlds) if
- * (wo != null && wo.hasStaticTime())
- * getServer().getWorld(wo.getWorldName()).setTime(wo.getStaticTime()); }
- * }.runTaskTimer(this, 0, 10 * 20L);
- */
if (getConfig() != null && getConfig().contains("hasBungee") && getConfig().getBoolean("hasBungee")) {
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
getServer().getConsoleSender().sendMessage(prefix + ChatColor.GREEN + "Bungee For LobbyAPI is enabled");
@@ -235,14 +223,14 @@ public void run() {
Metrics met = new Metrics(this);
/*
* met.addCustomChart(new Metrics.SimplePie("worlds-loaded") {
- *
+ *
* @Override public String getValue() { return String.valueOf(worlds.size()); }
* }); met.addCustomChart(new Metrics.SimplePie("bungee-support") {
- *
+ *
* @Override public String getValue() { return
* String.valueOf(bungeeServers.size()); } }); met.addCustomChart(new
* Metrics.SimplePie("updater-active") {
- *
+ *
* @Override public String getValue() { return
* String.valueOf(getConfig().getBoolean("auto-update")); } });
*/
@@ -266,7 +254,7 @@ public void onDisable() {
public void setInventorySize(boolean isOp) {
int maxSlot = 0;
- for (LobbyWorld w : this.worlds) {
+ for (LobbyWorld w : LobbyWorld.getLobbyWorlds()) {
if (w.isHidden())
continue;
if (w != null && w.getSlot() > maxSlot) {
@@ -337,7 +325,7 @@ private void onDeath(PlayerDeathEvent event) {
@SuppressWarnings("deprecation")
@EventHandler
private void onPlayerDeath(PlayerRespawnEvent event) {
- LobbyWorld lb = LobbyAPI.getLobbyWorld(event.getPlayer().getWorld().getName());
+ LobbyWorld lb = LobbyAPI.getLobbyWorld(event.getPlayer().getWorld());
if (lb == null)
return;
@@ -345,32 +333,22 @@ private void onPlayerDeath(PlayerRespawnEvent event) {
if (!event.getPlayer().getWorld().getGameRuleValue("keepInventory").equalsIgnoreCase("true"))
clearInventory(event.getPlayer());
saveInventory(event.getPlayer(), event.getPlayer().getWorld());
-
- /*
- * if (lb == null) { if (lb.getMainWorld() != null) {
- * event.setRespawnLocation(LobbyAPI.getLobbyWorld(lb.getMainWorld()).getSpawn()
- * ); return; } else { return; } }
- */
-
- if (event.getPlayer().getBedSpawnLocation() != null
- && (event.getPlayer().getBedSpawnLocation().getWorld().equals(lb.getWorld())
- || (lb.getRespawnWorld() != null && event.getPlayer().getBedSpawnLocation().getWorld()
- .equals(LobbyAPI.getLobbyWorld(lb.getRespawnWorld()).getWorld()))))
- return;
- // Do not interfere if the player has a bed in this world.
-
- if (lb.getRespawnWorld() != null) {
- event.setRespawnLocation(LobbyAPI.getLobbyWorld(lb.getRespawnWorld()).getSpawn());
- // } else if (LobbyWorld.getMainLobby() != null) {
- // event.setRespawnLocation(LobbyWorld.getMainLobby().getSpawn());
- } else {
- event.setRespawnLocation(lb.getSpawn());
- // Should never happen. Test it
+ try {
+ if (event.getPlayer().getBedSpawnLocation() != null
+ && (event.getPlayer().getBedSpawnLocation().getWorld().equals(lb.getWorld())
+ /*|| (lb.getRespawnWorld() != null && event.getPlayer().getBedSpawnLocation().getWorld()
+ .equals(LobbyAPI.getLobbyWorld(lb.getRespawnWorld()).getWorld()))*/))
+ return;
+ } catch (Error | Exception e231124) {
}
- }
+ // Do not interfere if the player has a bed in this world.
- public static String getPrefix() {
- return prefix;
+ //if (lb.getRespawnWorld() != null) {
+ // event.setRespawnLocation(LobbyAPI.getLobbyWorld(lb.getRespawnWorld()).getSpawn());
+ //} else {
+ event.setRespawnLocation(lb.getSpawn());
+ // Should never happen. Test it
+ //}
}
@EventHandler
@@ -389,144 +367,101 @@ public void run() {
}
}.runTaskTimer(this, 0, 5);
}
- for (LobbyWorld wo : worlds)
+ for (LobbyWorld wo : LobbyWorld.getLobbyWorlds())
lastWorld.put(event.getPlayer().getName(), wo.hasMainWorld() ? wo.getWorld() : goingTo);
}
@EventHandler
private void onTeleport(EntityPortalEvent event) {
- LobbyWorld curr = LobbyAPI.getLobbyWorld(event.getFrom().getWorld());
- if (curr != null && !curr.hasPortal()) {
- event.setCancelled(true);
- Bukkit.broadcastMessage("previous world is null");
- return;
- }
- if (event.getTo().getWorld() == Bukkit.getWorlds().get(2)) {
- Location temp = event.getTo();
- if (temp == null) {
- if (event.getFrom().getWorld().getEnvironment() == Environment.THE_END) {
- temp = curr.getEnd().getSpawnLocation();// new Location(curr.getEnd(), 0, 100, 0);
- } else {
- temp = curr.getSpawn();
- }
- } else {
- temp.setWorld(curr.getEnd());
- }
- event.setTo(temp);
- } else if (event.getTo().getWorld() == Bukkit.getWorlds().get(1)) {
- Location temp = event.getTo();
- if (temp == null) {
- if (event.getFrom().getWorld().getEnvironment() == Environment.NETHER) {
- temp = new Location(curr.getNether(), event.getFrom().getX() * 8, event.getFrom().getY(),
- event.getFrom().getZ() * 8);
- } else {
- temp = new Location(curr.getNether(), event.getFrom().getX() / 8, event.getFrom().getY(),
- event.getFrom().getZ() / 8);
- }
- } else {
- temp.setWorld(curr.getNether());
- }
- event.setTo(temp);
- } else if (event.getTo().getWorld() == Bukkit.getWorlds().get(0)) {
- Location loc = event.getTo();
- if (curr.getNether() != null) {
- event.getTo().setWorld(curr.getNether());
- } else if (curr.getEnd() != null) {
- event.getTo().setWorld(curr.getEnd());
- }
- event.setTo(loc);
- }
+ LobbyWorld curr = LobbyAPI.getLobbyWorld(event.getFrom().getWorld());
+ Location to = handlePortalConversion(event.getEntity(), curr, event.getFrom(), event.getTo(), (event.getTo().getWorld() == Bukkit.getWorlds().get(2) ? TeleportCause.END_PORTAL : TeleportCause.NETHER_PORTAL),
+ event);
+ if (to != null)
+ event.setTo(to);
}
@EventHandler(priority = EventPriority.LOWEST)
private void onTeleport(PlayerPortalEvent event) {
LobbyWorld curr = LobbyAPI.getLobbyWorld(event.getFrom().getWorld());
+ Location to = handlePortalConversion(event.getPlayer(), curr, event.getFrom(), event.getTo(), event.getCause(),
+ event);
+ if (to != null) {
+ event.setTo(to);
+ }
+ }
+
+ private Location handlePortalConversion(Entity to, LobbyWorld curr, Location getFrom, Location getTo,
+ TeleportCause cause, Event event) {
if (curr != null && !curr.hasPortal()) {
- event.setCancelled(true);
+ ((Cancellable) event).setCancelled(true);
Bukkit.broadcastMessage("previous world is null");
- return;
+ return null;
}
- if (event.getCause() == TeleportCause.END_PORTAL) {
- Location temp = event.getTo();
- if (temp == null) {
- if (event.getFrom().getWorld().getEnvironment() == Environment.THE_END) {
- temp = curr.getEnd().getSpawnLocation();// new Location(curr.getEnd(), 0, 100, 0);
- } else {
- temp = curr.getSpawn();
- }
+ if (cause == TeleportCause.END_PORTAL) {
+ if (getFrom.getWorld().getEnvironment() == Environment.THE_END) {
+ getTo = curr.getSpawn();// new Location(curr.getEnd(), 0, 100, 0);
} else {
- temp.setWorld(curr.getEnd());
+ getTo = curr.getEnd().getSpawnLocation();
}
- event.setTo(temp);
- } else if (event.getCause() == TeleportCause.NETHER_PORTAL) {
- Location temp = event.getTo();
- if (temp == null) {
- if (event.getFrom().getWorld().getEnvironment() == Environment.NETHER) {
- temp = new Location(curr.getNether(), event.getFrom().getX() * 8, event.getFrom().getY(),
- event.getFrom().getZ() * 8);
- } else {
- temp = new Location(curr.getNether(), event.getFrom().getX() / 8, event.getFrom().getY(),
- event.getFrom().getZ() / 8);
- }
+ return getTo;
+ } else if (cause == TeleportCause.NETHER_PORTAL) {
+ if (getFrom.getWorld().getEnvironment() == Environment.NETHER) {
+ getTo = new Location(curr.getWorld(), getFrom.getX() * 8, getFrom.getY(), getFrom.getZ() * 8);
} else {
- temp.setWorld(curr.getNether());
+ getTo = new Location(curr.getNether(), getFrom.getX() / 8, getFrom.getY(), getFrom.getZ() / 8);
}
- event.setTo(temp);
- } else if (event.getTo().getWorld() == Bukkit.getWorlds().get(0)) {
- Location loc = event.getTo();
+ return getTo;
+ } else if (getTo.getWorld() == Bukkit.getWorlds().get(0)) {
if (curr.getNether() != null) {
- event.getTo().setWorld(curr.getNether());
+ getTo.setWorld(curr.getNether());
} else if (curr.getEnd() != null) {
- event.getTo().setWorld(curr.getEnd());
+ getTo.setWorld(curr.getEnd());
}
- if (loc != null)
- event.setTo(loc);
+ return getTo;
}
+ return null;
+
}
@EventHandler(priority = EventPriority.LOWEST)
private void onWorldchange(PlayerChangedWorldEvent event) {
final Player p = event.getPlayer();
saveInventory(p, event.getFrom());
- LobbyWorld lw = LobbyAPI.getLobbyWorld(p.getWorld());
- final boolean sameWorld;
- if (lw != null && LobbyAPI.getLobbyWorld(event.getFrom()) != null) {
- sameWorld = lw.getSaveName().equals(LobbyAPI.getLobbyWorld(event.getFrom()).getSaveName());
- } else
- sameWorld = false;
+ final LobbyWorld lw = LobbyAPI.getLobbyWorld(p.getWorld());
+ final LobbyWorld lwF = LobbyAPI.getLobbyWorld(event.getFrom());
+ final boolean sameWorld = (lw == lwF);
+
+ lastWorld.put(p.getName(), p.getWorld());
+
if (lw != null) {
- // if (lw.shouldWorldShouldSavePlayerLocation())
- // lw.setLastLocation(event.getPlayer(), event.getPlayer().getLocation());
- // setLastLocationForWorld(event.getPlayer(), lw, event.getf);
if (enablePWI)
- if (!sameWorld) {
- clearInventory(p);
- }
+ clearInventory(p);
}
-
new BukkitRunnable() {
public void run() {
- if (LobbyAPI.getLobbyWorld(p.getWorld()) != null) {
+ LobbyWorld lfT = LobbyAPI.getLobbyWorld(p.getWorld());
+ if (lfT != null) {
if (enablePWI) {
// if (!sameWorld) {
clearInventory(p);
loadInventory(p, p.getWorld());
// }
}
- if (LobbyAPI.getLobbyWorld(p.getWorld()).getGameMode() != null)
- p.setGameMode(LobbyAPI.getLobbyWorld(p.getWorld().getName()).getGameMode());
+ if (lfT.getGameMode() != null && !lfT.getSaveName().equals(lwF.getSaveName()))
+ p.setGameMode(lfT.getGameMode());
- if (LobbyAPI.getLobbyWorld(p.getWorld()).getSpawnItems() != null
- && LobbyAPI.getLobbyWorld(p.getWorld()).getSpawnItems().size() > 0)
- for (ItemStack is : LobbyAPI.getLobbyWorld(p.getWorld()).getSpawnItems())
+ if (lfT.getSpawnItems() != null && lfT.getSpawnItems().size() > 0)
+ for (ItemStack is : lfT.getSpawnItems())
if (is != null)
if (!p.getInventory().containsAtLeast(is, 1))
p.getInventory().addItem(is);
}
+
lastWorld.put(p.getName(), p.getWorld());
}
- }.runTaskLater(this, 5);
+ }.runTaskLater(this, 2);
+
}
@EventHandler
@@ -543,7 +478,6 @@ public void onSelect(InventoryClickEvent event) {
boolean isBungee = false;
if (this.bungeeServers.size() > 0) {
-
for (String s : event.getCurrentItem().getItemMeta().getLore()) {
if (s.contains(ChatColor.RED + "" + ChatColor.GREEN)) {
isBungee = true;
@@ -562,7 +496,7 @@ public void onSelect(InventoryClickEvent event) {
}
} else
- for (LobbyWorld wo : worlds) {
+ for (LobbyWorld wo : LobbyWorld.getLobbyWorlds()) {
if (wo == null)
continue;
if (wo.getSlot() == event.getSlot() && !wo.isHidden()) {
@@ -578,16 +512,17 @@ public void onSelect(InventoryClickEvent event) {
.sendMessage(ChatColor.RED + "This world is full, please try again later.");
} else if (!event.getWhoClicked().hasPermission("lobbyapi.bypassworldlimits")
&& (wo.isPrivate() && !wo.getWhitelistedPlayersUUID()
- .contains(event.getWhoClicked().getUniqueId()))) {
+ .contains(event.getWhoClicked().getUniqueId()))) {
event.getWhoClicked()
.sendMessage(ChatColor.RED + "You are not whitelisted for this world.");
} else {
final PlayerSelectWorldEvent e = new PlayerSelectWorldEvent(
(Player) event.getWhoClicked(), wo);
- // TODO: Veify: If world does not save location, return spawn.
- if (getLastLocationForWorld((Player) event.getWhoClicked(), wo) != null) {
- e.setDestination(getLastLocationForWorld((Player) event.getWhoClicked(), wo));
+
+ Location lastLoc;
+ if ((lastLoc = getLastLocationForWorld((Player) event.getWhoClicked(), wo)) != null) {
+ e.setDestination(lastLoc);
}
Bukkit.getPluginManager().callEvent(e);
if (!e.getIsCanceled()) {
@@ -616,9 +551,9 @@ public void onSelect(InventoryClickEvent event) {
playersOnline
.append(((Player) oo[i]).getDisplayName()
+ (i != (oo.length - 1 < 7 ? oo.length - 1 : 7) ? " ,"
- : (oo.length - 7 > 0
- ? " ...(" + (oo.length - 7) + " more)"
- : "")));
+ : (oo.length - 7 > 0
+ ? " ...(" + (oo.length - 7) + " more)"
+ : "")));
try {
Method method = e.getPlayer().getClass().getMethod("sendTitle",
@@ -683,7 +618,7 @@ private void clearInventory(Player p) {
p.setHealth((double) 20);
p.setExp((float) 0);
p.setLevel(0);
- p.setFoodLevel((int) 20);
+ p.setFoodLevel(20);
for (PotionEffect ep : p.getActivePotionEffects())
p.removePotionEffect(ep.getType());
}
@@ -691,11 +626,11 @@ private void clearInventory(Player p) {
private void loadInventory(Player p, World w) {
if (w == null) {
getServer().getConsoleSender().sendMessage(
- prefix + " The world \"" + w + "\" is null! Inventories for this world will not be saved.");
+ prefix + " The world that " + p.getName() + " is teleporting to is null! Inventories for this world will not be saved.");
return;
}
if (LobbyAPI.getLobbyWorld(w) == null) {
- getServer().getConsoleSender().sendMessage(prefix + " You have no registered world called \"" + w.getName()
+ getServer().getConsoleSender().sendMessage(prefix + " You have no registered worlds called \"" + w.getName()
+ "\"! Inventories for this world will not be loaded.");
return;
}
@@ -727,10 +662,39 @@ private void loadInventory(Player p, World w) {
} catch (Error | Exception e2) {
}
- if (config.get(p.getName() + "." + s + ".xpl") != null)
+ if (config.contains(p.getName() + "." + s + ".xpl"))
p.setLevel((int) config.get(p.getName() + "." + s + ".xpl"));
- if (config.get(p.getName() + "." + s + ".hunger") != null)
+ if (config.contains(p.getName() + "." + s + ".xp"))
+ p.setExp((float) (double) config.get(p.getName() + "." + s + ".xp"));
+ if (config.contains(p.getName() + "." + s + ".hunger"))
p.setFoodLevel((int) config.get(p.getName() + "." + s + ".hunger"));
+
+ if (config.contains(p.getName() + "." + s + ".potions_effects")) {
+ for (String effect : config.getConfigurationSection(p.getName() + "." + s + ".potions_effects").getKeys(false)) {
+ PotionEffectType type = PotionEffectType.getByName(effect);
+ int duration = config.getInt(p.getName() + "." + s + ".potions_effects." + effect + ".dur");
+ int amplifier = config.getInt(p.getName() + "." + s + ".potions_effects." + effect + ".amp");
+ p.addPotionEffect(new PotionEffect(type, duration, amplifier));
+ }
+ }
+
+ if (config.contains(p.getName() + "." + s + ".allowflight"))
+ p.setAllowFlight(config.getBoolean(p.getName() + "." + s + ".allowflight"));
+ if (config.contains(p.getName() + "." + s + ".compasslocation"))
+ p.setCompassTarget((Location) config.get(p.getName() + "." + s + ".compasslocation"));
+ if (config.contains(p.getName() + "." + s + ".fireticks"))
+ p.setFireTicks(config.getInt(p.getName() + "." + s + ".fireticks"));
+ try {
+ if (config.contains(p.getName() + "." + s + ".bedspawn"))
+ p.setBedSpawnLocation((Location) config.get(p.getName() + "." + s + ".bedspawn"));
+ } catch (Error | Exception e45) {
+ }
+ if (config.contains(p.getName() + "." + s + ".saturation"))
+ p.setSaturation((float) (double) config.get(p.getName() + "." + s + ".saturation"));
+ if (config.contains(p.getName() + "." + s + ".exhaustion"))
+ p.setExhaustion((float) (double) config.get(p.getName() + "." + s + ".exhaustion"));
+ if (config.contains(p.getName() + "." + s + ".air"))
+ p.setRemainingAir(config.getInt(p.getName() + "." + s + ".air"));
}
private Location getLastLocationForWorld(Player p, LobbyWorld lw) {
@@ -878,6 +842,19 @@ private void saveInventory(Player p, LobbyWorld lw) {
config.set(p.getName() + "." + world2 + ".xpl", p.getLevel());
config.set(p.getName() + "." + world2 + ".health", p.getHealth());
config.set(p.getName() + "." + world2 + ".hunger", p.getFoodLevel());
+ config.set(p.getName() + "." + world2 + ".allowflight", p.getAllowFlight());
+ config.set(p.getName() + "." + world2 + ".compasslocation", p.getCompassTarget());
+ config.set(p.getName() + "." + world2 + ".fireticks", p.getFireTicks());
+ try {
+ try {
+ config.set(p.getName() + "." + world2 + ".bedspawn", p.getBedSpawnLocation());
+ } catch (Error | Exception e4) {
+ }
+ config.set(p.getName() + "." + world2 + ".exhaustion", p.getExhaustion());
+ config.set(p.getName() + "." + world2 + ".saturation", p.getSaturation());
+ config.set(p.getName() + "." + world2 + ".air", p.getRemainingAir());
+ } catch (Error | Exception e4) {
+ }
ItemStack[] is = p.getInventory().getContents();
config.set(p.getName() + "." + world2 + ".i", null);
for (int itemIndex = 0; itemIndex < 36; itemIndex++)
@@ -888,7 +865,6 @@ private void saveInventory(Player p, LobbyWorld lw) {
|| p.getInventory().getItemInOffHand().getType() == Material.AIR) {
config.set(p.getName() + "." + world2 + ".i.offhand", null);
} else {
- // if(config.contains(p.getName() + "." + world2 + ".i.offhand"))
config.set(p.getName() + "." + world2 + ".i.offhand", p.getInventory().getItemInOffHand());
}
} catch (Error | Exception e2) {
@@ -899,9 +875,12 @@ private void saveInventory(Player p, LobbyWorld lw) {
config.set(p.getName() + "." + world2 + ".a." + 3, p.getInventory().getChestplate());
config.set(p.getName() + "." + world2 + ".a." + 4, p.getInventory().getHelmet());
- // if (lw.shouldWorldShouldSavePlayerLocation()) {
- // config.set(p.getName() + "." + world2 + ".LastLocation", p.getLocation());
- // }
+ config.set(p.getName() + "." + world2 + ".potions_effects", null);
+ for (PotionEffect eff : p.getActivePotionEffects()) {
+ config.set(p.getName() + "." + world2 + ".potions_effects." + eff.getType().getName() + ".dur", eff.getDuration());
+ config.set(p.getName() + "." + world2 + ".potions_effects." + eff.getType().getName() + ".amo", eff.getAmplifier());
+ }
+
try {
config.save(tempHolder);
} catch (IOException e) {
@@ -929,10 +908,16 @@ public void loadDecor() {
public void loadLocalWorlds() {
final Main main = this;
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
- @SuppressWarnings({ "deprecation", "unchecked" })
+ @SuppressWarnings({"deprecation", "unchecked"})
public void run() {
if (getConfig().contains("Worlds")) {
for (final String key : getConfig().getConfigurationSection("Worlds").getKeys(false)) {
+ if (getConfig().contains("Worlds." + key + ".respawnWorld")) {
+ getConfig().set("Worlds." + key, null);
+ saveConfig();
+ continue;
+ }
+
try {
String name = getConfig().getString("Worlds." + key + ".name");
String displayname = null;
@@ -941,6 +926,10 @@ public void run() {
} else {
displayname = key;
}
+ /**
+ * Only here to make sure that the loc variable will **always** be removed in
+ * case a user updates
+ */
if (getConfig().contains("Worlds." + key + ".loc")) {
Location l = (Location) getConfig().get("Worlds." + key + ".loc");
if (l != null) {
@@ -954,10 +943,6 @@ public void run() {
Bukkit.broadcastMessage(prefix + " SpawnLocation has been reset for world " + name
+ ". Please reset the spawnlocation by using /LobbyAPI changeSpawn.");
}
- /**
- * Only here to make sure that the loc variable will **always** be removed in
- * case a user updates
- */
getConfig().set("Worlds." + key + ".loc", null);
saveConfig();
}
@@ -973,7 +958,7 @@ public void run() {
+ " for '" + name + "' was null. Re-creating world");
Environment env = ConfigHandler.containsWorldVariable(key, ConfigKeys.WORLDENVIROMENT)
? Environment.valueOf((String) ConfigHandler.getWorldVariableObject(key,
- ConfigKeys.WORLDENVIROMENT))
+ ConfigKeys.WORLDENVIROMENT))
: Environment.NORMAL;
WorldCreator wc = new WorldCreator(name.toLowerCase()).environment(env).seed(
ConfigHandler.getWorldVariableInt(key, ConfigKeys.CustomAddedWorlds_Seed));
@@ -986,11 +971,10 @@ public void run() {
w = Bukkit.createWorld(wc);
l = new Location(w, x, y, z);
if (l == null || w == null)
- Bukkit.getConsoleSender().sendMessage(prefix + ChatColor.RED
- + (w == null ? "WorldInst" : (w == null ? "Location" : "Something"))
- + " for '" + name
- + "' is still null after recreating world. Something may be wrong!");
+ Bukkit.getConsoleSender().sendMessage(prefix + ChatColor.RED + "WorldInst for '" + name + "' is still null after recreating world. Something may be wrong!");
}
+
+
if (getConfig().contains("Worlds." + key + ".spawnLoc.yaw")) {
float yaw = (float) getConfig().getDouble("Worlds." + key + ".spawnLoc.yaw");
float pitch = (float) getConfig().getDouble("Worlds." + key + ".spawnLoc.pitch");
@@ -1022,27 +1006,25 @@ public void run() {
false);
for (String jC : getConfig().getStringList("Worlds." + key + ".joincommands"))
lw.addCommand(jC);
- final World fWorld = w;
- new BukkitRunnable() {
-
- @Override
- public void run() {
- if (getConfig().contains("Worlds." + key + "." + ConfigKeys.PORTALLIST)) {
- List portals = new ArrayList<>();
- List listAsString = getConfig()
- .getStringList("Worlds." + key + "." + ConfigKeys.PORTALLIST);
- for (String a : listAsString) {
- String[] splits = a.split(",");
- int x2 = Integer.parseInt(splits[0]);
- int y2 = Integer.parseInt(splits[1]);
- int z2 = Integer.parseInt(splits[2]);
- Location portaltest = new Location(fWorld, x2, y2, z2);
- portals.add(portaltest);
- }
- lw.setPortalLocations(portals);
- }
- }
- }.runTaskLater(main, 2);
+
+
+ if (getConfig().contains("Worlds." + key + "." + ConfigKeys.LINKED_NETHER)) {
+ String connectname = getConfig().getString("Worlds." + key + "." + ConfigKeys.LINKED_NETHER);
+ Environment env = Environment.NETHER;
+ WorldCreator wc = new WorldCreator(connectname.toLowerCase()).environment(env).seed(w.getSeed());
+ wc.generator(Bukkit.getWorlds().get(1).getGenerator());
+ World nether = Bukkit.createWorld(wc);
+ lw.setNether(nether);
+ }
+ if (getConfig().contains("Worlds." + key + "." + ConfigKeys.LINKED_END)) {
+ String connectname = getConfig().getString("Worlds." + key + "." + ConfigKeys.LINKED_END);
+ Environment env = Environment.THE_END;
+ WorldCreator wc = new WorldCreator(connectname.toLowerCase()).environment(env).seed(w.getSeed());
+ wc.generator(Bukkit.getWorlds().get(2).getGenerator());
+ World end = Bukkit.createWorld(wc);
+ lw.setEnd(end);
+ }
+
if (getConfig().contains("Worlds." + key + ".weatherstate")) {
WeatherState ws = WeatherState.getWeatherStateByName(
@@ -1052,9 +1034,7 @@ public void run() {
lw.setDisplayName(displayname);
- boolean hidden = getConfig().contains("Worlds." + key + ".hidden")
- ? getConfig().getBoolean("Worlds." + key + ".hidden")
- : false;
+ boolean hidden = getConfig().contains("Worlds." + key + ".hidden") && getConfig().getBoolean("Worlds." + key + ".hidden");
lw.setHidden(hidden);
int maxplayers = getConfig().contains("Worlds." + key + ".maxPlayers")
@@ -1062,14 +1042,10 @@ public void run() {
: -1;
lw.setMaxPlayers(maxplayers >= 0, maxplayers);
- boolean locsaving = getConfig().contains("Worlds." + key + ".shouldsavelocation")
- ? getConfig().getBoolean("Worlds." + key + ".shouldsavelocation")
- : false;
+ boolean locsaving = getConfig().contains("Worlds." + key + ".shouldsavelocation") && getConfig().getBoolean("Worlds." + key + ".shouldsavelocation");
lw.setWorldShouldSavePlayerLocation(locsaving);
- boolean portal = getConfig().contains("Worlds." + key + ".canuseportals")
- ? getConfig().getBoolean("Worlds." + key + ".canuseportals")
- : false;
+ boolean portal = getConfig().contains("Worlds." + key + ".canuseportals") && getConfig().getBoolean("Worlds." + key + ".canuseportals");
lw.setPortal(portal);
if (getConfig().contains("Worlds." + key + ".connectedTo")) {
@@ -1078,22 +1054,6 @@ public void run() {
getConfig().set("Worlds." + key + ".connectedTo", null);
saveConfig();
}
- if (getConfig().contains("Worlds." + key + ".respawnWorld")) {
- lw.setRespawnWorld(Bukkit.getWorld(
- getConfig().getString("Worlds." + key + ".respawnWorld").toLowerCase()));
- }
- new BukkitRunnable() {
-
- @Override
- public void run() {
- if (getConfig().contains("Worlds." + key + "." + ConfigKeys.LINKED_END))
- lw.setEnd(Bukkit.getWorld(ConfigHandler
- .getWorldVariableString(key, ConfigKeys.LINKED_END).toLowerCase()));
- if (getConfig().contains("Worlds." + key + "." + ConfigKeys.LINKED_NETHER))
- lw.setNether(Bukkit.getWorld(ConfigHandler
- .getWorldVariableString(key, ConfigKeys.LINKED_NETHER).toLowerCase()));
- }
- }.runTaskLater(Main.this, 6);
if (ConfigHandler.containsWorldVariable(lw, ConfigKeys.DefaultItems))
lw.setSpawnItems((List) ConfigHandler.getWorldVariableObject(lw,
@@ -1105,9 +1065,7 @@ public void run() {
if (ConfigHandler.containsWorldVariable(lw, ConfigKeys.DisableVoid))
lw.setVoidDisable(ConfigHandler.getWorldVariableBoolean(lw, ConfigKeys.DisableVoid));
- boolean isprivate = getConfig().contains("Worlds." + key + ".isprivate")
- ? getConfig().getBoolean("Worlds." + key + ".isprivate")
- : false;
+ boolean isprivate = getConfig().contains("Worlds." + key + ".isprivate") && getConfig().getBoolean("Worlds." + key + ".isprivate");
List uuids = getConfig().contains("Worlds." + key + ".whitelistedUUIDS")
? getConfig().getStringList("Worlds." + key + ".whitelistedUUIDS")
: null;
@@ -1184,10 +1142,6 @@ public HashMap getLastWorld() {
return lastWorld;
}
- public Set getWorlds() {
- return worlds;
- }
-
public Set getBungeeServers() {
return bungeeServers;
}
diff --git a/src/me/zombie_striker/lobbyapi/PlayerChangeWorldEvent.java b/src/me/zombie_striker/lobbyapi/PlayerChangeWorldEvent.java
index 20fc0fc..3d0e981 100644
--- a/src/me/zombie_striker/lobbyapi/PlayerChangeWorldEvent.java
+++ b/src/me/zombie_striker/lobbyapi/PlayerChangeWorldEvent.java
@@ -20,24 +20,25 @@
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
-public final class PlayerChangeWorldEvent extends Event{
-
- private static final HandlerList handlers = new HandlerList();
- private Player teleporter;
-
- public PlayerChangeWorldEvent(Player teleporter) {
- this.teleporter = teleporter;
- }
-
- public Player getPlayer() {
- return teleporter;
- }
- public HandlerList getHandlers() {
- return handlers;
- }
-
- public static HandlerList getHandlerList() {
- return handlers;
- }
+public final class PlayerChangeWorldEvent extends Event {
+
+ private static final HandlerList handlers = new HandlerList();
+ private Player teleporter;
+
+ public PlayerChangeWorldEvent(Player teleporter) {
+ this.teleporter = teleporter;
+ }
+
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+
+ public Player getPlayer() {
+ return teleporter;
+ }
+
+ public HandlerList getHandlers() {
+ return handlers;
+ }
}
diff --git a/src/me/zombie_striker/lobbyapi/PlayerSelectWorldEvent.java b/src/me/zombie_striker/lobbyapi/PlayerSelectWorldEvent.java
index 89682d0..cc1541f 100644
--- a/src/me/zombie_striker/lobbyapi/PlayerSelectWorldEvent.java
+++ b/src/me/zombie_striker/lobbyapi/PlayerSelectWorldEvent.java
@@ -20,38 +20,43 @@
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
-public final class PlayerSelectWorldEvent extends Event{
-
- private static final HandlerList handlers = new HandlerList();
- private Player clicker;
- private Location des;
- private boolean isCanceled = false;
-
- public PlayerSelectWorldEvent(Player clicker,LobbyWorld selectedWorld) {
- this.clicker = clicker;
- this.des = selectedWorld.getSpawn();
- }
-
- public Player getPlayer() {
- return clicker;
- }
- public Location getDestination(){
- return des;
- }
- public void setDestination(Location location){
- this.des = location;
- }
- public boolean getIsCanceled(){
- return this.isCanceled;
- }
- public void setCanceled(boolean canceled){
- this.isCanceled = canceled;
- }
- public HandlerList getHandlers() {
- return handlers;
- }
-
- public static HandlerList getHandlerList() {
- return handlers;
- }
+public final class PlayerSelectWorldEvent extends Event {
+
+ private static final HandlerList handlers = new HandlerList();
+ private Player clicker;
+ private Location des;
+ private boolean isCanceled = false;
+
+ public PlayerSelectWorldEvent(Player clicker, LobbyWorld selectedWorld) {
+ this.clicker = clicker;
+ this.des = selectedWorld.getSpawn();
+ }
+
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+
+ public Player getPlayer() {
+ return clicker;
+ }
+
+ public Location getDestination() {
+ return des;
+ }
+
+ public void setDestination(Location location) {
+ this.des = location;
+ }
+
+ public boolean getIsCanceled() {
+ return this.isCanceled;
+ }
+
+ public void setCanceled(boolean canceled) {
+ this.isCanceled = canceled;
+ }
+
+ public HandlerList getHandlers() {
+ return handlers;
+ }
}
diff --git a/src/me/zombie_striker/lobbyapi/utils/ConfigHandler.java b/src/me/zombie_striker/lobbyapi/utils/ConfigHandler.java
index 8da4a62..ee2d7a3 100644
--- a/src/me/zombie_striker/lobbyapi/utils/ConfigHandler.java
+++ b/src/me/zombie_striker/lobbyapi/utils/ConfigHandler.java
@@ -1,18 +1,17 @@
package me.zombie_striker.lobbyapi.utils;
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.Set;
-
import me.zombie_striker.lobbyapi.LobbyWorld;
import me.zombie_striker.lobbyapi.Main;
-
import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Set;
+
public class ConfigHandler {
private static FileConfiguration config;
@@ -25,50 +24,6 @@ public static void setConfig(FileConfiguration f, File f2, Main main) {
m = main;
}
- public enum ConfigKeys {
- WorldSelector("worldselector"), CanUsePortals("canuseportals"), DisableHealthAndHunger(
- "disablehealthandhunger"), DisableVoid("disablevoid"), isHidden("hidden"), Material(
- "material"), Weather("weatherstate"), Color("color"), JoiningCommands("joincommands"), GameMode(
- "gamemode"), SavingLocation("playerworldsavinglocations"), ShouldBeSavingLocation(
- "shouldsavelocation"), DefaultItems("defaultitems"), CustomAddedWorlds_Seed(
- "Seeds"), ENABLE_PER_WORLD_INVENTORIES(
- "Enable_Per_World_Inventories"), LINKED_NETHER(
- "Linked_nether"), LINKED_END(
- "Linked_End"), WORLDENVIROMENT(
- "World_Enviroment"), PORTALLIST(
- "Portal_Loc_List");
-
- private String s;
-
- ConfigKeys(String s2) {
- this.s = s2;
- }
-
- @Override
- public String toString() {
- return s;
- }
- }/*
- *
- * public static Set getCustomWorldKeys() { if
- * (!config.contains(ConfigKeys.CustomAddedWorlds.s)) return null; return
- * config.getConfigurationSection(ConfigKeys.CustomAddedWorlds.s).getKeys(false)
- * ; }
- *
- * public static int getCustomWorldInt(String name, ConfigKeys path) { return
- * config.getInt(ConfigKeys.CustomAddedWorlds.s + "." + name + "." + path); }
- *
- * public static String getCustomWorldString(String name, ConfigKeys path) {
- * return config.getString(ConfigKeys.CustomAddedWorlds.s + "." + name + "." +
- * path); }
- *
- * public static void setCustomWorldValue(String name, ConfigKeys path, Object
- * o) { config = YamlConfiguration.loadConfiguration(file);
- * config.set(ConfigKeys.CustomAddedWorlds.s + "." + name + "." + path, o); try
- * { config.save(file); } catch (IOException e) { e.printStackTrace(); }
- * m.reloadConfig(); }
- */
-
public static void setLobbyAPIVariable(ConfigKeys key, Object value) {
config = YamlConfiguration.loadConfiguration(file);
config.set("Settings." + key, value);
@@ -166,4 +121,48 @@ public static Object getWorldVariableObject(LobbyWorld lw, ConfigKeys key) {
public static Object getWorldVariableObject(String lw, ConfigKeys key) {
return config.get("Worlds." + lw + "." + key);
}
+
+ public enum ConfigKeys {
+ WorldSelector("worldselector"), CanUsePortals("canuseportals"), DisableHealthAndHunger(
+ "disablehealthandhunger"), DisableVoid("disablevoid"), isHidden("hidden"), Material(
+ "material"), Weather("weatherstate"), Color("color"), JoiningCommands("joincommands"), GameMode(
+ "gamemode"), SavingLocation("playerworldsavinglocations"), ShouldBeSavingLocation(
+ "shouldsavelocation"), DefaultItems("defaultitems"), CustomAddedWorlds_Seed(
+ "Seeds"), ENABLE_PER_WORLD_INVENTORIES(
+ "Enable_Per_World_Inventories"), LINKED_NETHER(
+ "Linked_nether"), LINKED_END(
+ "Linked_End"), WORLDENVIROMENT(
+ "World_Enviroment"), PORTALLIST(
+ "Portal_Loc_List");
+
+ private String s;
+
+ ConfigKeys(String s2) {
+ this.s = s2;
+ }
+
+ @Override
+ public String toString() {
+ return s;
+ }
+ }/*
+ *
+ * public static Set getCustomWorldKeys() { if
+ * (!config.contains(ConfigKeys.CustomAddedWorlds.s)) return null; return
+ * config.getConfigurationSection(ConfigKeys.CustomAddedWorlds.s).getKeys(false)
+ * ; }
+ *
+ * public static int getCustomWorldInt(String name, ConfigKeys path) { return
+ * config.getInt(ConfigKeys.CustomAddedWorlds.s + "." + name + "." + path); }
+ *
+ * public static String getCustomWorldString(String name, ConfigKeys path) {
+ * return config.getString(ConfigKeys.CustomAddedWorlds.s + "." + name + "." +
+ * path); }
+ *
+ * public static void setCustomWorldValue(String name, ConfigKeys path, Object
+ * o) { config = YamlConfiguration.loadConfiguration(file);
+ * config.set(ConfigKeys.CustomAddedWorlds.s + "." + name + "." + path, o); try
+ * { config.save(file); } catch (IOException e) { e.printStackTrace(); }
+ * m.reloadConfig(); }
+ */
}
diff --git a/src/me/zombie_striker/lobbyapi/utils/GithubDependDownloader.java b/src/me/zombie_striker/lobbyapi/utils/GithubDependDownloader.java
index 0bd811a..1665ea0 100644
--- a/src/me/zombie_striker/lobbyapi/utils/GithubDependDownloader.java
+++ b/src/me/zombie_striker/lobbyapi/utils/GithubDependDownloader.java
@@ -1,45 +1,49 @@
package me.zombie_striker.lobbyapi.utils;
-import java.io.*;
-import java.net.*;
-import com.google.gson.*;
-import org.bukkit.*;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
+import java.io.*;
+import java.net.URL;
+import java.net.URLConnection;
+
public class GithubDependDownloader {
/*
* public void update(Player p){ String version = Main.version; String
* parsedVersion = version.replace(".", "");
- *
+ *
* try { URL api = new
* URL("https://api.github.com/repos/greeves12/COD/releases/latest");
* URLConnection con = api.openConnection(); con.setConnectTimeout(15000);
* con.setReadTimeout(15000);
- *
+ *
* String tagName = null;
- *
+ *
* try{ JsonObject json = new JsonParser().parse(new
* InputStreamReader(con.getInputStream())).getAsJsonObject(); tagName =
* json.get("tag_name").getAsString();
- *
+ *
* String finalTagName = tagName.replace(".", ""); int latestVersion =
* Integer.parseInt(finalTagName.substring(1, finalTagName.length()));
- *
+ *
* if(latestVersion > Integer.parseInt(parsedVersion)) {
- *
- * p.sendMessage("§8*** [COD] §bThere is a new version available §a" + tagName +
- * "§8***"); p.sendMessage("§8*** §dDownload the new build from here §8***");
- * p.sendMessage("§8*** §6§6https://github.com/greeves12/COD/releases §8***");
- * p.sendMessage("§bOnly Admins can see this message!"); }
- *
+ *
+ * p.sendMessage("�8*** [COD] �bThere is a new version available �a" + tagName +
+ * "�8***"); p.sendMessage("�8*** �dDownload the new build from here �8***");
+ * p.sendMessage("�8*** �6�6https://github.com/greeves12/COD/releases �8***");
+ * p.sendMessage("�bOnly Admins can see this message!"); }
+ *
* }catch(JsonIOException e){ e.printStackTrace(); } } catch (IOException e) {
* e.printStackTrace(); } }
*/
public static boolean autoUpdate(final Plugin main, final File output, String author, String githubProject,
- String jarname) {
+ String jarname) {
try {
String tagname = null;
diff --git a/src/me/zombie_striker/lobbyapi/utils/GithubUpdater.java b/src/me/zombie_striker/lobbyapi/utils/GithubUpdater.java
index 65cdb8e..a039fd5 100644
--- a/src/me/zombie_striker/lobbyapi/utils/GithubUpdater.java
+++ b/src/me/zombie_striker/lobbyapi/utils/GithubUpdater.java
@@ -1,43 +1,19 @@
package me.zombie_striker.lobbyapi.utils;
-import java.io.*;
-import java.net.*;
-
-import com.google.gson.*;
-import org.bukkit.*;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
-public class GithubUpdater {
+import java.io.*;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
- /*
- * public void update(Player p){ String version = Main.version; String
- * parsedVersion = version.replace(".", "");
- *
- * try { URL api = new
- * URL("https://api.github.com/repos/greeves12/COD/releases/latest");
- * URLConnection con = api.openConnection(); con.setConnectTimeout(15000);
- * con.setReadTimeout(15000);
- *
- * String tagName = null;
- *
- * try{ JsonObject json = new JsonParser().parse(new
- * InputStreamReader(con.getInputStream())).getAsJsonObject(); tagName =
- * json.get("tag_name").getAsString();
- *
- * String finalTagName = tagName.replace(".", ""); int latestVersion =
- * Integer.parseInt(finalTagName.substring(1, finalTagName.length()));
- *
- * if(latestVersion > Integer.parseInt(parsedVersion)) {
- *
- * p.sendMessage("§8*** [COD] §bThere is a new version available §a" + tagName +
- * "§8***"); p.sendMessage("§8*** §dDownload the new build from here §8***");
- * p.sendMessage("§8*** §6§6https://github.com/greeves12/COD/releases §8***");
- * p.sendMessage("§bOnly Admins can see this message!"); }
- *
- * }catch(JsonIOException e){ e.printStackTrace(); } } catch (IOException e) {
- * e.printStackTrace(); } }
- */
+public class GithubUpdater {
public static boolean autoUpdate(final Plugin main, String author, String githubProject, String jarname) {
try {
@@ -50,19 +26,27 @@ public static boolean autoUpdate(final Plugin main, String author, String github
con.setConnectTimeout(15000);
con.setReadTimeout(15000);
- JsonObject json = new JsonParser().parse(new InputStreamReader(con.getInputStream())).getAsJsonObject();
+ JsonObject json = null;
+ try {
+ json = new JsonParser().parse(new InputStreamReader(con.getInputStream())).getAsJsonObject();
+ } catch (Error | Exception e45) {
+ return false;
+ }
tagname = json.get("tag_name").getAsString();
String parsedTagName = tagname.replace(".", "");
- int latestVersion = Integer.valueOf(parsedTagName.substring(1, parsedTagName.length()));
+ int latestVersion = Integer.valueOf(parsedTagName.substring(1).replaceAll("[^\\d.]", ""));
+ int parsedVersion = Integer.parseInt(parseVersion.replaceAll("[^\\d.]", ""));
final URL download = new URL("https://github.com/" + author + "/" + githubProject + "/releases/download/"
+ tagname + "/" + jarname);
- if (latestVersion > Integer.parseInt(parseVersion)) {
- Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Found a new version of "+ChatColor.GOLD+main.getDescription().getName()+": " + ChatColor.WHITE
- + tagname + ChatColor.LIGHT_PURPLE + " downloading now!!");
+ if (latestVersion > parsedVersion) {
+ Bukkit.getConsoleSender()
+ .sendMessage(ChatColor.GREEN + "Found a new version of " + ChatColor.GOLD
+ + main.getDescription().getName() + ": " + ChatColor.WHITE + tagname
+ + ChatColor.LIGHT_PURPLE + " downloading now!!");
new BukkitRunnable() {
@@ -71,65 +55,65 @@ public void run() {
try {
InputStream in = download.openStream();
-
File pluginFile = null;
- try {
- pluginFile = new File(URLDecoder.decode(
- this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(),
- "UTF-8"));
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException("You don't have a good text codec on your system", e);
- }
+ pluginFile = new File(URLDecoder.decode(
+ this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(),
+ StandardCharsets.UTF_8.name()));
// File temp = new File("plugins/update");
// if (!temp.exists()) {
// temp.mkdir();
// }
-
- File tempInCaseSomethingGoesWrong = new File(main.getName()+"-backup.jar");
- copy(new FileInputStream(pluginFile),new FileOutputStream(tempInCaseSomethingGoesWrong));
+
+ File tempInCaseSomethingGoesWrong = new File(main.getName() + "-backup.jar");
+ copy(new FileInputStream(pluginFile), new FileOutputStream(tempInCaseSomethingGoesWrong));
// Path path = new File("plugins/update" + File.separator + "COD.jar").toPath();
pluginFile.setWritable(true, false);
pluginFile.delete();
- //Files.copy(in, pluginFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
+ // Files.copy(in, pluginFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
copy(in, new FileOutputStream(pluginFile));
-
- if(pluginFile.length()<1000) {
- //Plugin is too small. Keep old version in case new one is incomplete/nonexistant
- copy(new FileInputStream(tempInCaseSomethingGoesWrong),new FileOutputStream(pluginFile));
- }else {
- //Plugin is valid, and we can delete the temp
+
+ if (pluginFile.length() < 1000) {
+ // Plugin is too small. Keep old version in case new one is
+ // incomplete/nonexistant
+ copy(new FileInputStream(tempInCaseSomethingGoesWrong),
+ new FileOutputStream(pluginFile));
+ } else {
+ // Plugin is valid, and we can delete the temp
tempInCaseSomethingGoesWrong.delete();
}
} catch (IOException e) {
+ e.printStackTrace();
}
}
}.runTaskLaterAsynchronously(main, 0);
return true;
}
} catch (IOException e) {
+ e.printStackTrace();
}
return false;
}
- private static long copy(InputStream in, OutputStream out) throws IOException {
- long bytes = 0;
- byte[] buf = new byte[0x1000];
- while (true) {
- int r = in.read(buf);
- if (r == -1)
- break;
- out.write(buf, 0, r);
- bytes += r;
- // debug("Another 4K, current: " + r);
- }
- out.flush();
- out.close();
- in.close();
- return bytes;
- }
+
+ private static long copy(InputStream in, OutputStream out) throws IOException {
+ long bytes = 0;
+ byte[] buf = new byte[0x1000];
+ while (true) {
+ int r = in.read(buf);
+ if (r == -1)
+ break;
+ out.write(buf, 0, r);
+ bytes += r;
+ // debug("Another 4K, current: " + r);
+ }
+ out.flush();
+ out.close();
+ in.close();
+ return bytes;
+ }
}
diff --git a/src/me/zombie_striker/lobbyapi/utils/Metrics.java b/src/me/zombie_striker/lobbyapi/utils/Metrics.java
index d0ab955..f131c83 100644
--- a/src/me/zombie_striker/lobbyapi/utils/Metrics.java
+++ b/src/me/zombie_striker/lobbyapi/utils/Metrics.java
@@ -1,678 +1,718 @@
package me.zombie_striker.lobbyapi.utils;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
+import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicePriority;
-import org.bukkit.plugin.java.JavaPlugin;
-import org.json.simple.JSONArray;
-import org.json.simple.JSONObject;
import javax.net.ssl.HttpsURLConnection;
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.IOException;
+import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.UUID;
+import java.nio.charset.StandardCharsets;
+import java.util.*;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
/**
* bStats collects some data for plugin authors.
- *
+ *
* Check out https://bStats.org/ to learn more about bStats!
*/
+@SuppressWarnings({"WeakerAccess", "unused"})
public class Metrics {
- static {
- // You can use the property to disable the check in your test environment
- if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
- // Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
- final String defaultPackage = new String(
- new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
- final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
- // We want to make sure nobody just copy & pastes the example and use the wrong package names
- if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
- throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
- }
- }
- }
-
- // The version of this bStats class
- public static final int B_STATS_VERSION = 1;
-
- // The url to which the data is sent
- private static final String URL = "https://bStats.org/submitData/bukkit";
-
- // Should failed requests be logged?
- private static boolean logFailedRequests;
-
- // The uuid of the server
- private static String serverUUID;
-
- // The plugin
- private final JavaPlugin plugin;
-
- // A list with all custom charts
- private final List charts = new ArrayList<>();
-
- /**
- * Class constructor.
- *
- * @param plugin The plugin which stats should be submitted.
- */
- public Metrics(JavaPlugin plugin) {
- if (plugin == null) {
- throw new IllegalArgumentException("Plugin cannot be null!");
- }
- this.plugin = plugin;
-
- // Get the config file
- File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
- File configFile = new File(bStatsFolder, "config.yml");
- YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
-
- // Check if the config file exists
- if (!config.isSet("serverUuid")) {
-
- // Add default values
- config.addDefault("enabled", true);
- // Every server gets it's unique random id.
- config.addDefault("serverUuid", UUID.randomUUID().toString());
- // Should failed request be logged?
- config.addDefault("logFailedRequests", false);
-
- // Inform the server owners about bStats
- config.options().header(
- "bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
- "To honor their work, you should not disable it.\n" +
- "This has nearly no effect on the server performance!\n" +
- "Check out https://bStats.org/ to learn more :)"
- ).copyDefaults(true);
- try {
- config.save(configFile);
- } catch (IOException ignored) { }
- }
-
- // Load the data
- serverUUID = config.getString("serverUuid");
- logFailedRequests = config.getBoolean("logFailedRequests", false);
- if (config.getBoolean("enabled", true)) {
- boolean found = false;
- // Search for all other bStats Metrics classes to see if we are the first one
- for (Class> service : Bukkit.getServicesManager().getKnownServices()) {
- try {
- service.getField("B_STATS_VERSION"); // Our identifier :)
- found = true; // We aren't the first
- break;
- } catch (NoSuchFieldException ignored) { }
- }
- // Register our service
- Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
- if (!found) {
- // We are the first!
- startSubmitting();
- }
- }
- }
-
- /**
- * Adds a custom chart.
- *
- * @param chart The chart to add.
- */
- public void addCustomChart(CustomChart chart) {
- if (chart == null) {
- throw new IllegalArgumentException("Chart cannot be null!");
- }
- charts.add(chart);
- }
-
- /**
- * Starts the Scheduler which submits our data every 30 minutes.
- */
- private void startSubmitting() {
- final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
- timer.scheduleAtFixedRate(new TimerTask() {
- @Override
- public void run() {
- if (!plugin.isEnabled()) { // Plugin was disabled
- timer.cancel();
- return;
- }
- // Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
- // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
- Bukkit.getScheduler().runTask(plugin, new Runnable() {
- @Override
- public void run() {
- submitData();
- }
- });
- }
- }, 1000*60*5, 1000*60*30);
- // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
- // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
- // WARNING: Just don't do it!
- }
-
- /**
- * Gets the plugin specific data.
- * This method is called using Reflection.
- *
- * @return The plugin specific data.
- */
- @SuppressWarnings("unchecked")
- public JSONObject getPluginData() {
- JSONObject data = new JSONObject();
-
- String pluginName = plugin.getDescription().getName();
- String pluginVersion = plugin.getDescription().getVersion();
-
- data.put("pluginName", pluginName); // Append the name of the plugin
- data.put("pluginVersion", pluginVersion); // Append the version of the plugin
- JSONArray customCharts = new JSONArray();
- for (CustomChart customChart : charts) {
- // Add the data of the custom charts
- JSONObject chart = customChart.getRequestJsonObject();
- if (chart == null) { // If the chart is null, we skip it
- continue;
- }
- customCharts.add(chart);
- }
- data.put("customCharts", customCharts);
-
- return data;
- }
-
- /**
- * Gets the server specific data.
- *
- * @return The server specific data.
- */
- @SuppressWarnings("unchecked")
- private JSONObject getServerData() {
- // Minecraft specific data
- int playerAmount;
- try {
- // Around MC 1.8 the return type was changed to a collection from an array,
- // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
- Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
- playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
- ? ((Collection>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
- : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
- } catch (Exception e) {
- playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
- }
- int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
- String bukkitVersion = org.bukkit.Bukkit.getVersion();
- bukkitVersion = bukkitVersion.substring(bukkitVersion.indexOf("MC: ") + 4, bukkitVersion.length() - 1);
-
- // OS/Java specific data
- String javaVersion = System.getProperty("java.version");
- String osName = System.getProperty("os.name");
- String osArch = System.getProperty("os.arch");
- String osVersion = System.getProperty("os.version");
- int coreCount = Runtime.getRuntime().availableProcessors();
-
- JSONObject data = new JSONObject();
-
- data.put("serverUUID", serverUUID);
-
- data.put("playerAmount", playerAmount);
- data.put("onlineMode", onlineMode);
- data.put("bukkitVersion", bukkitVersion);
-
- data.put("javaVersion", javaVersion);
- data.put("osName", osName);
- data.put("osArch", osArch);
- data.put("osVersion", osVersion);
- data.put("coreCount", coreCount);
-
- return data;
- }
-
- /**
- * Collects the data and sends it afterwards.
- */
- @SuppressWarnings("unchecked")
+ static {
+ // You can use the property to disable the check in your test environment
+ if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
+ // Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
+ final String defaultPackage = new String(
+ new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
+ final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
+ // We want to make sure nobody just copy & pastes the example and use the wrong package names
+ if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
+ throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
+ }
+ }
+ }
+
+ // The version of this bStats class
+ public static final int B_STATS_VERSION = 1;
+
+ // The url to which the data is sent
+ private static final String URL = "https://bStats.org/submitData/bukkit";
+
+ // Is bStats enabled on this server?
+ private boolean enabled;
+
+ // Should failed requests be logged?
+ private static boolean logFailedRequests;
+
+ // Should the sent data be logged?
+ private static boolean logSentData;
+
+ // Should the response text be logged?
+ private static boolean logResponseStatusText;
+
+ // The uuid of the server
+ private static String serverUUID;
+
+ // The plugin
+ private final Plugin plugin;
+
+ // A list with all custom charts
+ private final List charts = new ArrayList<>();
+
+ /**
+ * Class constructor.
+ *
+ * @param plugin The plugin which stats should be submitted.
+ */
+ public Metrics(Plugin plugin) {
+ if (plugin == null) {
+ throw new IllegalArgumentException("Plugin cannot be null!");
+ }
+ this.plugin = plugin;
+
+ // Get the config file
+ File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
+ File configFile = new File(bStatsFolder, "config.yml");
+ YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
+
+ // Check if the config file exists
+ if (!config.isSet("serverUuid")) {
+
+ // Add default values
+ config.addDefault("enabled", true);
+ // Every server gets it's unique random id.
+ config.addDefault("serverUuid", UUID.randomUUID().toString());
+ // Should failed request be logged?
+ config.addDefault("logFailedRequests", false);
+ // Should the sent data be logged?
+ config.addDefault("logSentData", false);
+ // Should the response text be logged?
+ config.addDefault("logResponseStatusText", false);
+
+ // Inform the server owners about bStats
+ config.options().header(
+ "bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
+ "To honor their work, you should not disable it.\n" +
+ "This has nearly no effect on the server performance!\n" +
+ "Check out https://bStats.org/ to learn more :)"
+ ).copyDefaults(true);
+ try {
+ config.save(configFile);
+ } catch (IOException ignored) { }
+ }
+
+ // Load the data
+ enabled = config.getBoolean("enabled", true);
+ serverUUID = config.getString("serverUuid");
+ logFailedRequests = config.getBoolean("logFailedRequests", false);
+ logSentData = config.getBoolean("logSentData", false);
+ logResponseStatusText = config.getBoolean("logResponseStatusText", false);
+
+ if (enabled) {
+ boolean found = false;
+ // Search for all other bStats Metrics classes to see if we are the first one
+ for (Class> service : Bukkit.getServicesManager().getKnownServices()) {
+ try {
+ service.getField("B_STATS_VERSION"); // Our identifier :)
+ found = true; // We aren't the first
+ break;
+ } catch (NoSuchFieldException ignored) { }
+ }
+ // Register our service
+ Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
+ if (!found) {
+ // We are the first!
+ startSubmitting();
+ }
+ }
+ }
+
+ /**
+ * Checks if bStats is enabled.
+ *
+ * @return Whether bStats is enabled or not.
+ */
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ /**
+ * Adds a custom chart.
+ *
+ * @param chart The chart to add.
+ */
+ public void addCustomChart(CustomChart chart) {
+ if (chart == null) {
+ throw new IllegalArgumentException("Chart cannot be null!");
+ }
+ charts.add(chart);
+ }
+
+ /**
+ * Starts the Scheduler which submits our data every 30 minutes.
+ */
+ private void startSubmitting() {
+ final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
+ timer.scheduleAtFixedRate(new TimerTask() {
+ @Override
+ public void run() {
+ if (!plugin.isEnabled()) { // Plugin was disabled
+ timer.cancel();
+ return;
+ }
+ // Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
+ // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
+ Bukkit.getScheduler().runTask(plugin, () -> submitData());
+ }
+ }, 1000 * 60 * 5, 1000 * 60 * 30);
+ // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
+ // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
+ // WARNING: Just don't do it!
+ }
+
+ /**
+ * Gets the plugin specific data.
+ * This method is called using Reflection.
+ *
+ * @return The plugin specific data.
+ */
+ public JsonObject getPluginData() {
+ JsonObject data = new JsonObject();
+
+ String pluginName = plugin.getDescription().getName();
+ String pluginVersion = plugin.getDescription().getVersion();
+
+ data.addProperty("pluginName", pluginName); // Append the name of the plugin
+ data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin
+ JsonArray customCharts = new JsonArray();
+ for (CustomChart customChart : charts) {
+ // Add the data of the custom charts
+ JsonObject chart = customChart.getRequestJsonObject();
+ if (chart == null) { // If the chart is null, we skip it
+ continue;
+ }
+ customCharts.add(chart);
+ }
+ data.add("customCharts", customCharts);
+
+ return data;
+ }
+
+ /**
+ * Gets the server specific data.
+ *
+ * @return The server specific data.
+ */
+ private JsonObject getServerData() {
+ // Minecraft specific data
+ int playerAmount;
+ try {
+ // Around MC 1.8 the return type was changed to a collection from an array,
+ // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
+ Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
+ playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
+ ? ((Collection>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
+ : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
+ } catch (Exception e) {
+ playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
+ }
+ int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
+ String bukkitVersion = Bukkit.getVersion();
+ String bukkitName = Bukkit.getName();
+
+ // OS/Java specific data
+ String javaVersion = System.getProperty("java.version");
+ String osName = System.getProperty("os.name");
+ String osArch = System.getProperty("os.arch");
+ String osVersion = System.getProperty("os.version");
+ int coreCount = Runtime.getRuntime().availableProcessors();
+
+ JsonObject data = new JsonObject();
+
+ data.addProperty("serverUUID", serverUUID);
+
+ data.addProperty("playerAmount", playerAmount);
+ data.addProperty("onlineMode", onlineMode);
+ data.addProperty("bukkitVersion", bukkitVersion);
+ data.addProperty("bukkitName", bukkitName);
+
+ data.addProperty("javaVersion", javaVersion);
+ data.addProperty("osName", osName);
+ data.addProperty("osArch", osArch);
+ data.addProperty("osVersion", osVersion);
+ data.addProperty("coreCount", coreCount);
+
+ return data;
+ }
+
+ /**
+ * Collects the data and sends it afterwards.
+ */
private void submitData() {
- final JSONObject data = getServerData();
-
- JSONArray pluginData = new JSONArray();
- // Search for all other bStats Metrics classes to get their plugin data
- for (Class> service : Bukkit.getServicesManager().getKnownServices()) {
- try {
- service.getField("B_STATS_VERSION"); // Our identifier :)
-
- for (RegisteredServiceProvider> provider : Bukkit.getServicesManager().getRegistrations(service)) {
- try {
- pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider()));
- } catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
- }
- } catch (NoSuchFieldException ignored) { }
- }
-
- data.put("plugins", pluginData);
-
- // Create a new thread for the connection to the bStats server
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- // Send the data
- sendData(data);
- } catch (Exception e) {
- // Something went wrong! :(
- if (logFailedRequests) {
- plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
- }
- }
- }
- }).start();
- }
-
- /**
- * Sends the data to the bStats server.
- *
- * @param data The data to send.
- * @throws Exception If the request failed.
- */
- private static void sendData(JSONObject data) throws Exception {
- if (data == null) {
- throw new IllegalArgumentException("Data cannot be null!");
- }
- if (Bukkit.isPrimaryThread()) {
- throw new IllegalAccessException("This method must not be called from the main thread!");
- }
- HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
-
- // Compress the data to save bandwidth
- byte[] compressedData = compress(data.toString());
-
- // Add headers
- connection.setRequestMethod("POST");
- connection.addRequestProperty("Accept", "application/json");
- connection.addRequestProperty("Connection", "close");
- connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
- connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
- connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
- connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
-
- // Send data
- connection.setDoOutput(true);
- DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
- outputStream.write(compressedData);
- outputStream.flush();
- outputStream.close();
-
- connection.getInputStream().close(); // We don't care about the response - Just send our data :)
- }
-
- /**
- * Gzips the given String.
- *
- * @param str The string to gzip.
- * @return The gzipped String.
- * @throws IOException If the compression failed.
- */
- private static byte[] compress(final String str) throws IOException {
- if (str == null) {
- return null;
- }
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
- gzip.write(str.getBytes("UTF-8"));
- gzip.close();
- return outputStream.toByteArray();
- }
-
- /**
- * Represents a custom chart.
- */
- public static abstract class CustomChart {
-
- // The id of the chart
- final String chartId;
-
- /**
- * Class constructor.
- *
- * @param chartId The id of the chart.
- */
- CustomChart(String chartId) {
- if (chartId == null || chartId.isEmpty()) {
- throw new IllegalArgumentException("ChartId cannot be null or empty!");
- }
- this.chartId = chartId;
- }
-
- @SuppressWarnings("unchecked")
- private JSONObject getRequestJsonObject() {
- JSONObject chart = new JSONObject();
- chart.put("chartId", chartId);
- try {
- JSONObject data = getChartData();
- if (data == null) {
- // If the data is null we don't send the chart.
- return null;
- }
- chart.put("data", data);
- } catch (Throwable t) {
- if (logFailedRequests) {
- Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
- }
- return null;
- }
- return chart;
- }
-
- protected abstract JSONObject getChartData() throws Exception;
-
- }
-
- /**
- * Represents a custom simple pie.
- */
- public static class SimplePie extends CustomChart {
-
- private final Callable callable;
-
- /**
- * Class constructor.
- *
- * @param chartId The id of the chart.
- * @param callable The callable which is used to request the chart data.
- */
- public SimplePie(String chartId, Callable callable) {
- super(chartId);
- this.callable = callable;
- }
-
- @SuppressWarnings("unchecked")
+ final JsonObject data = getServerData();
+
+ JsonArray pluginData = new JsonArray();
+ // Search for all other bStats Metrics classes to get their plugin data
+ for (Class> service : Bukkit.getServicesManager().getKnownServices()) {
+ try {
+ service.getField("B_STATS_VERSION"); // Our identifier :)
+
+ for (RegisteredServiceProvider> provider : Bukkit.getServicesManager().getRegistrations(service)) {
+ try {
+ Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider());
+ if (plugin instanceof JsonObject) {
+ pluginData.add((JsonObject) plugin);
+ } else { // old bstats version compatibility
+ try {
+ Class> jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject");
+ if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) {
+ Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString");
+ jsonStringGetter.setAccessible(true);
+ String jsonString = (String) jsonStringGetter.invoke(plugin);
+ JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject();
+ pluginData.add(object);
+ }
+ } catch (ClassNotFoundException e) {
+ // minecraft version 1.14+
+ if (logFailedRequests) {
+ this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception", e);
+ }
+ continue; // continue looping since we cannot do any other thing.
+ }
+ }
+ } catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
+ }
+ } catch (NoSuchFieldException ignored) { }
+ }
+
+ data.add("plugins", pluginData);
+
+ // Create a new thread for the connection to the bStats server
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ // Send the data
+ sendData(plugin, data);
+ } catch (Exception e) {
+ // Something went wrong! :(
+ if (logFailedRequests) {
+ plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
+ }
+ }
+ }
+ }).start();
+ }
+
+ /**
+ * Sends the data to the bStats server.
+ *
+ * @param plugin Any plugin. It's just used to get a logger instance.
+ * @param data The data to send.
+ * @throws Exception If the request failed.
+ */
+ private static void sendData(Plugin plugin, JsonObject data) throws Exception {
+ if (data == null) {
+ throw new IllegalArgumentException("Data cannot be null!");
+ }
+ if (Bukkit.isPrimaryThread()) {
+ throw new IllegalAccessException("This method must not be called from the main thread!");
+ }
+ if (logSentData) {
+ plugin.getLogger().info("Sending data to bStats: " + data.toString());
+ }
+ HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
+
+ // Compress the data to save bandwidth
+ byte[] compressedData = compress(data.toString());
+
+ // Add headers
+ connection.setRequestMethod("POST");
+ connection.addRequestProperty("Accept", "application/json");
+ connection.addRequestProperty("Connection", "close");
+ connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
+ connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
+ connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
+ connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
+
+ // Send data
+ connection.setDoOutput(true);
+ DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
+ outputStream.write(compressedData);
+ outputStream.flush();
+ outputStream.close();
+
+ InputStream inputStream = connection.getInputStream();
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
+
+ StringBuilder builder = new StringBuilder();
+ String line;
+ while ((line = bufferedReader.readLine()) != null) {
+ builder.append(line);
+ }
+ bufferedReader.close();
+ if (logResponseStatusText) {
+ plugin.getLogger().info("Sent data to bStats and received response: " + builder.toString());
+ }
+ }
+
+ /**
+ * Gzips the given String.
+ *
+ * @param str The string to gzip.
+ * @return The gzipped String.
+ * @throws IOException If the compression failed.
+ */
+ private static byte[] compress(final String str) throws IOException {
+ if (str == null) {
+ return null;
+ }
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
+ gzip.write(str.getBytes(StandardCharsets.UTF_8));
+ gzip.close();
+ return outputStream.toByteArray();
+ }
+
+ /**
+ * Represents a custom chart.
+ */
+ public static abstract class CustomChart {
+
+ // The id of the chart
+ final String chartId;
+
+ /**
+ * Class constructor.
+ *
+ * @param chartId The id of the chart.
+ */
+ CustomChart(String chartId) {
+ if (chartId == null || chartId.isEmpty()) {
+ throw new IllegalArgumentException("ChartId cannot be null or empty!");
+ }
+ this.chartId = chartId;
+ }
+
+ private JsonObject getRequestJsonObject() {
+ JsonObject chart = new JsonObject();
+ chart.addProperty("chartId", chartId);
+ try {
+ JsonObject data = getChartData();
+ if (data == null) {
+ // If the data is null we don't send the chart.
+ return null;
+ }
+ chart.add("data", data);
+ } catch (Throwable t) {
+ if (logFailedRequests) {
+ Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
+ }
+ return null;
+ }
+ return chart;
+ }
+
+ protected abstract JsonObject getChartData() throws Exception;
+
+ }
+
+ /**
+ * Represents a custom simple pie.
+ */
+ public static class SimplePie extends CustomChart {
+
+ private final Callable callable;
+
+ /**
+ * Class constructor.
+ *
+ * @param chartId The id of the chart.
+ * @param callable The callable which is used to request the chart data.
+ */
+ public SimplePie(String chartId, Callable callable) {
+ super(chartId);
+ this.callable = callable;
+ }
+
@Override
- protected JSONObject getChartData() throws Exception {
- JSONObject data = new JSONObject();
- String value = callable.call();
- if (value == null || value.isEmpty()) {
- // Null = skip the chart
- return null;
- }
- data.put("value", value);
- return data;
- }
- }
-
- /**
- * Represents a custom advanced pie.
- */
- public static class AdvancedPie extends CustomChart {
-
- private final Callable