Skip to content

Commit

Permalink
Permission bridge; resolves #42
Browse files Browse the repository at this point in the history
Includes some fixes
  • Loading branch information
Sataniel98 committed May 31, 2016
1 parent 22da8f5 commit dcf58bc
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public void checkWorlds() {
}
}

// Getters & loaders
/* Getters and loaders */
/**
* @return the plugin instance
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerEscapeEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerLeaveDGroupEvent;
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DInstancePlayer;
import io.github.dre2n.dungeonsxl.player.DPermissions;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import org.bukkit.command.CommandSender;
Expand All @@ -48,7 +48,13 @@ public LeaveCommand() {
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);

if (!(plugin.getDPlayers().getByPlayer(player) instanceof DInstancePlayer)) {
MessageUtil.sendMessage(player, DMessages.ERROR_NOT_IN_DUNGEON.getMessage());
return;
}

DInstancePlayer dPlayer = (DInstancePlayer) plugin.getDPlayers().getByPlayer(player);

if (GameWorld.getByWorld(player.getWorld()) != null) {
if (GameWorld.getByWorld(player.getWorld()).isTutorial()) {
Expand Down Expand Up @@ -77,10 +83,7 @@ public void onExecute(String[] args, CommandSender sender) {
if (dGroup != null) {
dGroup.removePlayer(player);
MessageUtil.sendMessage(player, DMessages.CMD_LEAVE_SUCCESS.getMessage());
return;
}

MessageUtil.sendMessage(player, DMessages.ERROR_NOT_IN_DUNGEON.getMessage());
}
}

Expand Down
22 changes: 20 additions & 2 deletions src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
public class MainConfig extends BRConfig {

public static final int CONFIG_VERSION = 5;
public static final int CONFIG_VERSION = 6;

private String language = "en";
private boolean enableEconomy = false;
Expand All @@ -44,13 +44,16 @@ public class MainConfig extends BRConfig {
private boolean sendFloorTitle = true;
private Map<String, Object> externalMobProviders = new HashMap<>();

/* Secure Mode*/
/* Secure Mode */
private boolean secureModeEnabled = false;
private double secureModeCheckInterval = 5;
private boolean openInventories = false;
private boolean dropItems = false;
private List<String> editCommandWhitelist = new ArrayList<>();

/* Permissions bridge */
private List<String> editPermissions = new ArrayList<>();

/* Default Dungeon Settings */
private WorldConfig defaultWorldConfig;

Expand Down Expand Up @@ -154,6 +157,13 @@ public List<String> getEditCommandWhitelist() {
return editCommandWhitelist;
}

/**
* @return the edit mode permissions
*/
public List<String> getEditPermissions() {
return editPermissions;
}

/**
* @return the defaultWorldConfig
*/
Expand Down Expand Up @@ -216,6 +226,10 @@ public void initialize() {
config.set("secureMode.editCommandWhitelist", editCommandWhitelist);
}

if (!config.contains("editPermissions")) {
config.set("editPermissions", editPermissions);
}

