Compare commits
8 commits
Author | SHA1 | Date | |
---|---|---|---|
e95822ab94 | |||
0c72166509 | |||
88a24251f9 | |||
28e3aa721f | |||
eaa9f7f79e | |||
520e54d823 | |||
131c489ccd | |||
777e723105 |
24 changed files with 353 additions and 220 deletions
6
.project
6
.project
|
@ -10,8 +10,14 @@
|
||||||
<arguments>
|
<arguments>
|
||||||
</arguments>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
</buildSpec>
|
</buildSpec>
|
||||||
<natures>
|
<natures>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|
26
config.yml
26
config.yml
|
@ -1,26 +0,0 @@
|
||||||
# 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:
|
|
|
@ -1,4 +1,4 @@
|
||||||
main: tbmc.perworld.main.MainPlugin
|
main: buttondevteam.perworld.main.MainPlugin
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
name: PerWorldInventories
|
name: PerWorldInventories
|
||||||
softdepend:
|
softdepend:
|
||||||
|
|
65
pom.xml
Normal file
65
pom.xml
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.github.TBMCPlugins</groupId>
|
||||||
|
<artifactId>PerWorldInventory</artifactId>
|
||||||
|
<version>master-SNAPSHOT</version>
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>src</sourceDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src</directory>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>.</directory>
|
||||||
|
<includes>
|
||||||
|
<include>*.properties</include>
|
||||||
|
<include>*.yml</include>
|
||||||
|
<include>*.csv</include>
|
||||||
|
<include>*.txt</include>
|
||||||
|
</includes>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.5.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source />
|
||||||
|
<target />
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spigot-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>jitpack.io</id>
|
||||||
|
<url>https://jitpack.io/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.10-R0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||||
|
<artifactId>ButtonCore</artifactId>
|
||||||
|
<version>master-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>1.10-R0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -1 +0,0 @@
|
||||||
not written yet, this will be a breakdown of how the plugin works
|
|
16
src/buttondevteam/perworld/cache/CacheInterface.java
vendored
Normal file
16
src/buttondevteam/perworld/cache/CacheInterface.java
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
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();
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package perworld.cache;
|
package buttondevteam.perworld.cache;
|
||||||
|
|
||||||
public class CacheRequestHandler {
|
public class CacheRequestHandler {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package perworld.cache.player;
|
package buttondevteam.perworld.cache.player;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
6
src/buttondevteam/perworld/cache/player/Name.java
vendored
Normal file
6
src/buttondevteam/perworld/cache/player/Name.java
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
package buttondevteam.perworld.cache.player;
|
||||||
|
|
||||||
|
public class Name {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
package perworld.cache.world;
|
package buttondevteam.perworld.cache.world;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import perworld.cache.CacheInterface;
|
import buttondevteam.perworld.cache.CacheInterface;
|
||||||
|
|
||||||
public class ShareSettings implements CacheInterface {
|
public class ShareSettings implements CacheInterface {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package perworld.main;
|
package buttondevteam.perworld.main;
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
|
@ -1,6 +1,6 @@
|
||||||
package perworld.main;
|
package buttondevteam.perworld.main;
|
||||||
|
|
||||||
import static perworld.main.MainPlugin.debugClock;
|
import static buttondevteam.perworld.main.MainPlugin.debugClock;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
|
@ -1,10 +1,10 @@
|
||||||
package perworld.main;
|
package buttondevteam.perworld.main;
|
||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
//import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
|
|
||||||
public class MainPlugin extends JavaPlugin {
|
public class MainPlugin extends JavaPlugin {
|
||||||
|
|
||||||
|
@ -19,10 +19,9 @@ public class MainPlugin extends JavaPlugin {
|
||||||
|
|
||||||
public void onEnable(){
|
public void onEnable(){
|
||||||
|
|
||||||
getServer().getPluginManager().registerEvents(new ListenerPlayerJoin(this), this);
|
//getServer().getPluginManager().registerEvents(new WorldLoadListener(this), this);
|
||||||
getServer().getPluginManager().registerEvents(new ListenerPlayerWorldChange(this), this);
|
TBMCCoreAPI.RegisterEventsForExceptions(new WorldChangeListener(this), this);
|
||||||
//TBMCCoreAPI.RegisterEventsForExceptions(new ListenerPlayerJoin(this), this);
|
TBMCCoreAPI.RegisterEventsForExceptions(new ListenerPlayerWorldChange(this), this);
|
||||||
//TBMCCoreAPI.RegisterEventsForExceptions(new ListenerPlayerWorldChange(this), this);
|
|
||||||
|
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
|
|
||||||
|
@ -31,6 +30,10 @@ public class MainPlugin extends JavaPlugin {
|
||||||
worlds = config.getConfigurationSection("worlds");
|
worlds = config.getConfigurationSection("worlds");
|
||||||
players = config.getConfigurationSection("players");
|
players = config.getConfigurationSection("players");
|
||||||
|
|
||||||
new perworld.cache.world.ShareSettings().initCache();
|
if (!config.contains("worlds")) config.createSection("worlds");
|
||||||
|
if (!config.contains("players")) config.createSection("players");
|
||||||
|
saveConfig();
|
||||||
|
|
||||||
|
new buttondevteam.perworld.cache.world.ShareSettings().initCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package perworld.main;
|
package buttondevteam.perworld.main;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -7,17 +7,13 @@ import net.minecraft.server.v1_10_R1.IInventory;
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static perworld.cache.world.ShareSettings.compare;
|
import static buttondevteam.perworld.cache.world.ShareSettings.compare;
|
||||||
import static perworld.main.MainPlugin.config;
|
import static buttondevteam.perworld.main.MainPlugin.config;
|
||||||
import static perworld.main.MainPlugin.debugClock;
|
import static buttondevteam.perworld.main.MainPlugin.debugClock;
|
||||||
import static perworld.main.MainPlugin.plugin;
|
import static buttondevteam.perworld.main.MainPlugin.plugin;
|
||||||
|
|
||||||
public class PlayerUpdater {
|
public class PlayerUpdater {
|
||||||
|
|
||||||
/* this class is called on world-change events
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
//VALUES USED BY THE UPDATE METHODS
|
//VALUES USED BY THE UPDATE METHODS
|
||||||
public static class Values {
|
public static class Values {
|
||||||
|
@ -38,6 +34,7 @@ public class PlayerUpdater {
|
||||||
this.pFrom = "worlds." + 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];
|
||||||
|
@ -54,11 +51,11 @@ public class PlayerUpdater {
|
||||||
|
|
||||||
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");
|
player.sendMessage("...done, " + (System.currentTimeMillis() - debugClock) + " ms");
|
||||||
new perworld.cache.world.ShareSettings().initCache();
|
new buttondevteam.perworld.cache.world.ShareSettings().initCache();
|
||||||
player.sendMessage(perworld.cache.world.ShareSettings.cache.keySet().stream().collect(Collectors.joining(",")));
|
player.sendMessage(buttondevteam.perworld.cache.world.ShareSettings.cache.keySet().stream().collect(Collectors.joining(",")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,7 +63,7 @@ public class PlayerUpdater {
|
||||||
public static void updateLocation(Values values, Player player){
|
public static void updateLocation(Values values, Player player){
|
||||||
config.set(
|
config.set(
|
||||||
values.pFrom + ".location",
|
values.pFrom + ".location",
|
||||||
perworld.serializers.location.serialize(player.getLocation())
|
buttondevteam.perworld.serializers.location.serialize(player.getLocation())
|
||||||
);
|
);
|
||||||
plugin.saveConfig();
|
plugin.saveConfig();
|
||||||
/* players are not automatically moved to their stored location,
|
/* players are not automatically moved to their stored location,
|
||||||
|
@ -78,30 +75,28 @@ public class PlayerUpdater {
|
||||||
//UPDATE INVENTORIES
|
//UPDATE INVENTORIES
|
||||||
public static void updateInventories(Values values, Player player){
|
public static void updateInventories(Values values, Player player){
|
||||||
IInventory inventory = ((CraftInventory) player.getInventory()).getInventory();
|
IInventory inventory = ((CraftInventory) player.getInventory()).getInventory();
|
||||||
config.set(values.pFrom + ".inventory", perworld.serializers.inventory.serialize(inventory));
|
config.set(values.pFrom + ".inventory", buttondevteam.perworld.serializers.inventory.serialize(inventory));
|
||||||
plugin.saveConfig();
|
plugin.saveConfig();
|
||||||
if (!values.shareinv)
|
if (!values.shareinv)
|
||||||
perworld.serializers.inventory.setFromSerialized(
|
buttondevteam.perworld.serializers.inventory.setFromSerialized(
|
||||||
inventory, config.getString(values.pTo + ".inventory")
|
inventory, (String) config.get(values.pTo + ".inventory")
|
||||||
);
|
);
|
||||||
|
|
||||||
IInventory enderchest = ((CraftInventory) player.getEnderChest()).getInventory();
|
IInventory enderchest = ((CraftInventory) player.getEnderChest()).getInventory();
|
||||||
config.set(values.pFrom + ".enderchest", perworld.serializers.inventory.serialize(enderchest));
|
config.set(values.pFrom + ".enderchest", buttondevteam.perworld.serializers.inventory.serialize(enderchest));
|
||||||
plugin.saveConfig();
|
plugin.saveConfig();
|
||||||
if (!values.shareinv)
|
if (!values.sharedata)
|
||||||
perworld.serializers.inventory.setFromSerialized(
|
buttondevteam.perworld.serializers.inventory.setFromSerialized(
|
||||||
enderchest, config.getString(values.pTo + ".enderchest")
|
enderchest, (String) config.get(values.pTo + ".enderchest")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//UPDATE PLAYERDATA
|
//UPDATE PLAYERDATA
|
||||||
public static void updatePlayerData(Values values, Player player){
|
public static void updatePlayerData(Values values, Player player){
|
||||||
config.set(values.pFrom + ".playerdata", perworld.serializers.playerdata.serialize(player));
|
config.set(values.pFrom + ".playerdata", buttondevteam.perworld.serializers.playerdata.serialize(player));
|
||||||
plugin.saveConfig();
|
plugin.saveConfig();
|
||||||
if (!values.sharedata)
|
if (!values.sharedata)
|
||||||
perworld.serializers.playerdata.setFromSerialized(
|
;
|
||||||
player, config.getString(values.pTo + ".playerdata")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package perworld.main;
|
package buttondevteam.perworld.main;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
39
src/buttondevteam/perworld/main/WorldChangeListener.java
Normal file
39
src/buttondevteam/perworld/main/WorldChangeListener.java
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
142
src/buttondevteam/perworld/main/WorldChangeManager.java
Normal file
142
src/buttondevteam/perworld/main/WorldChangeManager.java
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
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)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package perworld.serializers;
|
package buttondevteam.perworld.serializers;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
|
@ -1,4 +1,4 @@
|
||||||
package perworld.serializers;
|
package buttondevteam.perworld.serializers;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
39
src/buttondevteam/perworld/serializers/playerdata.java
Normal file
39
src/buttondevteam/perworld/serializers/playerdata.java
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
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]));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
16
src/perworld/cache/CacheInterface.java
vendored
16
src/perworld/cache/CacheInterface.java
vendored
|
@ -1,16 +0,0 @@
|
||||||
package perworld.cache;
|
|
||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
|
|
||||||
public interface CacheInterface {
|
|
||||||
|
|
||||||
public static ConfigurationSection worlds = perworld.main.MainPlugin.worlds;
|
|
||||||
public static ConfigurationSection players = perworld.main.MainPlugin.players;
|
|
||||||
|
|
||||||
Object generateElement(String string);
|
|
||||||
|
|
||||||
void putCache(String string);
|
|
||||||
|
|
||||||
void initCache();
|
|
||||||
|
|
||||||
}
|
|
6
src/perworld/cache/player/Name.java
vendored
6
src/perworld/cache/player/Name.java
vendored
|
@ -1,6 +0,0 @@
|
||||||
package perworld.cache.player;
|
|
||||||
|
|
||||||
public class Name {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
package 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");
|
|
||||||
}
|
|
|
@ -1,110 +0,0 @@
|
||||||
package 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]))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue