next have to do playerdata serializing
not sure if there’s stuff i was in the middle of changing, there might be weird shit anomalies or there
This commit is contained in:
parent
a664e33963
commit
6ceb5e1210
14 changed files with 242 additions and 150 deletions
BIN
.DS_Store
vendored
BIN
.DS_Store
vendored
Binary file not shown.
|
@ -1,3 +1,5 @@
|
||||||
main: main.MainPlugin
|
main: main.MainPlugin
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
name: PerWorldInventories
|
name: PerWorldInventories
|
||||||
|
softdepend:
|
||||||
|
[Multiverse-Core]
|
BIN
src/.DS_Store
vendored
BIN
src/.DS_Store
vendored
Binary file not shown.
16
src/cache/CacheInterface.java
vendored
Normal file
16
src/cache/CacheInterface.java
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package cache;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
public interface CacheInterface {
|
||||||
|
|
||||||
|
public static ConfigurationSection worlds = main.MainPlugin.worlds;
|
||||||
|
public static ConfigurationSection players = main.MainPlugin.players;
|
||||||
|
|
||||||
|
Object generateElement(String string);
|
||||||
|
|
||||||
|
void putCache(String string);
|
||||||
|
|
||||||
|
void initCache();
|
||||||
|
|
||||||
|
}
|
7
src/cache/CacheRequestHandler.java
vendored
Normal file
7
src/cache/CacheRequestHandler.java
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package cache;
|
||||||
|
|
||||||
|
public class CacheRequestHandler {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
10
src/cache/player/GameMode.java
vendored
Normal file
10
src/cache/player/GameMode.java
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package cache.player;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class GameMode {
|
||||||
|
|
||||||
|
|
||||||
|
//CACHE
|
||||||
|
public static HashMap<String,Integer> cache;
|
||||||
|
}
|
6
src/cache/player/Name.java
vendored
Normal file
6
src/cache/player/Name.java
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
package cache.player;
|
||||||
|
|
||||||
|
public class Name {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
100
src/cache/world/ShareSettings.java
vendored
Normal file
100
src/cache/world/ShareSettings.java
vendored
Normal file
|
@ -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<String,E[]> cache = new HashMap<String,E[]>();
|
||||||
|
/* 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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
21
src/main/ListenerPlayerJoin.java
Normal file
21
src/main/ListenerPlayerJoin.java
Normal file
|
@ -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){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
32
src/main/ListenerPlayerWorldChange.java
Normal file
32
src/main/ListenerPlayerWorldChange.java
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,59 +1,35 @@
|
||||||
package main;
|
package main;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class MainPlugin extends 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(){
|
public void onEnable(){
|
||||||
|
|
||||||
//getServer().getPluginManager().registerEvents(new WorldLoadListener(this), this);
|
getServer().getPluginManager().registerEvents(new ListenerPlayerJoin(this), this);
|
||||||
getServer().getPluginManager().registerEvents(new WorldChangeListener(this), this);
|
getServer().getPluginManager().registerEvents(new ListenerPlayerWorldChange(this), this);
|
||||||
MainPlugin.getPlugin(this.getClass()).getServer().getListeningPluginChannels();
|
|
||||||
|
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
WorldChangeManager.init(this);
|
|
||||||
//BukkitTask task = new initWorldSettings().runTaskLater(this, 20);
|
plugin = this;
|
||||||
}
|
config = getConfig();
|
||||||
}
|
worlds = config.getConfigurationSection("worlds");
|
||||||
/*
|
players = config.getConfigurationSection("players");
|
||||||
public void initWorldSettings(){
|
|
||||||
Bukkit.getServer().getWorlds()
|
if (!config.contains("worlds")) config.createSection("worlds");
|
||||||
.stream()
|
if (!config.contains("players")) config.createSection("players");
|
||||||
.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);
|
|
||||||
|
|
||||||
});
|
|
||||||
saveConfig();
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
|
@ -1,65 +1,19 @@
|
||||||
package main;
|
package main;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
|
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import net.minecraft.server.v1_10_R1.IInventory;
|
import net.minecraft.server.v1_10_R1.IInventory;
|
||||||
|
|
||||||
public class WorldChangeManager {
|
import static cache.world.ShareSettings.compare;
|
||||||
|
import static main.MainPlugin.plugin;
|
||||||
private static MainPlugin plugin;
|
|
||||||
private static FileConfiguration config;
|
import java.util.stream.Collectors;
|
||||||
public static void init(MainPlugin plugin){ //onEnable()
|
|
||||||
WorldChangeManager.plugin = plugin;
|
import static main.MainPlugin.config;
|
||||||
WorldChangeManager.config = plugin.getConfig();
|
import static main.MainPlugin.debugClock;
|
||||||
}
|
|
||||||
|
public class PlayerUpdater {
|
||||||
|
|
||||||
//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
|
//VALUES USED BY THE UPDATE METHODS
|
||||||
|
@ -77,15 +31,18 @@ public class WorldChangeManager {
|
||||||
this.uuid = player.getUniqueId().toString();
|
this.uuid = player.getUniqueId().toString();
|
||||||
this.worldTo = worldTo;
|
this.worldTo = worldTo;
|
||||||
this.worldFrom = worldFrom;
|
this.worldFrom = worldFrom;
|
||||||
this.pTo = worldTo + ".players." + uuid;
|
this.pTo = "worlds." + worldTo + ".players." + uuid;
|
||||||
this.pFrom = worldFrom + ".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.shareinv = compare[0];
|
||||||
this.sharedata = compare[1];
|
this.sharedata = compare[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//MAIN UPDATE METHOD
|
//MAIN UPDATE METHOD
|
||||||
|
@ -96,6 +53,10 @@ public class WorldChangeManager {
|
||||||
updateLocation(values, player);
|
updateLocation(values, player);
|
||||||
updateInventories(values, player);
|
updateInventories(values, player);
|
||||||
//updatePlayerData(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(",")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -10,10 +10,10 @@ public class location {
|
||||||
public static String serialize(Location location){
|
public static String serialize(Location location){
|
||||||
return
|
return
|
||||||
location.getBlockX() + ","
|
location.getBlockX() + ","
|
||||||
+ location.getBlockZ() + ","
|
|
||||||
+ location.getBlockY() + ","
|
+ location.getBlockY() + ","
|
||||||
+ location.getPitch() + ","
|
+ location.getBlockZ() + ","
|
||||||
+ location.getYaw();
|
+ location.getYaw() + ","
|
||||||
|
+ location.getPitch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue