Made progress on merge conflict

This commit is contained in:
Norbi Peti 2016-11-05 21:47:21 +01:00
parent ae11acc4bf
commit c1a7aa8732
7 changed files with 934 additions and 678 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>iieHardcoreWorld</name> <name>PerWorldInventory</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> </projects>
@ -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>

View file

@ -1,4 +1,4 @@
main: 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
View 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>

View file

@ -4,6 +4,8 @@ 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;
public class MainPlugin extends JavaPlugin { public class MainPlugin extends JavaPlugin {
@ -17,8 +19,10 @@ 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 ListenerPlayerWorldChange(this), this);
saveDefaultConfig(); saveDefaultConfig();
plugin = this; plugin = this;

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

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