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
|
||||
version: 1.0.0
|
||||
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;
|
||||
|
||||
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);
|
||||
plugin = this;
|
||||
config = getConfig();
|
||||
worlds = config.getConfigurationSection("worlds");
|
||||
players = config.getConfigurationSection("players");
|
||||
|
||||
if (config.get(name + ".settings.sharedatagroup") == null)
|
||||
config.set(name + ".settings.sharedatagroup", name);
|
||||
|
||||
});
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
|
@ -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 {
|
||||
import static cache.world.ShareSettings.compare;
|
||||
import static main.MainPlugin.plugin;
|
||||
|
||||
private static MainPlugin plugin;
|
||||
private static FileConfiguration config;
|
||||
public static void init(MainPlugin plugin){ //onEnable()
|
||||
WorldChangeManager.plugin = plugin;
|
||||
WorldChangeManager.config = plugin.getConfig();
|
||||
}
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static main.MainPlugin.config;
|
||||
import static main.MainPlugin.debugClock;
|
||||
|
||||
//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;
|
||||
}
|
||||
public class PlayerUpdater {
|
||||
|
||||
|
||||
//VALUES USED BY THE UPDATE METHODS
|
||||
|
@ -77,10 +31,11 @@ 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);
|
||||
//compare() is a static import from world.ShareSettings.java
|
||||
|
||||
this.shareinv = compare[0];
|
||||
this.sharedata = compare[1];
|
||||
|
@ -88,6 +43,8 @@ public class WorldChangeManager {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//MAIN UPDATE METHOD
|
||||
public static void update(Player player, String worldTo, String worldFrom){
|
||||
|
||||
|
@ -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(",")));
|
||||
}
|
||||
|
||||
|
|
@ -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){
|
||||
return
|
||||
location.getBlockX() + ","
|
||||
+ location.getBlockZ() + ","
|
||||
+ location.getBlockY() + ","
|
||||
+ location.getPitch() + ","
|
||||
+ location.getYaw();
|
||||
+ location.getBlockZ() + ","
|
||||
+ location.getYaw() + ","
|
||||
+ location.getPitch();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue