Skip to content

Commit

Permalink
Configurable player interaction protection
Browse files Browse the repository at this point in the history
  • Loading branch information
gdude2002 committed Apr 1, 2015
1 parent fd6043b commit 9dbc8fc
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 82 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/archivesmc/archblock/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import java.util.List;

/**
* The main plugin class for ArchBlock.
*/
Expand Down Expand Up @@ -202,4 +204,8 @@ public synchronized boolean isTaskRunning() {
public synchronized void setTaskRunning(boolean taskRunning) {
this.taskRunning = taskRunning;
}

public List<String> getInteractProtected() {
return this.mainConfig.getInteractProtected();
}
}
183 changes: 102 additions & 81 deletions src/main/java/com/archivesmc/archblock/config/MainConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.archivesmc.archblock.Plugin;
import org.bukkit.configuration.file.FileConfiguration;

import java.util.List;

/**
* The main configuration class, which handles abstraction of the plugin's configuration,
* and automatically upgrades old configuration files when the plugin is updated.
Expand Down Expand Up @@ -37,6 +39,19 @@ public void reload() {
this.reload();
break;
case "0.0.3": // Don't do the update for now, since these are non-functional
this.configuration.set("protect_interact", new String[] {
"ANVIL", "BEACON", "BED", "BED_BLOCK", "BREWING_STAND",
"BURNING_FURNACE", "CAKE", "CAKE_BLOCK", "CAULDRON", "CHEST",
"COMMAND", "CROPS", "DAYLIGHT_DETECTOR", "DIODE", "DIODE_BLOCK_OFF",
"DIODE_BLOCK_ON", "DISPENSER", "DRAGON_EGG", "DROPPER", "ENCHANTMENT_TABLE",
"ENDER_CHEST", "FENCE_GATE", "FLOWER_POT", "FURNACE", "GLOWING_REDSTONE_ORE",
"GOLD_PLATE", "HOPPER", "IRON_DOOR", "IRON_DOOR_BLOCK", "IRON_PLATE", "JUKEBOX",
"MOB_SPAWNER", "NETHER_STALK", "NETHER_WARTS", "NOTE_BLOCK", "REDSTONE_COMPARATOR",
"REDSTONE_COMPARATOR_OFF", "REDSTONE_COMPARATOR_ON", "REDSTONE_ORE", "SIGN",
"SIGN_POST", "SKULL", "STONE_BUTTON", "STONE_PLATE", "TNT", "TRAP_DOOR",
"TRAPPED_CHEST", "WALL_SIGN", "WOOD_BUTTON", "WOOD_DOOR", "WOOD_PLATE",
"WOODEN_DOOR", "WORKBENCH"
});
// this.configuration.set("special_permissions.prevent_burning", false);
// this.configuration.set("special_permissions.prevent_damage", true);
// this.configuration.set("special_permissions.prevent_fade", true);
Expand All @@ -56,13 +71,12 @@ public void reload() {
// this.configuration.set("special_permissions.prevent_player_bucket_empty", true);
// this.configuration.set("special_permissions.prevent_player_bucket_fill", true);
// this.configuration.set("special_permissions.prevent_vehicle_create", true);
// this.configuration.set("version", "0.1.0");
// this.plugin.saveConfig();
// this.plugin.getLogger().info("Updated config to version 0.1.0");
// this.plugin.getLogger().info("You may want to check out all the extra options!");
// this.reload();
this.configuration.set("version", "0.1.0b1");
this.plugin.saveConfig();
this.plugin.getLogger().info("Updated config to version 0.1.0b1");
this.reload();
break;
case "0.1.0": // Latest version
case "0.1.0b1": // Latest version
break;
default:
this.plugin.getLogger().warning(
Expand Down Expand Up @@ -138,79 +152,86 @@ public boolean getMigrate() {
return this.configuration.getBoolean("migrate", true);
}

public boolean getSpecialPreventBurning() {
return this.configuration.getBoolean("special_protections.prevent_burning");
}

public boolean getSpecialPreventDamage() {
return this.configuration.getBoolean("special_protections.prevent_damage");
}

public boolean getSpecialPreventFade() {
return this.configuration.getBoolean("special_protections.prevent_fade");
}

public boolean getSpecialPreventForm() {
return this.configuration.getBoolean("special_protections.prevent_form");
}

public boolean getSpecialPreventLiquidFlow() {
return this.configuration.getBoolean("special_protections.prevent_liquid_flow");
}

public boolean getSpecialPreventDragonEggTeleport() {
return this.configuration.getBoolean("special_protections.prevent_dragon_egg_teleport");
}

public boolean getSpecialPreventGrowth() {
return this.configuration.getBoolean("special_protections.prevent_growth");
}

public boolean getSpecialPreventIgnite() {
return this.configuration.getBoolean("special_protections.prevent_ignite");
}

public boolean getSpecialPreventPhysics() {
return this.configuration.getBoolean("special_protections.prevent_physics");
}

public boolean getSpecialPreventLeafDecay() {
return this.configuration.getBoolean("special_protections.prevent_leaf_decay");
}

public boolean getSpecialPreventSignChange() {
return this.configuration.getBoolean("special_protections.prevent_sign_change");
}

public boolean getSpecialPreventEntityExplode() {
return this.configuration.getBoolean("special_protections.prevent_entity_explode");
}

public boolean getSpecialPreventHangingBreak() {
return this.configuration.getBoolean("special_protections.prevent_hanging_break");
}

public boolean getSpecialPreventHangingBreakByEntity() {
return this.configuration.getBoolean("special_protections.prevent_hanging_break_by_entity");
}

public boolean getSpecialPreventHangingPlace() {
return this.configuration.getBoolean("special_protections.prevent_hanging_place");
}

public boolean getSpecialPreventLightningStrike() {
return this.configuration.getBoolean("special_protections.prevent_lightning_strike");
}

public boolean getSpecialPreventBucketEmpty() {
return this.configuration.getBoolean("special_protections.prevent_player_bucket_empty");
}

public boolean getSpecialPreventBucketFill() {
return this.configuration.getBoolean("special_protections.prevent_player_bucket_fill");
}

public boolean getSpecialPreventVehicleCreate() {
return this.configuration.getBoolean("special_protections.prevent_vehicle_create");
}
/**
* @return An array of material IDs that should be protected against interactions
*/
public List<String> getInteractProtected() {
return this.configuration.getStringList("protect_interact");
}

