mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-09 12:20:30 +01:00
Secure Mode
This commit is contained in:
parent
63ffd6a3f8
commit
cdb18b5ae6
@ -45,6 +45,7 @@ import io.github.dre2n.dungeonsxl.requirement.RequirementTypes;
|
||||
import io.github.dre2n.dungeonsxl.reward.RewardTypes;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSigns;
|
||||
import io.github.dre2n.dungeonsxl.task.LazyUpdateTask;
|
||||
import io.github.dre2n.dungeonsxl.task.SecureModeTask;
|
||||
import io.github.dre2n.dungeonsxl.task.UpdateTask;
|
||||
import io.github.dre2n.dungeonsxl.task.WorldUnloadTask;
|
||||
import io.github.dre2n.dungeonsxl.trigger.Triggers;
|
||||
@ -81,6 +82,7 @@ public class DungeonsXL extends BRPlugin {
|
||||
private BukkitTask worldUnloadTask;
|
||||
private BukkitTask lazyUpdateTask;
|
||||
private BukkitTask updateTask;
|
||||
private BukkitTask secureModeTask;
|
||||
|
||||
private CopyOnWriteArrayList<DLootInventory> dLootInventories = new CopyOnWriteArrayList<>();
|
||||
private CopyOnWriteArrayList<EditWorld> editWorlds = new CopyOnWriteArrayList<>();
|
||||
@ -144,6 +146,9 @@ public class DungeonsXL extends BRPlugin {
|
||||
startWorldUnloadTask(1200L);
|
||||
startLazyUpdateTask(20L);
|
||||
startUpdateTask(20L);
|
||||
if (mainConfig.isSecureModeEnabled()) {
|
||||
startSecureModeTask(mainConfig.getSecureModeCheckInterval());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -480,6 +485,20 @@ public class DungeonsXL extends BRPlugin {
|
||||
updateTask = new UpdateTask().runTaskTimer(this, 0L, period);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the secureModeTask
|
||||
*/
|
||||
public BukkitTask getSecureModeTask() {
|
||||
return secureModeTask;
|
||||
}
|
||||
|
||||
/**
|
||||
* start a new SecureModeTask
|
||||
*/
|
||||
public void startSecureModeTask(long period) {
|
||||
updateTask = new SecureModeTask().runTaskTimer(this, 0L, period);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dLootInventories
|
||||
*/
|
||||
|
@ -27,7 +27,7 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
*/
|
||||
public class MainConfig extends BRConfig {
|
||||
|
||||
public static final int CONFIG_VERSION = 2;
|
||||
public static final int CONFIG_VERSION = 3;
|
||||
|
||||
private String language = "en";
|
||||
private boolean enableEconomy = false;
|
||||
@ -40,6 +40,12 @@ public class MainConfig extends BRConfig {
|
||||
|
||||
/* Misc */
|
||||
private boolean sendFloorTitle = true;
|
||||
|
||||
/* Secure Mode*/
|
||||
private boolean secureModeEnabled = false;
|
||||
private long secureModeCheckInterval = 100;
|
||||
private boolean openInventories = false;
|
||||
private boolean dropItems = false;
|
||||
private List<String> editCommandWhitelist = new ArrayList<>();
|
||||
|
||||
/* Default Dungeon Settings */
|
||||
@ -61,14 +67,6 @@ public class MainConfig extends BRConfig {
|
||||
return language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param language
|
||||
* the language to set
|
||||
*/
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the enableEconomy
|
||||
*/
|
||||
@ -111,6 +109,34 @@ public class MainConfig extends BRConfig {
|
||||
return tutorialEndGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the secure mode is enabled
|
||||
*/
|
||||
public boolean isSecureModeEnabled() {
|
||||
return secureModeEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if players may open inventories while editing; false if secure mode disabled
|
||||
*/
|
||||
public boolean getOpenInventories() {
|
||||
return openInventories && secureModeEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if players may drop items while editing; false if secure mode disabled
|
||||
*/
|
||||
public boolean getDropItems() {
|
||||
return dropItems && secureModeEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the interval for the check task
|
||||
*/
|
||||
public long getSecureModeCheckInterval() {
|
||||
return secureModeCheckInterval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the editCommandWhitelist
|
||||
*/
|
||||
@ -125,14 +151,6 @@ public class MainConfig extends BRConfig {
|
||||
return defaultWorldConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param defaultWorldConfig
|
||||
* the defaultWorldConfig to set
|
||||
*/
|
||||
public void setDefaultWorldConfig(WorldConfig defaultWorldConfig) {
|
||||
this.defaultWorldConfig = defaultWorldConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
/* Main Config */
|
||||
@ -164,8 +182,24 @@ public class MainConfig extends BRConfig {
|
||||
config.set("sendFloorTitle", sendFloorTitle);
|
||||
}
|
||||
|
||||
if (!config.contains("editCommandWhitelist")) {
|
||||
config.set("editCommandWhitelist", editCommandWhitelist);
|
||||
if (!config.contains("secureMode.enabled")) {
|
||||
config.set("secureMode.enabled", secureModeEnabled);
|
||||
}
|
||||
|
||||
if (!config.contains("secureMode.openInventories")) {
|
||||
config.set("secureMode.openInventories", openInventories);
|
||||
}
|
||||
|
||||
if (!config.contains("secureMode.dropItems")) {
|
||||
config.set("secureMode.dropItems", dropItems);
|
||||
}
|
||||
|
||||
if (!config.contains("secureMode.checkInterval")) {
|
||||
config.set("secureMode.checkInterval", secureModeCheckInterval);
|
||||
}
|
||||
|
||||
if (!config.contains("secureMode.editCommandWhitelist")) {
|
||||
config.set("secureMode.editCommandWhitelist", editCommandWhitelist);
|
||||
}
|
||||
|
||||
/* Default Dungeon Config */
|
||||
@ -207,14 +241,30 @@ public class MainConfig extends BRConfig {
|
||||
sendFloorTitle = config.getBoolean("sendFloorTitle");
|
||||
}
|
||||
|
||||
if (config.contains("editCommandWhitelist")) {
|
||||
editCommandWhitelist = config.getStringList("editCommandWhitelist");
|
||||
if (config.contains("secureMode.enabled")) {
|
||||
secureModeEnabled = config.getBoolean("secureMode.enabled");
|
||||
}
|
||||
|
||||
if (config.contains("secureMode.openInventories")) {
|
||||
openInventories = config.getBoolean("secureMode.openInventories");
|
||||
}
|
||||
|
||||
if (config.contains("secureMode.dropItems")) {
|
||||
dropItems = config.getBoolean("secureMode.dropItems");
|
||||
}
|
||||
|
||||
if (config.contains("secureMode.checkInterval")) {
|
||||
secureModeCheckInterval = config.getLong("secureMode.checkInterval");
|
||||
}
|
||||
|
||||
if (config.contains("secureMode.editCommandWhitelist")) {
|
||||
editCommandWhitelist = config.getStringList("secureMode.editCommandWhitelist");
|
||||
}
|
||||
|
||||
/* Default Dungeon Config */
|
||||
ConfigurationSection configSection = config.getConfigurationSection("default");
|
||||
if (configSection != null) {
|
||||
setDefaultWorldConfig(new WorldConfig(configSection));
|
||||
defaultWorldConfig = new WorldConfig(configSection);
|
||||
WorldConfig.defaultConfig = defaultWorldConfig;// TODO
|
||||
}
|
||||
}
|
||||
|
@ -220,6 +220,7 @@ public class GameChest {
|
||||
|
||||
/* Statics */
|
||||
/**
|
||||
* @deprecated
|
||||
* @param event
|
||||
* event.getPlayer() has to be a Player
|
||||
*/
|
||||
|
@ -46,6 +46,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -56,6 +57,7 @@ import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
@ -312,7 +314,15 @@ public class PlayerListener implements Listener {
|
||||
public void onDropItem(PlayerDropItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
// Deny dropping things at the lobby
|
||||
DPlayer dPlayer = DPlayer.getByPlayer(player);
|
||||
if (dPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (dPlayer.isEditing() && !plugin.getMainConfig().getDropItems() && !player.hasPermission("dxl.insecure")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
if (dGroup == null) {
|
||||
return;
|
||||
@ -323,11 +333,6 @@ public class PlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
DPlayer dPlayer = DPlayer.getByPlayer(player);
|
||||
if (dPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dPlayer.isReady()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -603,8 +608,17 @@ public class PlayerListener implements Listener {
|
||||
// Inventory Events
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
if (event.getPlayer() instanceof Player) {
|
||||
if (!(event.getPlayer() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
GameChest.onOpenInventory(event);
|
||||
|
||||
if (!plugin.getMainConfig().getOpenInventories() && !event.getPlayer().hasPermission("dxl.insecure")) {
|
||||
World world = event.getPlayer().getWorld();
|
||||
if (event.getInventory().getType() != InventoryType.CREATIVE && EditWorld.getByWorld(world) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Daniel Saukel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.task;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGlobalPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class SecureModeTask extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
DGlobalPlayer dGlobalPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player);
|
||||
if (dGlobalPlayer == null) {
|
||||
dGlobalPlayer = new DGlobalPlayer(player);
|
||||
}
|
||||
|
||||
if (!(dGlobalPlayer instanceof DPlayer || dGlobalPlayer instanceof DEditPlayer)) {
|
||||
if (player.getWorld().getName().startsWith("DXL_Game_") | player.getWorld().getName().startsWith("DXL_Edit_") && !player.hasPermission("dxl.insecure")) {
|
||||
player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -66,3 +66,5 @@ permissions:
|
||||
default: op
|
||||
dxl.cmdedit:
|
||||
default: op
|
||||
dxl.insecure:
|
||||
default: op
|
||||
|
Loading…
Reference in New Issue
Block a user