Skip to content

Commit

Permalink
Merge pull request #120 from DRE2N/new-protection
Browse files Browse the repository at this point in the history
New game block protection system; close #116
  • Loading branch information
Sataniel98 authored Jul 28, 2016
2 parents 3366f6b + 914c31a commit 514a3f1
Show file tree
Hide file tree
Showing 15 changed files with 416 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public enum DMessages implements Messages {
GROUP_KICKED_PLAYER("Group_KickedPlayer", "&4&v1&6 kicked the player &4&v2&6 from the group &4&v3&6."),
GROUP_PLAYER_JOINED("Group_PlayerJoined", "&6Player &4&v1&6 has joined the group!"),
GROUP_WAVE_FINISHED("Group_WaveFinished", "&6Your group finished wave no. &4&v1&6. The next one is going to start in &4&v2&6 seconds."),
LOG_DISABLED_TWEAKS("Log_DisabledTweaks", "&4Disabled performance tweaks because there is no support for this server software."),
LOG_ERROR_MOB_ENCHANTMENT("Log_Error_MobEnchantment", "&4Error at loading mob.yml: Enchantment &6&v1&4 doesn't exist!"),
LOG_ERROR_MOBTYPE("Log_Error_MobType", "&4Error at loading mob.yml: Mob &6&v1&4 doesn't exist!"),
LOG_ERROR_NO_CONSOLE_COMMAND("Log_Error_NoConsoleCommand", "&6/dxl &v1&4 can not be executed as console!"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
*/
package io.github.dre2n.dungeonsxl.config;

import io.github.dre2n.commons.compatibility.CompatibilityHandler;
import io.github.dre2n.commons.compatibility.Internals;
import io.github.dre2n.commons.config.BRConfig;
import io.github.dre2n.commons.util.EnumUtil;
import io.github.dre2n.commons.util.messageutil.MessageUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -496,7 +499,12 @@ public void load() {
}

if (config.contains("tweaksEnabled")) {
tweaksEnabled = config.getBoolean("tweaksEnabled");
if (Internals.andHigher(Internals.v1_9_R1).contains(CompatibilityHandler.getInstance().getInternals())) {
tweaksEnabled = config.getBoolean("tweaksEnabled");
} else {
tweaksEnabled = false;
MessageUtil.log(DMessages.LOG_DISABLED_TWEAKS.getMessage());
}
}

if (config.contains("secureMode.enabled")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
Expand Down Expand Up @@ -121,12 +125,7 @@ public void load(ConfigurationSection configFile) {
keepInventoryOnDeath = configFile.getBoolean("keepInventoryOnDeath");
}

/* Build */
if (configFile.contains("build")) {
build = configFile.getBoolean("build");
}

/* GameMode */
/* World interaction */
if (configFile.contains("gameMode")) {
if (EnumUtil.isValidEnum(GameMode.class, configFile.getString("gameMode").toUpperCase())) {
gameMode = GameMode.valueOf(configFile.getString("gameMode"));
Expand All @@ -135,6 +134,47 @@ public void load(ConfigurationSection configFile) {
}
}

if (configFile.contains("breakBlocks")) {
breakBlocks = configFile.getBoolean("breakBlocks");
}

if (configFile.contains("breakPlacedBlocks")) {
breakPlacedBlocks = configFile.getBoolean("breakPlacedBlocks");
}

if (configFile.contains("breakWhitelist")) {
breakWhitelist = new HashMap<>();
for (Entry<String, Object> entry : configFile.getConfigurationSection("breakWhitelist").getValues(true).entrySet()) {
Material breakable = Material.matchMaterial(entry.getKey());

HashSet<Material> tools = new HashSet<>();
if (entry.getValue() instanceof List) {
for (String materialString : (List<String>) entry.getValue()) {
Material tool = Material.matchMaterial(materialString);
if (tool != null) {
tools.add(tool);
}
}
}

breakWhitelist.put(breakable, tools);
}
}

if (configFile.contains("placeBlocks")) {
placeBlocks = configFile.getBoolean("placeBlocks");
}

if (configFile.contains("placeWhitelist")) {
placeWhitelist = new HashSet<>();
for (String materialString : configFile.getStringList("placeWhitelist")) {
Material material = Material.matchMaterial(materialString);
if (material != null) {
placeWhitelist.add(material);
}
}
}

/* PvP */
if (configFile.contains("playerVersusPlayer")) {
playerVersusPlayer = configFile.getBoolean("playerVersusPlayer");
Expand Down
83 changes: 73 additions & 10 deletions core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
import io.github.dre2n.dungeonsxl.reward.Reward;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

/**
Expand All @@ -42,7 +45,11 @@ public class GameRules {

/* World interaction */
DEFAULT_VALUES.gameMode = GameMode.SURVIVAL;
DEFAULT_VALUES.build = false;
DEFAULT_VALUES.breakBlocks = false;
DEFAULT_VALUES.breakPlacedBlocks = false;
DEFAULT_VALUES.breakWhitelist = null;
DEFAULT_VALUES.placeBlocks = false;
DEFAULT_VALUES.placeWhitelist = null;

/* Fighting */
DEFAULT_VALUES.playerVersusPlayer = false;
Expand Down Expand Up @@ -81,7 +88,11 @@ public class GameRules {

/* World interaction */
protected GameMode gameMode;
protected Boolean build;
protected Boolean breakBlocks;
protected Boolean breakPlacedBlocks;
protected Map<Material, HashSet<Material>> breakWhitelist;
protected Boolean placeBlocks;
protected Set<Material> placeWhitelist;

/* Fighting */
protected Boolean playerVersusPlayer;
Expand Down Expand Up @@ -156,10 +167,38 @@ public GameMode getGameMode() {
}

/**
* @return if players may build
* @return if all blocks may be destroyed
*/
public boolean canBuild() {
return build;
public boolean canBreakBlocks() {
return breakBlocks;
}

/**
* @return if blocks placed in game may be destroyed
*/
public boolean canBreakPlacedBlocks() {
return breakPlacedBlocks;
}

/**
* @return the destroyable materials and the materials that may be used to break them or null if any
*/
public Map<Material, HashSet<Material>> getBreakWhitelist() {
return breakWhitelist;
}

/**
* @return if blocks may be placed
*/
public boolean canPlaceBlocks() {
return placeBlocks;
}

/**
* @return the placeable materials
*/
public Set<Material> getPlaceWhitelist() {
return placeWhitelist;
}

// Fight
Expand Down Expand Up @@ -353,12 +392,20 @@ public void apply(GameType defaultValues) {
friendlyFire = defaultValues.isFriendlyFire();
}

if (timeToFinish == null) {
if (timeToFinish == null && defaultValues.getShowTime() != null) {
timeToFinish = defaultValues.getShowTime() ? null : -1;
}

if (build == null) {
build = defaultValues.canBuild();
if (breakBlocks == null) {
breakBlocks = defaultValues.canBreakBlocks();
}

if (breakPlacedBlocks == null) {
breakPlacedBlocks = defaultValues.canBreakPlacedBlocks();
}

if (placeBlocks == null) {
placeBlocks = defaultValues.canPlaceBlocks();
}

if (gameMode == null) {
Expand Down Expand Up @@ -397,8 +444,24 @@ public void apply(GameRules defaultValues) {
gameMode = defaultValues.gameMode;
}

if (build == null) {
build = defaultValues.build;
if (breakBlocks == null) {
breakBlocks = defaultValues.breakBlocks;
}

if (breakPlacedBlocks == null) {
breakPlacedBlocks = defaultValues.breakPlacedBlocks;
}

if (breakWhitelist == null) {
breakWhitelist = defaultValues.breakWhitelist;
}

if (placeBlocks == null) {
placeBlocks = defaultValues.placeBlocks;
}

if (placeWhitelist == null) {
placeWhitelist = defaultValues.placeWhitelist;
}

/* Fighting */
Expand Down
56 changes: 39 additions & 17 deletions core/src/main/java/io/github/dre2n/dungeonsxl/game/GameType.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,68 +48,90 @@ public interface GameType {
/**
* @return the playerVersusPlayer
*/
public boolean isPlayerVersusPlayer();
public Boolean isPlayerVersusPlayer();

/**
* @param playerVersusPlayer
* the playerVersusPlayer to set
*/
public void setPlayerVersusPlayer(boolean playerVersusPlayer);
public void setPlayerVersusPlayer(Boolean playerVersusPlayer);

/**
* @return the friendlyFire
*/
public boolean isFriendlyFire();
public Boolean isFriendlyFire();

/**
* @param friendlyFire
* the friendlyFire to set
*/
public void setFriendlyFire(boolean friendlyFire);
public void setFriendlyFire(Boolean friendlyFire);

/**
* @return the mobWaves
*/
public boolean hasMobWaves();
public Boolean hasMobWaves();

/**
* @param mobWaves
* enable / disable mob waves
*/
public void setMobWaves(boolean mobWaves);
public void setMobWaves(Boolean mobWaves);

/**
* @return if players get rewards after the dungeon
*/
public boolean hasRewards();
public Boolean hasRewards();

/**
* @param rewards
* enable / disable rewards
*/
public void setRewards(boolean rewards);
public void setRewards(Boolean rewards);

/**
* @return if players shall see how long they play
*/
public boolean getShowTime();
public Boolean getShowTime();

/**
* @param showTime
* set if players shall see how long they play
*/
public void setShowTime(boolean showTime);
public void setShowTime(Boolean showTime);

/**
* @return if players can build
* @return if all blocks may be destroyed
*/
public boolean canBuild();
public Boolean canBreakBlocks();

/**
* @param build
* enable / disable building
* @param breakBlocks
* if blocks may be destroyed
*/
public void setBuild(boolean build);
public void setBreakBlocks(Boolean breakBlocks);

/**
* @return if blocks placed in game may be destroyed
*/
public Boolean canBreakPlacedBlocks();

/**
* @param breakPlacedBlocks
* if placed blocks may be destroyed
*/
public void setBreakPlacedBlocks(Boolean breakPlacedBlocks);

/**
* @return if blocks may be placed
*/
public Boolean canPlaceBlocks();

/**
* @param placeBlocks
* if blocks may be placed
*/
public void setPlaceBlocks(Boolean placeBlocks);

/**
* @return the gameMode
Expand All @@ -125,12 +147,12 @@ public interface GameType {
/**
* @return if players lose lives
*/
public boolean hasLives();
public Boolean hasLives();

/**
* @param lives
* set if the gametype uses player lives
*/
public void setLives(boolean lives);
public void setLives(Boolean lives);

}
Loading

0 comments on commit 514a3f1

Please sign in to comment.