// public boolean getSpecialPreventBurning() {
// return this.configuration.getBoolean("special_protections.prevent_burning");
// }
//
// public boolean getSpecialPreventDamage() {
// return this.configuration.getBoolean("special_protections.prevent_damage");
// }
//
// public boolean getSpecialPreventFade() {
// return this.configuration.getBoolean("special_protections.prevent_fade");
// }
//
// public boolean getSpecialPreventForm() {
// return this.configuration.getBoolean("special_protections.prevent_form");
// }
//
// public boolean getSpecialPreventLiquidFlow() {
// return this.configuration.getBoolean("special_protections.prevent_liquid_flow");
// }
//
// public boolean getSpecialPreventDragonEggTeleport() {
// return this.configuration.getBoolean("special_protections.prevent_dragon_egg_teleport");
// }
//
// public boolean getSpecialPreventGrowth() {
// return this.configuration.getBoolean("special_protections.prevent_growth");
// }
//
// public boolean getSpecialPreventIgnite() {
// return this.configuration.getBoolean("special_protections.prevent_ignite");
// }
//
// public boolean getSpecialPreventPhysics() {
// return this.configuration.getBoolean("special_protections.prevent_physics");
// }
//
// public boolean getSpecialPreventLeafDecay() {
// return this.configuration.getBoolean("special_protections.prevent_leaf_decay");
// }
//
// public boolean getSpecialPreventSignChange() {
// return this.configuration.getBoolean("special_protections.prevent_sign_change");
// }
//
// public boolean getSpecialPreventEntityExplode() {
// return this.configuration.getBoolean("special_protections.prevent_entity_explode");
// }
//
// public boolean getSpecialPreventHangingBreak() {
// return this.configuration.getBoolean("special_protections.prevent_hanging_break");
// }
//
// public boolean getSpecialPreventHangingBreakByEntity() {
// return this.configuration.getBoolean("special_protections.prevent_hanging_break_by_entity");
// }
//
// public boolean getSpecialPreventHangingPlace() {
// return this.configuration.getBoolean("special_protections.prevent_hanging_place");
// }
//
// public boolean getSpecialPreventLightningStrike() {
// return this.configuration.getBoolean("special_protections.prevent_lightning_strike");
// }
//
// public boolean getSpecialPreventBucketEmpty() {
// return this.configuration.getBoolean("special_protections.prevent_player_bucket_empty");
// }
//
// public boolean getSpecialPreventBucketFill() {
// return this.configuration.getBoolean("special_protections.prevent_player_bucket_fill");
// }
//
// public boolean getSpecialPreventVehicleCreate() {
// return this.configuration.getBoolean("special_protections.prevent_vehicle_create");
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ public void onEvent(org.bukkit.event.player.PlayerInteractEvent event) {

event.setCancelled(true);
}
} else {
if (this.plugin.getInteractProtected().contains(event.getClickedBlock().getType().toString())) {
if (!this.plugin.getApi().canEditBlock(event.getClickedBlock(), event.getPlayer())) {
event.getPlayer().sendMessage(String.format(
"%s[%sArchBlock%s]%s You may not interact with any %s%s%s owned by %s%s%s.",
ChatColor.LIGHT_PURPLE, ChatColor.GOLD, ChatColor.LIGHT_PURPLE,
ChatColor.RED, ChatColor.AQUA, event.getClickedBlock().getType().toString(),
ChatColor.RED, ChatColor.AQUA,
this.plugin.getApi().getUsernameForUuid(this.plugin.getApi().getOwnerUUID(event.getClickedBlock())),
ChatColor.RED
));

event.setCancelled(true);
}
}
}
}
}
59 changes: 58 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,62 @@ db_config:
# if you haven't done so already.
migrate: false

