Merge iie's code into my code #1

Merged
NorbiPeti merged 4 commits from iie into master 2016-11-05 20:57:36 +00:00
23 changed files with 1099 additions and 751 deletions

BIN
.DS_Store vendored

Binary file not shown.

1
.gitignore vendored
View file

@ -12,3 +12,4 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/bin/
/target/

View file

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

1348
LICENSE

File diff suppressed because it is too large Load diff

View file

@ -1,3 +1,5 @@
main: main.MainPlugin
main: buttondevteam.perworld.main.MainPlugin
version: 1.0.0
name: PerWorldInventories
name: PerWorldInventories
softdepend:
[Multiverse-Core]

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>

BIN
src/.DS_Store vendored

Binary file not shown.

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

View file

@ -0,0 +1,7 @@
package buttondevteam.perworld.cache;
public class CacheRequestHandler {
}

View file

@ -0,0 +1,10 @@
package buttondevteam.perworld.cache.player;
import java.util.HashMap;
public class GameMode {
//CACHE
public static HashMap<String,Integer> cache;
}

View file

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

View file

@ -0,0 +1,100 @@
package buttondevteam.perworld.cache.world;
import java.util.HashMap;
import buttondevteam.perworld.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
};
}
}

View file

@ -0,0 +1,21 @@
package buttondevteam.perworld.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){
}
}

View file

@ -0,0 +1,32 @@
package buttondevteam.perworld.main;
import static buttondevteam.perworld.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);
}
}

View file

@ -0,0 +1,39 @@
package buttondevteam.perworld.main;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import buttondevteam.lib.TBMCCoreAPI;
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);
TBMCCoreAPI.RegisterEventsForExceptions(new WorldChangeListener(this), this);
TBMCCoreAPI.RegisterEventsForExceptions(new ListenerPlayerWorldChange(this), this);
saveDefaultConfig();
plugin = this;
config = getConfig();
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();
}
}

View file

@ -0,0 +1,102 @@
package buttondevteam.perworld.main;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
import org.bukkit.entity.Player;
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;
public class PlayerUpdater {
//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 = "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];
}
}
//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);
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(",")));
}
//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,4 +1,4 @@
package main;
package buttondevteam.perworld.main;
import java.util.ArrayList;
import java.util.Arrays;

View file

@ -1,4 +1,4 @@
package main;
package buttondevteam.perworld.main;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;

View file

@ -1,4 +1,4 @@
package main;
package buttondevteam.perworld.main;
import java.util.Arrays;
@ -103,7 +103,7 @@ public class WorldChangeManager {
public static void updateLocation(Values values, Player player){
config.set(
values.pFrom + ".location",
serializers.location.serialize(player.getLocation())
buttondevteam.perworld.serializers.location.serialize(player.getLocation())
);
plugin.saveConfig();
/* players are not automatically moved to their stored location,
@ -115,18 +115,18 @@ public class WorldChangeManager {
//UPDATE INVENTORIES
public static void updateInventories(Values values, Player player){
IInventory inventory = ((CraftInventory) player.getInventory()).getInventory();
config.set(values.pFrom + ".inventory", serializers.inventory.serialize(inventory));
config.set(values.pFrom + ".inventory", buttondevteam.perworld.serializers.inventory.serialize(inventory));
plugin.saveConfig();
if (!values.shareinv)
serializers.inventory.setFromSerialized(
buttondevteam.perworld.serializers.inventory.setFromSerialized(
inventory, (String) config.get(values.pTo + ".inventory")
);
IInventory enderchest = ((CraftInventory) player.getEnderChest()).getInventory();
config.set(values.pFrom + ".enderchest", serializers.inventory.serialize(enderchest));
config.set(values.pFrom + ".enderchest", buttondevteam.perworld.serializers.inventory.serialize(enderchest));
plugin.saveConfig();
if (!values.sharedata)
serializers.inventory.setFromSerialized(
buttondevteam.perworld.serializers.inventory.setFromSerialized(
enderchest, (String) config.get(values.pTo + ".enderchest")
);
}
@ -134,7 +134,7 @@ public class WorldChangeManager {
//UPDATE PLAYERDATA
public static void updatePlayerData(Values values, Player player){
config.set(values.pFrom + ".playerdata", serializers.playerdata.serialize(player));
config.set(values.pFrom + ".playerdata", buttondevteam.perworld.serializers.playerdata.serialize(player));
plugin.saveConfig();
if (!values.sharedata)
;

View file

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

View file

@ -1,4 +1,4 @@
package serializers;
package buttondevteam.perworld.serializers;
import org.bukkit.Location;
import org.bukkit.World;
@ -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();
}

View file

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

View file

@ -1,59 +0,0 @@
package main;
import org.bukkit.plugin.java.JavaPlugin;
public class MainPlugin extends JavaPlugin {
public void onEnable(){
//getServer().getPluginManager().registerEvents(new WorldLoadListener(this), this);
getServer().getPluginManager().registerEvents(new WorldChangeListener(this), this);
MainPlugin.getPlugin(this.getClass()).getServer().getListeningPluginChannels();
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);
if (config.get(name + ".settings.sharedatagroup") == null)
config.set(name + ".settings.sharedatagroup", name);
});
saveConfig();
}
}
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();
}
}
*/