mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 19:45:43 +01:00
Made Vault soft dependency only
This commit is contained in:
parent
ebd644afe7
commit
e0a87dd2ac
@ -42,6 +42,8 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
public class DungeonsXL extends JavaPlugin {
|
||||
|
||||
private static DungeonsXL plugin;
|
||||
private Economy economyProvider;
|
||||
private Permission permissionProvider;
|
||||
|
||||
private MainConfig mainConfig;
|
||||
private DMessages dMessages;
|
||||
@ -80,10 +82,10 @@ public class DungeonsXL extends JavaPlugin {
|
||||
initFolders();
|
||||
|
||||
// Setup Permissions
|
||||
setupPermissions();
|
||||
loadPermissionProvider();
|
||||
|
||||
// Setup Economy
|
||||
setupEconomy();
|
||||
loadEconomyProvider();
|
||||
|
||||
getCommand("dungeonsxl").setExecutor(new CommandListener());
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new EntityListener(), this);
|
||||
@ -195,43 +197,6 @@ public class DungeonsXL extends JavaPlugin {
|
||||
}, 0L, 2L);
|
||||
}
|
||||
|
||||
// Permissions
|
||||
public Permission permission = null;
|
||||
|
||||
private Boolean setupPermissions() {
|
||||
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
|
||||
if (permissionProvider != null) {
|
||||
permission = permissionProvider.getProvider();
|
||||
}
|
||||
return permission != null;
|
||||
}
|
||||
|
||||
public Boolean GroupEnabled(String group) {
|
||||
|
||||
for (String agroup : permission.getGroups()) {
|
||||
if (agroup.equalsIgnoreCase(group)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Economy
|
||||
public Economy economy = null;
|
||||
|
||||
private Boolean setupEconomy() {
|
||||
if (mainConfig.enableEconomy()) {
|
||||
RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if (economyProvider != null) {
|
||||
economy = economyProvider.getProvider();
|
||||
}
|
||||
return economy != null;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Save and Load
|
||||
public void saveData() {
|
||||
File file = new File(getDataFolder(), "data.yml");
|
||||
@ -293,6 +258,64 @@ public class DungeonsXL extends JavaPlugin {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of Economy
|
||||
*/
|
||||
public Economy getEconomyProvider() {
|
||||
return economyProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* load / reload a new instance of Permission
|
||||
*/
|
||||
public void loadEconomyProvider() {
|
||||
try {
|
||||
if (mainConfig.enableEconomy()) {
|
||||
RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (economyProvider != null) {
|
||||
this.economyProvider = economyProvider.getProvider();
|
||||
}
|
||||
}
|
||||
} catch (NoClassDefFoundError error) {
|
||||
getLogger().info("Could not hook into Vault to register an economy provider!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of Permission
|
||||
*/
|
||||
public Permission getPermissionProvider() {
|
||||
return permissionProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* load / reload a new instance of Permission
|
||||
*/
|
||||
public void loadPermissionProvider() {
|
||||
try {
|
||||
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(Permission.class);
|
||||
if (permissionProvider != null) {
|
||||
this.permissionProvider = permissionProvider.getProvider();
|
||||
}
|
||||
} catch (NoClassDefFoundError error) {
|
||||
getLogger().info("Could not hook into Vault to register a permission provider!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param group
|
||||
* the group to be checked
|
||||
*/
|
||||
public boolean isGroupEnabled(String group) {
|
||||
for (String agroup : permissionProvider.getGroups()) {
|
||||
if (agroup.equalsIgnoreCase(group)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of MainConfig
|
||||
*/
|
||||
|
@ -198,7 +198,7 @@ public class GameWorld {
|
||||
WorldConfig worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + dungeon, "config.yml"));
|
||||
|
||||
if (plugin.getMainConfig().enableEconomy()) {
|
||||
if ( !(DungeonsXL.getPlugin().economy.getBalance(player) >= worldConfig.getFee())) {
|
||||
if ( !(DungeonsXL.getPlugin().getEconomyProvider().getBalance(player) >= worldConfig.getFee())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -413,7 +413,7 @@ public class PlayerListener implements Listener {
|
||||
if (plugin.getMainConfig().isTutorialActivated()) {
|
||||
if (DPlayer.get(player) == null) {
|
||||
if (plugin.getMainConfig().getTutorialDungeon() != null && plugin.getMainConfig().getTutorialStartGroup() != null && plugin.getMainConfig().getTutorialEndGroup() != null) {
|
||||
for (String group : plugin.permission.getPlayerGroups(player)) {
|
||||
for (String group : plugin.getPermissionProvider().getPlayerGroups(player)) {
|
||||
if (plugin.getMainConfig().getTutorialStartGroup().equalsIgnoreCase(group)) {
|
||||
DGroup dgroup = new DGroup(player, plugin.getMainConfig().getTutorialDungeon(), false);
|
||||
|
||||
|
@ -233,8 +233,8 @@ public class DGroup {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (plugin.economy != null) {
|
||||
DungeonsXL.getPlugin().economy.withdrawPlayer(player, fee);
|
||||
if (plugin.getEconomyProvider() != null) {
|
||||
plugin.getEconomyProvider().withdrawPlayer(player, fee);
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,6 +249,7 @@ public class DGroup {
|
||||
return dgroup;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -258,6 +259,7 @@ public class DGroup {
|
||||
return dgroup;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -145,8 +145,8 @@ public class DPlayer {
|
||||
if ( !isinTestMode) {// Nur wenn man nicht am Testen ist
|
||||
if (isFinished) {
|
||||
addTreasure();
|
||||
if (plugin.economy != null) {
|
||||
plugin.economy.depositPlayer(player, treasureMoney);
|
||||
if (plugin.getEconomyProvider() != null) {
|
||||
plugin.getEconomyProvider().depositPlayer(player, treasureMoney);
|
||||
}
|
||||
|
||||
// Set Time
|
||||
@ -172,8 +172,15 @@ public class DPlayer {
|
||||
|
||||
// Tutorial Permissions
|
||||
if (gWorld.isTutorial) {
|
||||
plugin.permission.playerAddGroup(player, plugin.getMainConfig().getTutorialEndGroup());
|
||||
plugin.permission.playerRemoveGroup(player, plugin.getMainConfig().getTutorialStartGroup());
|
||||
String endGroup = plugin.getMainConfig().getTutorialEndGroup();
|
||||
if (plugin.isGroupEnabled(endGroup)) {
|
||||
plugin.getPermissionProvider().playerAddGroup(player, endGroup);
|
||||
}
|
||||
|
||||
String startGroup = plugin.getMainConfig().getTutorialStartGroup();
|
||||
if (plugin.isGroupEnabled(startGroup)) {
|
||||
plugin.getPermissionProvider().playerRemoveGroup(player, startGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -235,7 +242,6 @@ public class DPlayer {
|
||||
|
||||
// Respawn Items
|
||||
if (GameWorld.get(world).getConfig().getKeepInventoryOnDeath()) {
|
||||
org.bukkit.Bukkit.broadcastMessage("deactivated code triggered");
|
||||
if (respawnInventory != null || respawnArmor != null) {
|
||||
player.getInventory().setContents(respawnInventory);
|
||||
player.getInventory().setArmorContents(respawnArmor);
|
||||
@ -300,6 +306,10 @@ public class DPlayer {
|
||||
dGroup.removeUnplayedFloor(dGroup.getMapName());
|
||||
dGroup.setMapName(newFloor);
|
||||
dGroup.setGWorld(GameWorld.load(newFloor));
|
||||
for (Player player : dGroup.getPlayers()) {
|
||||
DPlayer dPlayer = get(player);
|
||||
dPlayer.checkpoint = dGroup.getGWorld().locStart;
|
||||
}
|
||||
dGroup.startGame();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user