protect_interact:
# This is a list of blocks to prevent players from interacting with
# if they aren't allowed to edit them (For example, right-clicking note blocks)
- ANVIL
- BEACON
- BED
- BED_BLOCK
- BREWING_STAND
- BURNING_FURNACE
- CAKE
- CAKE_BLOCK
- CAULDRON
- CHEST
- COMMAND
- CROPS
- DAYLIGHT_DETECTOR
- DIODE
- DIODE_BLOCK_OFF
- DIODE_BLOCK_ON
- DISPENSER
- DRAGON_EGG
- DROPPER
- ENCHANTMENT_TABLE
- ENDER_CHEST
- FENCE_GATE
- FLOWER_POT
- FURNACE
- GLOWING_REDSTONE_ORE
- GOLD_PLATE
- HOPPER
- IRON_DOOR
- IRON_DOOR_BLOCK
- IRON_PLATE
- JUKEBOX
- MOB_SPAWNER
- NETHER_STALK
- NETHER_WARTS
- NOTE_BLOCK
- REDSTONE_COMPARATOR
- REDSTONE_COMPARATOR_OFF
- REDSTONE_COMPARATOR_ON
- REDSTONE_ORE
- SIGN
- SIGN_POST
- SKULL
- STONE_BUTTON
- STONE_PLATE
- TNT
- TRAP_DOOR
- TRAPPED_CHEST
- WALL_SIGN
- WOOD_BUTTON
- WOOD_DOOR
- WOOD_PLATE
- WOODEN_DOOR
- WORKBENCH

# Don't edit this - you'll break your configuration.
version: "0.0.3"
version: "0.1.0b"

0 comments on commit 9dbc8fc

Please # to comment.