diff --git a/.project b/.project
index 2607fa2..3ffecda 100644
--- a/.project
+++ b/.project
@@ -10,14 +10,8 @@
-
- org.eclipse.m2e.core.maven2Builder
-
-
-
- org.eclipse.m2e.core.maven2Nature
org.eclipse.jdt.core.javanature
diff --git a/config.yml b/config.yml
index e69de29..766efca 100644
--- a/config.yml
+++ b/config.yml
@@ -0,0 +1,26 @@
+# two spaces __ per indent
+
+
+teleport-commands: #not coded yet
+settings:
+ world:
+ #=======================================================================#
+ # Possible values: #
+ # #
+ # [WORLD]: #
+ # share: #
+ # inventory: #
+ # group: [GROUP NAME] or '' to share with all worlds #
+ # type: [0, 1, or 2] #
+ # #
+ # 0 - default #
+ # 1 - IN, share only for incoming traffic #
+ # 2 - OUT, share only for outgoing traffic #
+ # #
+ # playerdata: #
+ # group: #
+ # type: #
+ #=======================================================================#
+ player:
+worlds:
+players:
\ No newline at end of file
diff --git a/plugin.yml b/plugin.yml
index 2ed8063..232b31e 100644
--- a/plugin.yml
+++ b/plugin.yml
@@ -1,4 +1,4 @@
- main: buttondevteam.perworld.main.MainPlugin
+ main: tbmc.perworld.main.MainPlugin
version: 1.0.0
name: PerWorldInventories
softdepend:
diff --git a/pom.xml b/pom.xml
deleted file mode 100644
index 563b493..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,65 +0,0 @@
-
- 4.0.0
- com.github.TBMCPlugins
- PerWorldInventory
- master-SNAPSHOT
-
- src
-
-
- src
-
- **/*.java
-
-
-
- .
-
- *.properties
- *.yml
- *.csv
- *.txt
-
- true
-
-
-
-
- maven-compiler-plugin
- 3.5.1
-
-
-
-
-
-
-
-
-
- spigot-repo
- https://hub.spigotmc.org/nexus/content/repositories/snapshots/
-
-
- jitpack.io
- https://jitpack.io/
-
-
-
-
- org.spigotmc
- spigot-api
- 1.10-R0.1-SNAPSHOT
-
-
- com.github.TBMCPlugins.ButtonCore
- ButtonCore
- master-SNAPSHOT
-
-
- org.bukkit
- craftbukkit
- 1.10-R0.1-SNAPSHOT
-
-
-
\ No newline at end of file
diff --git a/src/Guide to this plugin b/src/Guide to this plugin
new file mode 100644
index 0000000..e11982c
--- /dev/null
+++ b/src/Guide to this plugin
@@ -0,0 +1 @@
+not written yet, this will be a breakdown of how the plugin works
\ No newline at end of file
diff --git a/src/buttondevteam/perworld/cache/CacheInterface.java b/src/buttondevteam/perworld/cache/CacheInterface.java
deleted file mode 100644
index d7a390b..0000000
--- a/src/buttondevteam/perworld/cache/CacheInterface.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package buttondevteam.perworld.cache;
-
-import org.bukkit.configuration.ConfigurationSection;
-
-public interface CacheInterface {
-
- public static ConfigurationSection worlds = buttondevteam.perworld.main.MainPlugin.worlds;
- public static ConfigurationSection players = buttondevteam.perworld.main.MainPlugin.players;
-
- Object generateElement(String string);
-
- void putCache(String string);
-
- void initCache();
-
-}
diff --git a/src/buttondevteam/perworld/cache/player/Name.java b/src/buttondevteam/perworld/cache/player/Name.java
deleted file mode 100644
index 7400736..0000000
--- a/src/buttondevteam/perworld/cache/player/Name.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package buttondevteam.perworld.cache.player;
-
-public class Name {
-
-
-}
diff --git a/src/buttondevteam/perworld/main/WorldChangeListener.java b/src/buttondevteam/perworld/main/WorldChangeListener.java
deleted file mode 100644
index dfcc062..0000000
--- a/src/buttondevteam/perworld/main/WorldChangeListener.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package buttondevteam.perworld.main;
-
-import org.bukkit.configuration.file.FileConfiguration;
-import org.bukkit.entity.Player;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.EventPriority;
-import org.bukkit.event.Listener;
-import org.bukkit.event.player.PlayerChangedWorldEvent;
-
-public class WorldChangeListener implements Listener {
-
- private static MainPlugin plugin;
- private static FileConfiguration config;
- public WorldChangeListener(MainPlugin plugin){
- WorldChangeListener.plugin = plugin;
- WorldChangeListener.config = plugin.getConfig();
- }
-
-
- @EventHandler(priority = EventPriority.MONITOR)
- public void onWorldChangeListener(PlayerChangedWorldEvent event){
- Player player = event.getPlayer();
- String worldTo = player.getWorld().getName();
- String worldFrom = event.getFrom().getName();
-
- initWorldSettings(worldTo);
- initWorldSettings(worldFrom);
- WorldChangeManager.update(player,worldTo, worldFrom);
- }
-
-
- public static void initWorldSettings(String world){
- if (config.get(world + ".settings.shareinvgroup") == null)
- config.set(world + ".settings.shareinvgroup", world);
- if (config.get(world + ".settings.sharedatagroup") == null)
- config.set(world + ".settings.sharedatagroup", world);
- plugin.saveConfig();
- }
-}
diff --git a/src/buttondevteam/perworld/main/WorldChangeManager.java b/src/buttondevteam/perworld/main/WorldChangeManager.java
deleted file mode 100644
index 75ea4c4..0000000
--- a/src/buttondevteam/perworld/main/WorldChangeManager.java
+++ /dev/null
@@ -1,142 +0,0 @@
-package buttondevteam.perworld.main;
-
-import java.util.Arrays;
-
-import org.bukkit.configuration.file.FileConfiguration;
-import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
-import org.bukkit.entity.Player;
-
-import net.minecraft.server.v1_10_R1.IInventory;
-
-public class WorldChangeManager {
-
- private static MainPlugin plugin;
- private static FileConfiguration config;
- public static void init(MainPlugin plugin){ //onEnable()
- WorldChangeManager.plugin = plugin;
- WorldChangeManager.config = plugin.getConfig();
- }
-
-
- //EVALUATE SHARE SETTINGS
- public static boolean[] compare (String worldTo, String worldFrom) {
- boolean[] result = new boolean[] {false,false};
- String[][] params =
- (String[][]) Arrays.asList
- (new String[] {
- (String) config.get(worldTo + ".settings.shareinvgroup"),
- (String) config.get(worldFrom + ".settings.shareinvgroup"),
- (String) config.get(worldTo + ".settings.sharedatagroup"),
- (String) config.get(worldFrom + ".settings.sharedatagroup")
- })
- .stream()
- .map(s -> (String[]) s
- .trim()
- .replaceAll("( )", "")
- .toLowerCase()
- .split("\\*"))
- .toArray(String[][]::new);
-
- /* Each world has two sharing settings: for inventory sharing,
- * and for playerdata sharing. Each setting has two parameters:
- * the sharegroup flag, which labels a group of sharing worlds,
- * and an optional suffix, *in or *out, specifying that the world
- * shares with its group in only one traffic direction
- */
-
- if (
- params[0][0].equals(params[1][0])//inv
- && params[0].length > 1 ? params[0][1].equals("in") : true
- && params[1].length > 1 ? params[1][1].equals("out") : true
- )
- result[0] = true;
-
- if (
- params[2][0].equals(params[3][0])//data
- && params[2].length > 1 ? params[2][1].equals("in") : true
- && params[3].length > 1 ? params[3][1].equals("out") : true
- )
- result[1] = true;
-
- return result;
- }
-
-
- //VALUES USED BY THE UPDATE METHODS
- public static class Values {
- public String uuid;
- public String worldTo;
- public String worldFrom;
- public String pTo;
- public String pFrom;
- public boolean shareinv;
- public boolean sharedata;
-
- public Values (Player player, String worldTo, String worldFrom){
-
- this.uuid = player.getUniqueId().toString();
- this.worldTo = worldTo;
- this.worldFrom = worldFrom;
- this.pTo = worldTo + ".players." + uuid;
- this.pFrom = worldFrom + ".players." + uuid;
-
- boolean[] compare = compare(worldTo,worldFrom);
-
- this.shareinv = compare[0];
- this.sharedata = compare[1];
- }
- }
-
-
- //MAIN UPDATE METHOD
- public static void update(Player player, String worldTo, String worldFrom){
-
- final Values values = new Values(player, worldTo, worldFrom);
-
- updateLocation(values, player);
- updateInventories(values, player);
- //updatePlayerData(values, player);
- }
-
-
- //UPDATE LOCATION
- public static void updateLocation(Values values, Player player){
- config.set(
- values.pFrom + ".location",
- buttondevteam.perworld.serializers.location.serialize(player.getLocation())
- );
- plugin.saveConfig();
- /* players are not automatically moved to their stored location,
- * this is done only on request, in a dedicated teleport method
- */
- }
-
-
- //UPDATE INVENTORIES
- public static void updateInventories(Values values, Player player){
- IInventory inventory = ((CraftInventory) player.getInventory()).getInventory();
- config.set(values.pFrom + ".inventory", buttondevteam.perworld.serializers.inventory.serialize(inventory));
- plugin.saveConfig();
- if (!values.shareinv)
- buttondevteam.perworld.serializers.inventory.setFromSerialized(
- inventory, (String) config.get(values.pTo + ".inventory")
- );
-
- IInventory enderchest = ((CraftInventory) player.getEnderChest()).getInventory();
- config.set(values.pFrom + ".enderchest", buttondevteam.perworld.serializers.inventory.serialize(enderchest));
- plugin.saveConfig();
- if (!values.sharedata)
- buttondevteam.perworld.serializers.inventory.setFromSerialized(
- enderchest, (String) config.get(values.pTo + ".enderchest")
- );
- }
-
-
- //UPDATE PLAYERDATA
- public static void updatePlayerData(Values values, Player player){
- config.set(values.pFrom + ".playerdata", buttondevteam.perworld.serializers.playerdata.serialize(player));
- plugin.saveConfig();
- if (!values.sharedata)
- ;
- }
-}
diff --git a/src/buttondevteam/perworld/serializers/playerdata.java b/src/buttondevteam/perworld/serializers/playerdata.java
deleted file mode 100644
index 5056a25..0000000
--- a/src/buttondevteam/perworld/serializers/playerdata.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package buttondevteam.perworld.serializers;
-
-import java.util.Arrays;
-
-import org.bukkit.entity.Player;
-
-public class playerdata {
-
-
- //SERIALIZE PLAYERDATA
- public static String serialize(Player player){
- StringBuilder result = new StringBuilder();
- result.append("exp:" + player.getExp() + ",");
- result.append("health:" + player.getHealth() + ",");
- result.append("food:" + player.getFoodLevel() + ",");
- result.append("saturation:" + player.getSaturation() + ",");
- result.append("exhaustion:" + player.getExhaustion() + ",");
- result.append("air:" + player.getRemainingAir() + ",");
- result.append("walkspeed:" + player.getWalkSpeed() + ",");
- result.append("fireticks:" + player.getFireTicks() + ",");
- return result.toString();
- }
-
-
- //SET PLAYERDATA FROM SERIALIZED
- public static void setFromSerialized(String dataString, Player player){
- Double.valueOf(null);
- Arrays.asList(dataString.split(","))
- .parallelStream()
- .forEach(s -> {
- String[] e = s.split(":");
- switch(e[0]){
- case "health" :
- player.setHealth(Double.valueOf(e[1]));
- }
- });
-
- }
-}
diff --git a/src/tbmc/perworld/cache/CacheInterface.java b/src/tbmc/perworld/cache/CacheInterface.java
new file mode 100644
index 0000000..a94b808
--- /dev/null
+++ b/src/tbmc/perworld/cache/CacheInterface.java
@@ -0,0 +1,16 @@
+package tbmc.perworld.cache;
+
+import org.bukkit.configuration.ConfigurationSection;
+
+public interface CacheInterface {
+
+ public static ConfigurationSection worlds = tbmc.perworld.main.MainPlugin.worlds;
+ public static ConfigurationSection players = tbmc.perworld.main.MainPlugin.players;
+
+ Object generateElement(String string);
+
+ void putCache(String string);
+
+ void initCache();
+
+}
diff --git a/src/buttondevteam/perworld/cache/CacheRequestHandler.java b/src/tbmc/perworld/cache/CacheRequestHandler.java
similarity index 53%
rename from src/buttondevteam/perworld/cache/CacheRequestHandler.java
rename to src/tbmc/perworld/cache/CacheRequestHandler.java
index 0983930..42d11d9 100644
--- a/src/buttondevteam/perworld/cache/CacheRequestHandler.java
+++ b/src/tbmc/perworld/cache/CacheRequestHandler.java
@@ -1,4 +1,4 @@
-package buttondevteam.perworld.cache;
+package tbmc.perworld.cache;
public class CacheRequestHandler {
diff --git a/src/buttondevteam/perworld/cache/player/GameMode.java b/src/tbmc/perworld/cache/player/GameMode.java
similarity index 71%
rename from src/buttondevteam/perworld/cache/player/GameMode.java
rename to src/tbmc/perworld/cache/player/GameMode.java
index 7f3f86c..7f322e4 100644
--- a/src/buttondevteam/perworld/cache/player/GameMode.java
+++ b/src/tbmc/perworld/cache/player/GameMode.java
@@ -1,4 +1,4 @@
-package buttondevteam.perworld.cache.player;
+package tbmc.perworld.cache.player;
import java.util.HashMap;
diff --git a/src/tbmc/perworld/cache/player/Name.java b/src/tbmc/perworld/cache/player/Name.java
new file mode 100644
index 0000000..8528014
--- /dev/null
+++ b/src/tbmc/perworld/cache/player/Name.java
@@ -0,0 +1,6 @@
+package tbmc.perworld.cache.player;
+
+public class Name {
+
+
+}
diff --git a/src/buttondevteam/perworld/cache/world/ShareSettings.java b/src/tbmc/perworld/cache/world/ShareSettings.java
similarity index 96%
rename from src/buttondevteam/perworld/cache/world/ShareSettings.java
rename to src/tbmc/perworld/cache/world/ShareSettings.java
index 8b7b8d8..9d0768e 100644
--- a/src/buttondevteam/perworld/cache/world/ShareSettings.java
+++ b/src/tbmc/perworld/cache/world/ShareSettings.java
@@ -1,8 +1,8 @@
-package buttondevteam.perworld.cache.world;
+package tbmc.perworld.cache.world;
import java.util.HashMap;
-import buttondevteam.perworld.cache.CacheInterface;
+import tbmc.perworld.cache.CacheInterface;
public class ShareSettings implements CacheInterface {
diff --git a/src/tbmc/perworld/main/CustomConfigClass.java b/src/tbmc/perworld/main/CustomConfigClass.java
new file mode 100644
index 0000000..5888201
--- /dev/null
+++ b/src/tbmc/perworld/main/CustomConfigClass.java
@@ -0,0 +1,19 @@
+package tbmc.perworld.main;
+
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+public class CustomConfigClass extends YamlConfiguration {
+
+ public class SettingsSection extends YamlConfiguration {
+ public final ConfigurationSection worlds = this.getConfigurationSection("worlds");
+ public final ConfigurationSection players = this.getConfigurationSection("players");
+ }
+
+ public final ConfigurationSection commands = this.getConfigurationSection("teleport-commands");
+
+ public final SettingsSection settings = (SettingsSection) this.getConfigurationSection("settings");
+
+ public final ConfigurationSection worlds = this.getConfigurationSection("worlds");
+ public final ConfigurationSection players = this.getConfigurationSection("players");
+}
diff --git a/src/buttondevteam/perworld/main/ListenerPlayerJoin.java b/src/tbmc/perworld/main/ListenerPlayerJoin.java
similarity index 91%
rename from src/buttondevteam/perworld/main/ListenerPlayerJoin.java
rename to src/tbmc/perworld/main/ListenerPlayerJoin.java
index d0b81d2..964c424 100644
--- a/src/buttondevteam/perworld/main/ListenerPlayerJoin.java
+++ b/src/tbmc/perworld/main/ListenerPlayerJoin.java
@@ -1,4 +1,4 @@
-package buttondevteam.perworld.main;
+package tbmc.perworld.main;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
diff --git a/src/buttondevteam/perworld/main/ListenerPlayerWorldChange.java b/src/tbmc/perworld/main/ListenerPlayerWorldChange.java
similarity index 88%
rename from src/buttondevteam/perworld/main/ListenerPlayerWorldChange.java
rename to src/tbmc/perworld/main/ListenerPlayerWorldChange.java
index d3c6aa5..f523be8 100644
--- a/src/buttondevteam/perworld/main/ListenerPlayerWorldChange.java
+++ b/src/tbmc/perworld/main/ListenerPlayerWorldChange.java
@@ -1,6 +1,6 @@
-package buttondevteam.perworld.main;
+package tbmc.perworld.main;
-import static buttondevteam.perworld.main.MainPlugin.debugClock;
+import static tbmc.perworld.main.MainPlugin.debugClock;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
diff --git a/src/buttondevteam/perworld/main/MainPlugin.java b/src/tbmc/perworld/main/MainPlugin.java
similarity index 53%
rename from src/buttondevteam/perworld/main/MainPlugin.java
rename to src/tbmc/perworld/main/MainPlugin.java
index 1afeb26..7a6272b 100644
--- a/src/buttondevteam/perworld/main/MainPlugin.java
+++ b/src/tbmc/perworld/main/MainPlugin.java
@@ -1,10 +1,10 @@
-package buttondevteam.perworld.main;
+package tbmc.perworld.main;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
-import buttondevteam.lib.TBMCCoreAPI;
+//import buttondevteam.lib.TBMCCoreAPI;
public class MainPlugin extends JavaPlugin {
@@ -19,9 +19,10 @@ public class MainPlugin extends JavaPlugin {
public void onEnable(){
- //getServer().getPluginManager().registerEvents(new WorldLoadListener(this), this);
- TBMCCoreAPI.RegisterEventsForExceptions(new WorldChangeListener(this), this);
- TBMCCoreAPI.RegisterEventsForExceptions(new ListenerPlayerWorldChange(this), this);
+ getServer().getPluginManager().registerEvents(new ListenerPlayerJoin(this), this);
+ getServer().getPluginManager().registerEvents(new ListenerPlayerWorldChange(this), this);
+ //TBMCCoreAPI.RegisterEventsForExceptions(new ListenerPlayerJoin(this), this);
+ //TBMCCoreAPI.RegisterEventsForExceptions(new ListenerPlayerWorldChange(this), this);
saveDefaultConfig();
@@ -30,10 +31,6 @@ public class MainPlugin extends JavaPlugin {
worlds = config.getConfigurationSection("worlds");
players = config.getConfigurationSection("players");
- if (!config.contains("worlds")) config.createSection("worlds");
- if (!config.contains("players")) config.createSection("players");
- saveConfig();
-
- new buttondevteam.perworld.cache.world.ShareSettings().initCache();
+ new tbmc.perworld.cache.world.ShareSettings().initCache();
}
}
\ No newline at end of file
diff --git a/src/buttondevteam/perworld/main/PlayerUpdater.java b/src/tbmc/perworld/main/PlayerUpdater.java
similarity index 61%
rename from src/buttondevteam/perworld/main/PlayerUpdater.java
rename to src/tbmc/perworld/main/PlayerUpdater.java
index ea13d83..875f344 100644
--- a/src/buttondevteam/perworld/main/PlayerUpdater.java
+++ b/src/tbmc/perworld/main/PlayerUpdater.java
@@ -1,4 +1,4 @@
-package buttondevteam.perworld.main;
+package tbmc.perworld.main;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
import org.bukkit.entity.Player;
@@ -7,13 +7,17 @@ import net.minecraft.server.v1_10_R1.IInventory;
import java.util.stream.Collectors;
-import static buttondevteam.perworld.cache.world.ShareSettings.compare;
-import static buttondevteam.perworld.main.MainPlugin.config;
-import static buttondevteam.perworld.main.MainPlugin.debugClock;
-import static buttondevteam.perworld.main.MainPlugin.plugin;
+import static tbmc.perworld.cache.world.ShareSettings.compare;
+import static tbmc.perworld.main.MainPlugin.debugClock;
+import static tbmc.perworld.main.MainPlugin.plugin;
+import static tbmc.perworld.main.MainPlugin.config;
public class PlayerUpdater {
+ /* this class is called on world-change events
+ *
+ */
+
//VALUES USED BY THE UPDATE METHODS
public static class Values {
@@ -34,7 +38,6 @@ public class PlayerUpdater {
this.pFrom = "worlds." + worldFrom + ".players." + uuid;
boolean[] compare = compare(worldTo, worldFrom);
- //compare() is a static import from world.ShareSettings.java
this.shareinv = compare[0];
this.sharedata = compare[1];
@@ -51,11 +54,11 @@ public class PlayerUpdater {
updateLocation(values, player);
updateInventories(values, player);
- //updatePlayerData(values, player);
+ updatePlayerData(values, player);
player.sendMessage("...done, " + (System.currentTimeMillis() - debugClock) + " ms");
- new buttondevteam.perworld.cache.world.ShareSettings().initCache();
- player.sendMessage(buttondevteam.perworld.cache.world.ShareSettings.cache.keySet().stream().collect(Collectors.joining(",")));
+ new tbmc.perworld.cache.world.ShareSettings().initCache();
+ player.sendMessage(tbmc.perworld.cache.world.ShareSettings.cache.keySet().stream().collect(Collectors.joining(",")));
}
@@ -63,7 +66,7 @@ public class PlayerUpdater {
public static void updateLocation(Values values, Player player){
config.set(
values.pFrom + ".location",
- buttondevteam.perworld.serializers.location.serialize(player.getLocation())
+ tbmc.perworld.serializers.location.serialize(player.getLocation())
);
plugin.saveConfig();
/* players are not automatically moved to their stored location,
@@ -75,28 +78,30 @@ public class PlayerUpdater {
//UPDATE INVENTORIES
public static void updateInventories(Values values, Player player){
IInventory inventory = ((CraftInventory) player.getInventory()).getInventory();
- config.set(values.pFrom + ".inventory", buttondevteam.perworld.serializers.inventory.serialize(inventory));
+ config.set(values.pFrom + ".inventory", tbmc.perworld.serializers.inventory.serialize(inventory));
plugin.saveConfig();
if (!values.shareinv)
- buttondevteam.perworld.serializers.inventory.setFromSerialized(
- inventory, (String) config.get(values.pTo + ".inventory")
+ tbmc.perworld.serializers.inventory.setFromSerialized(
+ inventory, config.getString(values.pTo + ".inventory")
);
IInventory enderchest = ((CraftInventory) player.getEnderChest()).getInventory();
- config.set(values.pFrom + ".enderchest", buttondevteam.perworld.serializers.inventory.serialize(enderchest));
+ config.set(values.pFrom + ".enderchest", tbmc.perworld.serializers.inventory.serialize(enderchest));
plugin.saveConfig();
- if (!values.sharedata)
- buttondevteam.perworld.serializers.inventory.setFromSerialized(
- enderchest, (String) config.get(values.pTo + ".enderchest")
+ if (!values.shareinv)
+ tbmc.perworld.serializers.inventory.setFromSerialized(
+ enderchest, config.getString(values.pTo + ".enderchest")
);
}
//UPDATE PLAYERDATA
public static void updatePlayerData(Values values, Player player){
- config.set(values.pFrom + ".playerdata", buttondevteam.perworld.serializers.playerdata.serialize(player));
+ config.set(values.pFrom + ".playerdata", tbmc.perworld.serializers.playerdata.serialize(player));
plugin.saveConfig();
if (!values.sharedata)
- ;
+ tbmc.perworld.serializers.playerdata.setFromSerialized(
+ player, config.getString(values.pTo + ".playerdata")
+ );
}
}
diff --git a/src/buttondevteam/perworld/main/SerializerOld.java b/src/tbmc/perworld/main/SerializerOld.java
similarity index 99%
rename from src/buttondevteam/perworld/main/SerializerOld.java
rename to src/tbmc/perworld/main/SerializerOld.java
index d31336a..9909823 100644
--- a/src/buttondevteam/perworld/main/SerializerOld.java
+++ b/src/tbmc/perworld/main/SerializerOld.java
@@ -1,4 +1,4 @@
-package buttondevteam.perworld.main;
+package tbmc.perworld.main;
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/src/buttondevteam/perworld/serializers/inventory.java b/src/tbmc/perworld/serializers/inventory.java
similarity index 97%
rename from src/buttondevteam/perworld/serializers/inventory.java
rename to src/tbmc/perworld/serializers/inventory.java
index d83a07e..63ff553 100644
--- a/src/buttondevteam/perworld/serializers/inventory.java
+++ b/src/tbmc/perworld/serializers/inventory.java
@@ -1,4 +1,4 @@
-package buttondevteam.perworld.serializers;
+package tbmc.perworld.serializers;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
diff --git a/src/buttondevteam/perworld/serializers/location.java b/src/tbmc/perworld/serializers/location.java
similarity index 93%
rename from src/buttondevteam/perworld/serializers/location.java
rename to src/tbmc/perworld/serializers/location.java
index 4b7788d..499e738 100644
--- a/src/buttondevteam/perworld/serializers/location.java
+++ b/src/tbmc/perworld/serializers/location.java
@@ -1,4 +1,4 @@
-package buttondevteam.perworld.serializers;
+package tbmc.perworld.serializers;
import org.bukkit.Location;
import org.bukkit.World;
diff --git a/src/tbmc/perworld/serializers/playerdata.java b/src/tbmc/perworld/serializers/playerdata.java
new file mode 100644
index 0000000..57343c0
--- /dev/null
+++ b/src/tbmc/perworld/serializers/playerdata.java
@@ -0,0 +1,110 @@
+package tbmc.perworld.serializers;
+
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+import org.bukkit.Color;
+import org.bukkit.entity.Player;
+import org.bukkit.potion.PotionEffect;
+import org.bukkit.potion.PotionEffectType;
+
+public class playerdata {
+
+
+ //SERIALIZE PLAYERDATA
+ public static String serialize(Player player){
+ StringBuilder result = new StringBuilder();
+ result.append(player.getExp() + ",");
+ result.append(player.getHealth() + ",");
+ result.append(player.getFoodLevel() + ",");
+ result.append(player.getSaturation() + ",");
+ result.append(player.getExhaustion() + ",");
+ result.append(player.getRemainingAir() + ",");
+ result.append(player.getFireTicks() + ",");
+ result.append(player.getWalkSpeed() + ",");
+ result.append(
+ player.getActivePotionEffects()
+ .stream()
+ .map(s ->
+ {
+ String values =
+ s.getType().getName() + "."
+ + s.getDuration() + "."
+ + s.getAmplifier() + "."
+ + s.isAmbient() + "."
+ + s.hasParticles();
+ Color color = s.getColor();
+ return
+ color == null ?
+ values :
+ values + "." + color.asRGB();
+ }
+ )
+ .collect(Collectors.joining("&"))
+ );
+ return result.toString();
+ }
+
+
+ //RESTORE PLAYER TO DEFAULTS
+ public static void setToDefaults(Player player){
+ player.setExp(0);
+ player.setHealth(20);
+ player.setFoodLevel(20);
+ player.setSaturation(0);
+ player.setExhaustion(0);
+ player.setRemainingAir(20);
+ player.setFireTicks(0);
+ player.setWalkSpeed((float) 0.2);
+ Arrays.asList(PotionEffectType.values()).forEach(s ->
+ {
+ if (s != null){
+ player.removePotionEffect(s);
+ player.sendMessage("removing effect " + s.getName());
+ }else{
+ player.sendMessage("cannot remove null effect");
+ }
+ }
+ );
+ }
+
+
+ //SET PLAYERDATA FROM SERIALIZED
+ public static void setFromSerialized(Player player, String dataString){
+ setToDefaults(player);
+ if (dataString == null || dataString.isEmpty())
+ return;
+
+ String[] data = dataString.split(",");
+
+ player.setExp( Float.parseFloat( data[0]));
+ player.setHealth( Double.parseDouble( data[1]));
+ player.setFoodLevel( Integer.parseInt( data[2]));
+ player.setSaturation( Float.parseFloat( data[3]));
+ player.setExhaustion( Float.parseFloat( data[4]));
+ player.setRemainingAir( Integer.parseInt( data[5]));
+ player.setFireTicks( Integer.parseInt( data[6]));
+ player.setWalkSpeed( Float.parseFloat( data[7]));
+
+ //ADD POTION EFFECTS
+ if (data.length == 9)
+ Arrays.asList(data[8].split("&"))
+ .parallelStream()
+ .map(effect -> effect.split("\\."))
+ .forEach(effectArgs ->
+ player.addPotionEffect(
+ new PotionEffect(
+
+ PotionEffectType.getByName( effectArgs[0]),
+ Integer.parseInt( effectArgs[1]),
+ Integer.parseInt( effectArgs[2]),
+ Boolean.parseBoolean( effectArgs[3]),
+ Boolean.parseBoolean( effectArgs[4]),
+ effectArgs.length == 5 ? null:
+ Color.fromRGB(
+ Integer.parseInt( effectArgs[5]))
+ )
+ )
+ );
+ }
+}