/* Default Dungeon Config */
if (!config.contains("default")) {
config.createSection("default");
Expand Down Expand Up @@ -279,6 +293,10 @@ public void load() {
editCommandWhitelist = config.getStringList("secureMode.editCommandWhitelist");
}

if (config.contains("editPermissions")) {
editPermissions = config.getStringList("editPermissions");
}

/* Default Dungeon Config */
ConfigurationSection configSection = config.getConfigurationSection("default");
if (configSection != null) {
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/io/github/dre2n/dungeonsxl/config/WorldConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class WorldConfig {
private Set<DMobType> mobTypes = new HashSet<>();

private List<String> gameCommandWhitelist = new ArrayList<>();
private List<String> gamePermissions = new ArrayList<>();

public WorldConfig() {
}
Expand Down Expand Up @@ -359,6 +360,12 @@ public void load(ConfigurationSection configFile) {
gameCommandWhitelist = plugin.getDefaultConfig().gameCommandWhitelist;
}

if (configFile.contains("gamePermissions")) {
gamePermissions = configFile.getStringList("gamePermissions");
} else {
gamePermissions = plugin.getDefaultConfig().gamePermissions;
}

if (configFile.contains("forcedGameType")) {
GameType gameType = plugin.getGameTypes().getByName(configFile.getString("forcedGameType"));
if (gameType != null) {
Expand Down Expand Up @@ -667,6 +674,13 @@ public List<String> getGameCommandWhitelist() {
return gameCommandWhitelist;
}

/**
* @return the gamePermissions
*/
public List<String> getGamePermissions() {
return gamePermissions;
}

/**
* @return the forcedGameType
*/
Expand Down
40 changes: 34 additions & 6 deletions src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public DEditPlayer(Player player, World world) {
} else {
PlayerUtil.secureTeleport(player, teleport);
}

// Permission bridge
if (plugin.getPermissionProvider() != null) {
for (String permission : plugin.getMainConfig().getEditPermissions()) {
plugin.getPermissionProvider().playerAddTransient(world.getName(), player, permission);
}
}
}

/* Getters and setters */
Expand All @@ -76,6 +83,18 @@ public void setLinesCopy(String[] linesCopy) {
}

/* Actions */
@Override
public void delete() {
// Permission bridge
if (plugin.getPermissionProvider() != null) {
for (String permission : plugin.getMainConfig().getEditPermissions()) {
plugin.getPermissionProvider().playerRemoveTransient(getWorld().getName(), player, permission);
}
}

super.delete();
}

/**
* Escape the EditWorld without saving.
*/
Expand Down Expand Up @@ -115,6 +134,8 @@ public void poke(Block block) {

@Override
public void leave() {
delete();

getSavePlayer().reset(false);

EditWorld editWorld = EditWorld.getByWorld(getWorld());
Expand All @@ -141,14 +162,13 @@ public void sendMessage(String message) {
public void update(boolean updateSecond) {
boolean locationValid = true;
Location teleportLocation = player.getLocation();
boolean teleportWolf = false;
boolean respawnInventory = false;
boolean offline = false;
boolean kick = false;
boolean triggerAllInDistance = false;

EditWorld editWorld = EditWorld.getByWorld(getWorld());

if (!getPlayer().getWorld().equals(getWorld())) {
locationValid = false;
}

if (editWorld != null) {
if (editWorld.getLobbyLocation() == null) {
teleportLocation = editWorld.getWorld().getSpawnLocation();
Expand All @@ -157,8 +177,16 @@ public void update(boolean updateSecond) {
}
}

DPlayerUpdateEvent event = new DPlayerUpdateEvent(this, locationValid, teleportWolf, respawnInventory, offline, kick, triggerAllInDistance);
DPlayerUpdateEvent event = new DPlayerUpdateEvent(this, locationValid, false, false, false, false, false);
plugin.getServer().getPluginManager().callEvent(event);

if (event.isCancelled()) {
return;
}

if (!locationValid) {
PlayerUtil.secureTeleport(getPlayer(), teleportLocation);
}
}

/* Statics */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@ public void leave() {
GameWorld gameWorld = GameWorld.getByWorld(getWorld());
DGroup dGroup = DGroup.getByPlayer(getPlayer());

// Permission bridge
if (plugin.getPermissionProvider() != null) {
for (String permission : gameWorld.getConfig().getGamePermissions()) {
plugin.getPermissionProvider().playerRemoveTransient(getWorld().getName(), player, permission);
}
}

Game game = Game.getByGameWorld(gameWorld);
if (dGroup != null) {
dGroup.removePlayer(getPlayer());
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,13 @@ public void startGame(Game game) {
}
}
}

// Permission bridge
if (plugin.getPermissionProvider() != null) {
for (String permission : gameWorld.getConfig().getGamePermissions()) {
plugin.getPermissionProvider().playerRemoveTransient(gameWorld.getWorld().getName(), player, permission);
}
}
}

GroupSign.updatePerGroup(this);
Expand Down

0 comments on commit dcf58bc

Please sign in to comment.