Merge remote-tracking branch 'origin/master' into spigot

# Conflicts:
#	src/com/sekwah/advancedportals/coreconnector/container/PlayerContainer.java
This commit is contained in:
sekwah 2018-01-24 10:22:03 +00:00
commit eaa98480d1
18 changed files with 152 additions and 28 deletions

7
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,7 @@
# Contributing to Advanced Portals
Just generally sick to the coding style and layout style you see in the current project, it will just speed up pull requests. Useful requests will still be accepted if the style is wrong though will take longer as they will need to be changed by me or another key programmer to the project (if there are more at the time of requesting)
Just make sure to fill out the pull request template properly. If one of the fields doesnt apply just remove it or put None as the only bullet point.
More info coming soon

12
PULL_REQUEST_TEMPLATE.md Normal file
View File

@ -0,0 +1,12 @@
Fixes:
-
-
-
Tweaks:
-
-
-
Reason: (Leave this if it is obvious why from the tweak and/or fix notes)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,5 @@
package com.sekwah.advancedportals.core.api.events;
import com.sekwah.advancedportals.core.api.portal.Portal;
/**
* Trigered whenever a player activates the warp after the tags are handled.
*

View File

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

View File

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

View File

@ -3,5 +3,5 @@ package com.sekwah.advancedportals.core.api.portal;
/**
* @author sekwah41
*/
public class Portal {
public class AdvancedPortal {
}

View File

@ -110,7 +110,16 @@ public class CommandWithSubCommands implements CommandTemplate {
}
}
else {
return this.subCommandRegistry.getSubCommands();
List<String> allowedCommands = new ArrayList<>();
for (String subCommandName : this.subCommandRegistry.getSubCommands()) {
if (subCommandName.equalsIgnoreCase(args[0])) {
SubCommand subCommand = this.getSubCommand(subCommandName);
if(subCommand.hasPermission(sender)) {
allowedCommands.add(subCommandName);
}
}
}
return allowedCommands;
}
return null;
}

View File

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

View File

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

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

View File

@ -7,7 +7,7 @@ public class Config {
private boolean useOnlySpecialAxe;
private String axeMaterial = "IRON_AXE";
private String selectorMaterial = "IRON_AXE";
private boolean portalProtection = true;

View File

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

View File

@ -2,6 +2,8 @@ package com.sekwah.advancedportals.coreconnector.container;
import org.bukkit.entity.Player;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import java.util.UUID;
/**
@ -26,4 +28,8 @@ public class PlayerContainer {
public boolean isOp() {
return player.isOp();
}
public PlayerLocation getLoc() {
return null;
}
}