From 6ceb5e1210afcc1262b46bbc0be2243fca24761e Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 5 Nov 2016 15:00:29 -0400 Subject: [PATCH] next have to do playerdata serializing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit not sure if there’s stuff i was in the middle of changing, there might be weird shit anomalies or there --- .DS_Store | Bin 6148 -> 6148 bytes plugin.yml | 4 +- src/.DS_Store | Bin 6148 -> 6148 bytes src/cache/CacheInterface.java | 16 +++ src/cache/CacheRequestHandler.java | 7 ++ src/cache/player/GameMode.java | 10 ++ src/cache/player/Name.java | 6 ++ src/cache/world/ShareSettings.java | 100 ++++++++++++++++++ src/main/ListenerPlayerJoin.java | 21 ++++ src/main/ListenerPlayerWorldChange.java | 32 ++++++ src/main/MainPlugin.java | 74 +++++-------- ...dChangeManager.java => PlayerUpdater.java} | 77 ++++---------- src/main/WorldChangeListener.java | 39 ------- src/serializers/location.java | 6 +- 14 files changed, 242 insertions(+), 150 deletions(-) create mode 100644 src/cache/CacheInterface.java create mode 100644 src/cache/CacheRequestHandler.java create mode 100644 src/cache/player/GameMode.java create mode 100644 src/cache/player/Name.java create mode 100644 src/cache/world/ShareSettings.java create mode 100644 src/main/ListenerPlayerJoin.java create mode 100644 src/main/ListenerPlayerWorldChange.java rename src/main/{WorldChangeManager.java => PlayerUpdater.java} (54%) delete mode 100644 src/main/WorldChangeListener.java diff --git a/.DS_Store b/.DS_Store index 97754fd81ef6b21bb96b88ae44f73a9ce65327fb..5b749f68749e8da6b6d80ac8bc6e022e1a430fc6 100644 GIT binary patch delta 331 zcmZoMXfc=|#>B!kF;Q%yo+2af#(>?7ixZfc7bIDlaZb%E?b+U|{%}RFIQd zTw-8wlaYy;g_Vt+gOiIJ1O)`SVuLgC%Y#c2OG=BK5{sh2yv&r;Bq%!|u_Ob=4$05Y zfwL2n!ZK6K;{`;V^Ycm)GxJi5khI2xXV&MXAvkp;C~ixw|gx@`H1!$*O>0|G`y2+bf2r5PC5A*^GYpD>9qZD!}-=Ku!P=0N7} V%#-;=965j*m_RBvM~JLp1^^DVUta(K delta 67 zcmZoMXfc=|#>B)qF;Q%yo+2a9#(>?7j69QhSRQTu%gV*Hv4Ed>Gdl-A2T;joL5}at Vlles)IT(O|k%56_bA-qmW&l)E57Gbt diff --git a/plugin.yml b/plugin.yml index 25e5172..f4a3f8a 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,3 +1,5 @@ main: main.MainPlugin version: 1.0.0 - name: PerWorldInventories \ No newline at end of file + name: PerWorldInventories + softdepend: + [Multiverse-Core] \ No newline at end of file diff --git a/src/.DS_Store b/src/.DS_Store index 4e5679eae8c9aef33e490e016ef93edb83223ffa..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 100644 GIT binary patch delta 71 zcmZoMXfc=|&Zs&uQEZ}~A_oHyFfuR*Y-VI+W1lR*xN0*yhX4noDvEWCEI|0K^GE3 cache; +} diff --git a/src/cache/player/Name.java b/src/cache/player/Name.java new file mode 100644 index 0000000..66a9b7b --- /dev/null +++ b/src/cache/player/Name.java @@ -0,0 +1,6 @@ +package cache.player; + +public class Name { + + +} diff --git a/src/cache/world/ShareSettings.java b/src/cache/world/ShareSettings.java new file mode 100644 index 0000000..bd2e2ab --- /dev/null +++ b/src/cache/world/ShareSettings.java @@ -0,0 +1,100 @@ +package cache.world; + +import java.util.HashMap; + +import cache.CacheInterface; + +public class ShareSettings implements CacheInterface { + + + /* ConfigurationSection "worlds" is a static import from main.MainPlugin.java, + * inherited from CacheInterface. + * + * It points to the section found at config.getConfigurationSection("worlds") + * and contains all world keys, child keys, and their values + * + * this is a static field backed by the actual contents of config.yml + */ + + + + + + //CACHE ELEMENT + public class E { + /* the optional share type (in or out) specifies that the world + * shares with its group in only one traffic direction. + */ + String group; + int t; + public E(String group, int type){ + this.group = group; + this.t = type;//0-default, 1-in, 2-out + } + } + + + //CACHE + public static volatile HashMap cache = new HashMap(); + /* this stores the share settings for each world + * in an easily-parsed format, mapping each world to + * an array e[] of two cache elements (inv and data) + */ + + + + + + //GENERATE ELEMENT (FROM CONFIG) + public E[] generateElement(String world){ + return new E[] + { + new E( + worlds.getString(world + ".share.inventory.group"), + worlds.getInt(world + ".share.inventory.type", 0) + ), + new E( + worlds.getString(world + ".share.playerdata.group"), + worlds.getInt(world + ".share.playerdata.type", 0) + ) + }; + } + + + //PUT CACHE + public void putCache(String world){ + E[] element = generateElement(world); + if ((element[0].group != null || element[1].group != null)) cache.put(world, element); + } + + + //INIT CACHE ( forEach -> putCache() ) + public void initCache(){ + worlds.getKeys(false).forEach(s -> { putCache(s); }); + } + + + + + + //COMPARE SETTINGS + public static boolean[] compare (String worldTo, String worldFrom) { + E[][] params = new E[][] { cache.get(worldTo), cache.get(worldFrom) }; + return params[0] == null || params [1] == null ? + new boolean[] {false, false} : + new boolean[] + { + params[0][0] == null || params[1][0] == null ? false : + + params[0][0].group == params[1][0].group //inv + && params[0][0].t == 0 ? true : params[0][0].t == 1 + && params[1][0].t == 0 ? true : params[1][0].t == 2 + , + params[0][1] == null || params[1][1] == null ? false : + + params[0][1].group == params[1][1].group //data + && params[0][1].t == 0 ? true : params[0][1].t == 1 + && params[1][1].t == 0 ? true : params[1][1].t == 2 + }; + } +} diff --git a/src/main/ListenerPlayerJoin.java b/src/main/ListenerPlayerJoin.java new file mode 100644 index 0000000..34703c1 --- /dev/null +++ b/src/main/ListenerPlayerJoin.java @@ -0,0 +1,21 @@ +package main; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +public class ListenerPlayerJoin implements Listener { + + MainPlugin plugin; + public ListenerPlayerJoin(MainPlugin plugin){ + this.plugin = plugin; + } + + + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerJoin(PlayerJoinEvent event){ + + } + +} diff --git a/src/main/ListenerPlayerWorldChange.java b/src/main/ListenerPlayerWorldChange.java new file mode 100644 index 0000000..25c027d --- /dev/null +++ b/src/main/ListenerPlayerWorldChange.java @@ -0,0 +1,32 @@ +package main; + +import static main.MainPlugin.debugClock; + +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 ListenerPlayerWorldChange implements Listener { + + MainPlugin plugin; + public ListenerPlayerWorldChange(MainPlugin plugin){ + this.plugin = plugin; + + } + + + @EventHandler(priority = EventPriority.MONITOR) + public void onWorldChange(PlayerChangedWorldEvent event){ + + debugClock = System.currentTimeMillis(); + + Player player = event.getPlayer(); player.sendMessage("updating... "); + String gamemode; + String worldTo = player.getWorld().getName(); + String worldFrom = event.getFrom().getName(); + + PlayerUpdater.update(player, worldTo, worldFrom); + } +} diff --git a/src/main/MainPlugin.java b/src/main/MainPlugin.java index 3c83ac0..06c3486 100644 --- a/src/main/MainPlugin.java +++ b/src/main/MainPlugin.java @@ -1,59 +1,35 @@ package main; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; public class MainPlugin extends JavaPlugin { - + + + public static MainPlugin plugin; + public static volatile FileConfiguration config; + + public static volatile ConfigurationSection worlds; + public static volatile ConfigurationSection players; + public static long debugClock; + + public void onEnable(){ - //getServer().getPluginManager().registerEvents(new WorldLoadListener(this), this); - getServer().getPluginManager().registerEvents(new WorldChangeListener(this), this); - MainPlugin.getPlugin(this.getClass()).getServer().getListeningPluginChannels(); - + getServer().getPluginManager().registerEvents(new ListenerPlayerJoin(this), this); + getServer().getPluginManager().registerEvents(new ListenerPlayerWorldChange(this), this); saveDefaultConfig(); - WorldChangeManager.init(this); - //BukkitTask task = new initWorldSettings().runTaskLater(this, 20); - } -} -/* - public void initWorldSettings(){ - Bukkit.getServer().getWorlds() - .stream() - .forEach(s -> { - FileConfiguration config = getConfig(); - String name = s.getName(); - - if (config.get(name + ".settings.shareinvgroup") == null) - config.set(name + ".settings.shareinvgroup", name); - - if (config.get(name + ".settings.sharedatagroup") == null) - config.set(name + ".settings.sharedatagroup", name); - - }); + + plugin = this; + config = getConfig(); + worlds = config.getConfigurationSection("worlds"); + players = config.getConfigurationSection("players"); + + if (!config.contains("worlds")) config.createSection("worlds"); + if (!config.contains("players")) config.createSection("players"); saveConfig(); + + new cache.world.ShareSettings().initCache(); } -} - - private void createConfig(){ - try { - - - if (!getDataFolder().exists()) - getDataFolder().mkdirs(); - - - File file = new File(getDataFolder(), "config.yml"); - - if (!file.exists()){ - getLogger().info("Config.yml not found, creating!"); - saveDefaultConfig(); - }else - getLogger().info("Config.yml found, loading!"); - - - }catch (Exception e) { - e.printStackTrace(); - } - } - -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/src/main/WorldChangeManager.java b/src/main/PlayerUpdater.java similarity index 54% rename from src/main/WorldChangeManager.java rename to src/main/PlayerUpdater.java index d531d7f..2e46790 100644 --- a/src/main/WorldChangeManager.java +++ b/src/main/PlayerUpdater.java @@ -1,65 +1,19 @@ package 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; - } +import static cache.world.ShareSettings.compare; +import static main.MainPlugin.plugin; + +import java.util.stream.Collectors; + +import static main.MainPlugin.config; +import static main.MainPlugin.debugClock; + +public class PlayerUpdater { //VALUES USED BY THE UPDATE METHODS @@ -77,15 +31,18 @@ public class WorldChangeManager { this.uuid = player.getUniqueId().toString(); this.worldTo = worldTo; this.worldFrom = worldFrom; - this.pTo = worldTo + ".players." + uuid; - this.pFrom = worldFrom + ".players." + uuid; + this.pTo = "worlds." + worldTo + ".players." + uuid; + this.pFrom = "worlds." + worldFrom + ".players." + uuid; - boolean[] compare = compare(worldTo,worldFrom); + boolean[] compare = compare(worldTo, worldFrom); + //compare() is a static import from world.ShareSettings.java this.shareinv = compare[0]; this.sharedata = compare[1]; } } + + //MAIN UPDATE METHOD @@ -96,6 +53,10 @@ public class WorldChangeManager { updateLocation(values, player); updateInventories(values, player); //updatePlayerData(values, player); + + player.sendMessage("...done, " + (System.currentTimeMillis() - debugClock) + " ms"); + new cache.world.ShareSettings().initCache(); + player.sendMessage(cache.world.ShareSettings.cache.keySet().stream().collect(Collectors.joining(","))); } diff --git a/src/main/WorldChangeListener.java b/src/main/WorldChangeListener.java deleted file mode 100644 index 7763228..0000000 --- a/src/main/WorldChangeListener.java +++ /dev/null @@ -1,39 +0,0 @@ -package 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/serializers/location.java b/src/serializers/location.java index 7248f84..234d5f9 100644 --- a/src/serializers/location.java +++ b/src/serializers/location.java @@ -10,10 +10,10 @@ public class location { public static String serialize(Location location){ return location.getBlockX() + "," - + location.getBlockZ() + "," + location.getBlockY() + "," - + location.getPitch() + "," - + location.getYaw(); + + location.getBlockZ() + "," + + location.getYaw() + "," + + location.getPitch(); }