Compare commits

...

2 commits
master ... iie

Author SHA1 Message Date
BuildTools 6d88d023d6 Added per-world playerdata, shortened package names
I disabled maven, for now, and commented out the dependencies, so I can
continue working on the plugin. We can figure out that stuff later.
2016-11-07 04:04:33 -05:00
BuildTools 411acc51af Added per-world playerdata
I disabled maven, for now, and commented out the dependencies, so I can
continue working on the plugin. We can figure out that stuff later.
2016-11-07 03:56:42 -05:00
24 changed files with 220 additions and 353 deletions

View file

@ -10,14 +10,8 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -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:

View file

@ -1,4 +1,4 @@
main: buttondevteam.perworld.main.MainPlugin
main: tbmc.perworld.main.MainPlugin
version: 1.0.0
name: PerWorldInventories
softdepend:

65
pom.xml
View file

@ -1,65 +0,0 @@
<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
src/Guide to this plugin Normal file
View file

@ -0,0 +1 @@
not written yet, this will be a breakdown of how the plugin works

View file

@ -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();
}

View file

@ -1,6 +0,0 @@
package buttondevteam.perworld.cache.player;
public class Name {
}

View file

@ -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();
}
}

View file

@ -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)
;
}
}

View file

@ -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]));
}
});
}
}

16
src/perworld/cache/CacheInterface.java vendored Normal file
View file

@ -0,0 +1,16 @@
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();
}

View file

@ -1,4 +1,4 @@
package buttondevteam.perworld.cache;
package perworld.cache;
public class CacheRequestHandler {

View file

@ -1,4 +1,4 @@
package buttondevteam.perworld.cache.player;
package perworld.cache.player;
import java.util.HashMap;

6
src/perworld/cache/player/Name.java vendored Normal file
View file

@ -0,0 +1,6 @@
package perworld.cache.player;
public class Name {
}

View file

@ -1,8 +1,8 @@
package buttondevteam.perworld.cache.world;
package perworld.cache.world;
import java.util.HashMap;
import buttondevteam.perworld.cache.CacheInterface;
import perworld.cache.CacheInterface;
public class ShareSettings implements CacheInterface {

View file

@ -0,0 +1,19 @@
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");
}

View file

@ -1,4 +1,4 @@
package buttondevteam.perworld.main;
package perworld.main;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;

View file

@ -1,6 +1,6 @@
package buttondevteam.perworld.main;
package perworld.main;
import static buttondevteam.perworld.main.MainPlugin.debugClock;
import static perworld.main.MainPlugin.debugClock;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;

View file

@ -1,10 +1,10 @@
package buttondevteam.perworld.main;
package 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 perworld.cache.world.ShareSettings().initCache();
}
}

View file

@ -1,4 +1,4 @@
package buttondevteam.perworld.main;
package 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 perworld.cache.world.ShareSettings.compare;
import static perworld.main.MainPlugin.config;
import static perworld.main.MainPlugin.debugClock;
import static perworld.main.MainPlugin.plugin;
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 perworld.cache.world.ShareSettings().initCache();
player.sendMessage(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())
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", perworld.serializers.inventory.serialize(inventory));
plugin.saveConfig();
if (!values.shareinv)
buttondevteam.perworld.serializers.inventory.setFromSerialized(
inventory, (String) config.get(values.pTo + ".inventory")
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", 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)
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", perworld.serializers.playerdata.serialize(player));
plugin.saveConfig();
if (!values.sharedata)
;
perworld.serializers.playerdata.setFromSerialized(
player, config.getString(values.pTo + ".playerdata")
);
}
}

View file

@ -1,4 +1,4 @@
package buttondevteam.perworld.main;
package perworld.main;
import java.util.ArrayList;
import java.util.Arrays;

View file

@ -1,4 +1,4 @@
package buttondevteam.perworld.serializers;
package perworld.serializers;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

View file

@ -1,4 +1,4 @@
package buttondevteam.perworld.serializers;
package perworld.serializers;
import org.bukkit.Location;
import org.bukkit.World;

View file

@ -0,0 +1,110 @@
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]))
)
)
);
}
}