mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-22 02:25:49 +01:00
Started working on portal data saving
This commit is contained in:
parent
829ba9bdd4
commit
03c97984a6
@ -31,6 +31,7 @@ command.help.invalidnum= Sorry but \u00A7e%1$s\u00A7c is not a valid page number
|
||||
|
||||
command.reload.help=Reloads portal data
|
||||
command.reload.detailedhelp=Reloads all portal data from files in the data folder
|
||||
command.reload.reloaded= All Advanced Portals data reloaded
|
||||
|
||||
command.version.help=Returns the current version of the plugin
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.sekwah.advancedportals.core;
|
||||
|
||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.api.managers.DestinationManager;
|
||||
import com.sekwah.advancedportals.core.api.managers.PortalManager;
|
||||
import com.sekwah.advancedportals.core.commands.CommandWithSubCommands;
|
||||
import com.sekwah.advancedportals.core.commands.subcommands.portal.ReloadSubCommand;
|
||||
import com.sekwah.advancedportals.core.commands.subcommands.portal.TransUpdateSubCommand;
|
||||
@ -25,6 +27,9 @@ public class AdvancedPortalsCore {
|
||||
private CommandWithSubCommands portalCommand;
|
||||
private CommandWithSubCommands destiCommand;
|
||||
|
||||
private PortalManager portalManager;
|
||||
private DestinationManager destiManager;
|
||||
|
||||
public static final String version = "1.0.0";
|
||||
public static final String lastTranslationUpdate = "1.0.0";
|
||||
|
||||
@ -33,7 +38,9 @@ public class AdvancedPortalsCore {
|
||||
this.infoLogger = infoLogger;
|
||||
this.instance = this;
|
||||
this.commandRegister = commandRegister;
|
||||
this.coreListeners = new CoreListeners();
|
||||
this.coreListeners = new CoreListeners(this);
|
||||
this.portalManager = new PortalManager(this);
|
||||
this.destiManager = new DestinationManager(this);
|
||||
this.onEnable();
|
||||
}
|
||||
|
||||
@ -50,6 +57,8 @@ public class AdvancedPortalsCore {
|
||||
this.registerPortalCommand();
|
||||
this.registerDestinationCommand();
|
||||
|
||||
this.portalManager.loadPortals();
|
||||
|
||||
this.infoLogger.log(Lang.translate("logger.pluginenable"));
|
||||
}
|
||||
|
||||
@ -80,28 +89,39 @@ public class AdvancedPortalsCore {
|
||||
* Loads the portal config into the memory and saves from the memory to check in case certain things have changed
|
||||
* (basically if values are missing or whatever)
|
||||
*/
|
||||
private void loadPortalConfig() {
|
||||
public void loadPortalConfig() {
|
||||
this.config = this.dataStorage.loadJson(Config.class, "config.json");
|
||||
this.dataStorage.storeJson(this.config, "config.json");
|
||||
}
|
||||
|
||||
/**
|
||||
* This cannot be called to disable the plugin, it just performs any saves or anything needed after if they are required
|
||||
*/
|
||||
public void onDisable() {
|
||||
this.infoLogger.log(Lang.translate("logger.plugindisable"));
|
||||
}
|
||||
|
||||
private static AdvancedPortalsCore getInstance() {
|
||||
public static AdvancedPortalsCore getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static DataStorage getDataStorage() {
|
||||
return instance.dataStorage;
|
||||
public DataStorage getDataStorage() {
|
||||
return this.dataStorage;
|
||||
}
|
||||
|
||||
public static InfoLogger getInfoLogger() {
|
||||
return instance.infoLogger;
|
||||
}
|
||||
|
||||
public CoreListeners getCoreListeners() {
|
||||
return this.coreListeners;
|
||||
public static CoreListeners getCoreListeners() {
|
||||
return instance.coreListeners;
|
||||
}
|
||||
|
||||
public static PortalManager getPortalManager() {
|
||||
return instance.portalManager;
|
||||
}
|
||||
|
||||
public static DestinationManager getDestiManager() {
|
||||
return instance.destiManager;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,17 @@
|
||||
package com.sekwah.advancedportals.core;
|
||||
|
||||
import com.sekwah.advancedportals.core.data.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
public class CoreListeners {
|
||||
|
||||
private final AdvancedPortalsCore portalsCore;
|
||||
|
||||
public CoreListeners(AdvancedPortalsCore portalsCore) {
|
||||
this.portalsCore = portalsCore;
|
||||
}
|
||||
|
||||
public void playerJoin(PlayerContainer player) {
|
||||
if(player.isOp()) {
|
||||
if(!Lang.translate("translatedata.lastchange").equals(AdvancedPortalsCore.lastTranslationUpdate)) {
|
||||
@ -16,4 +23,8 @@ public class CoreListeners {
|
||||
}
|
||||
}
|
||||
|
||||
public void playerMove(PlayerContainer player, PlayerLocation fromLoc, PlayerLocation toLoc) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.sekwah.advancedportals.core.api.effect;
|
||||
|
||||
import com.sekwah.advancedportals.core.api.portal.Portal;
|
||||
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.data.PortalLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
@ -10,7 +10,7 @@ import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
public class TestEffect implements WarpEffect {
|
||||
|
||||
@Override
|
||||
public void onWarp(PlayerContainer player, PortalLocation loc, Action action, Portal portal) {
|
||||
public void onWarp(PlayerContainer player, PortalLocation loc, Action action, AdvancedPortal portal) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.sekwah.advancedportals.core.api.effect;
|
||||
|
||||
import com.sekwah.advancedportals.core.api.portal.Portal;
|
||||
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.data.PortalLocation;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
@ -15,7 +15,7 @@ import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
*/
|
||||
public interface WarpEffect {
|
||||
|
||||
void onWarp(PlayerContainer player, PortalLocation loc, Action action, Portal portal);
|
||||
void onWarp(PlayerContainer player, PortalLocation loc, Action action, AdvancedPortal portal);
|
||||
|
||||
Type getType();
|
||||
|
||||
|
@ -1,7 +1,22 @@
|
||||
package com.sekwah.advancedportals.core.api.managers;
|
||||
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.destination.Destination;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class DestinationManager {
|
||||
|
||||
private final AdvancedPortalsCore portalsCore;
|
||||
/**
|
||||
* Contains all the data for the destinations
|
||||
*/
|
||||
private HashMap<String, Destination> destiHashMap = new HashMap<>();
|
||||
|
||||
public DestinationManager(AdvancedPortalsCore portalsCore) {
|
||||
this.portalsCore = portalsCore;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,13 @@
|
||||
package com.sekwah.advancedportals.core.api.managers;
|
||||
|
||||
import com.sekwah.advancedportals.core.api.portal.Portal;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* When a player leaves the server any data stored on them is removed to free memory.
|
||||
@ -17,7 +21,10 @@ public class PortalManager {
|
||||
*/
|
||||
private static final int COOLDOWN = 0;
|
||||
|
||||
private static PortalManager instance = new PortalManager();
|
||||
private static PortalManager instance;
|
||||
|
||||
private final AdvancedPortalsCore portalsCore;
|
||||
|
||||
/**
|
||||
* Store data of when the player last entered the portal
|
||||
*/
|
||||
@ -25,10 +32,16 @@ public class PortalManager {
|
||||
/**
|
||||
* Tracks what portal a player has selected
|
||||
*/
|
||||
private HashMap<String, Portal> selectedPortal = new HashMap();
|
||||
private HashMap<String, AdvancedPortal> selectedPortal = new HashMap();
|
||||
|
||||
public PortalManager() {
|
||||
this.loadPortals();
|
||||
/**
|
||||
* Contains all the data for the portals
|
||||
*/
|
||||
private HashMap<String, AdvancedPortal> portalHashMap;
|
||||
|
||||
public PortalManager(AdvancedPortalsCore portalsCore) {
|
||||
this.instance = this;
|
||||
this.portalsCore = portalsCore;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -36,15 +49,20 @@ public class PortalManager {
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public static void playerLeave(PlayerContainer player) {
|
||||
instance.lastAttempt.remove(player.getUUID());
|
||||
instance.selectedPortal.remove(player.getUUID());
|
||||
public void playerLeave(PlayerContainer player) {
|
||||
this.lastAttempt.remove(player.getUUID());
|
||||
this.selectedPortal.remove(player.getUUID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the default data into the portals.
|
||||
*/
|
||||
private void loadPortals() {
|
||||
|
||||
public void loadPortals() {
|
||||
Type type = new TypeToken<Map<String, AdvancedPortal>>(){}.getType();
|
||||
this.portalHashMap = this.portalsCore.getDataStorage().loadJson(type ,"portals.json");
|
||||
if(this.portalHashMap == null) {
|
||||
this.portalHashMap = new HashMap<>();
|
||||
}
|
||||
this.portalsCore.getDataStorage().storeJson(this.portalHashMap, "config.json");
|
||||
}
|
||||
}
|
||||
|
@ -3,5 +3,5 @@ package com.sekwah.advancedportals.core.api.portal;
|
||||
/**
|
||||
* @author sekwah41
|
||||
*/
|
||||
public class Portal {
|
||||
public class AdvancedPortal {
|
||||
}
|
@ -2,6 +2,7 @@ package com.sekwah.advancedportals.core.commands.subcommands.portal;
|
||||
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.api.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
|
||||
|
||||
@ -10,6 +11,9 @@ import java.util.List;
|
||||
public class ReloadSubCommand implements SubCommand {
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
AdvancedPortalsCore.getInstance().loadPortalConfig();
|
||||
AdvancedPortalsCore.getPortalManager().loadPortals();
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.reload.reloaded"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -10,7 +10,7 @@ import java.util.List;
|
||||
public class TransUpdateSubCommand implements SubCommand {
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
AdvancedPortalsCore.getDataStorage().copyDefaultFile("lang/en_GB.lang", true);
|
||||
AdvancedPortalsCore.getInstance().getDataStorage().copyDefaultFile("lang/en_GB.lang", true);
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("translatedata.replaced"));
|
||||
}
|
||||
|
||||
|
14
src/com/sekwah/advancedportals/core/data/PlayerLocation.java
Normal file
14
src/com/sekwah/advancedportals/core/data/PlayerLocation.java
Normal file
@ -0,0 +1,14 @@
|
||||
package com.sekwah.advancedportals.core.data;
|
||||
|
||||
public class PlayerLocation {
|
||||
|
||||
public final double posX;
|
||||
public final double posY;
|
||||
public final double posZ;
|
||||
|
||||
public PlayerLocation(double posX, double posY, double posZ) {
|
||||
this.posX = posX;
|
||||
this.posY = posY;
|
||||
this.posZ = posZ;
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ public class Config {
|
||||
|
||||
private boolean useOnlySpecialAxe;
|
||||
|
||||
private String axeMaterial = "IRON_AXE";
|
||||
private String selectorMaterial = "IRON_AXE";
|
||||
|
||||
private boolean portalProtection = true;
|
||||
|
||||
|
@ -5,6 +5,7 @@ import com.google.gson.GsonBuilder;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class DataStorage {
|
||||
|
||||
@ -33,8 +34,16 @@ public class DataStorage {
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T loadJson(Type dataHolder, String location) {
|
||||
InputStream jsonResource = this.loadResource(location);
|
||||
if(jsonResource == null) {
|
||||
return null;
|
||||
}
|
||||
BufferedReader bufReader = new BufferedReader(new InputStreamReader(jsonResource));
|
||||
T object = gson.fromJson(bufReader, dataHolder);
|
||||
return object;
|
||||
}
|
||||
public <T> T loadJson(Class<T> dataHolder, String location) {
|
||||
// TODO get json and if file doesnt exist create default class if true
|
||||
InputStream jsonResource = this.loadResource(location);
|
||||
if(jsonResource == null) {
|
||||
try {
|
||||
|
@ -26,4 +26,8 @@ public class PlayerContainer {
|
||||
public boolean isOp() {
|
||||
return player.isOp();
|
||||
}
|
||||
|
||||
public PlayerLocation getLoc() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user