Skip to content

Commit

Permalink
Merge pull request #9 from BitLimit/preferences-redux
Browse files Browse the repository at this point in the history
Preferences Redux + Multi-world support
  • Loading branch information
kolinkrewinkel committed Jan 14, 2014
2 parents abbf97c + 6d24ad5 commit 7d78c5d
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 41 deletions.
28 changes: 28 additions & 0 deletions Tweaks.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.6.2-R1.0" level="project" />
<orderEntry type="library" name="Maven: com.sk89q:worldguard:5.6.6-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.sk89q:worldedit:5.4.4" level="project" />
<orderEntry type="library" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" name="Maven: rhino:js:1.7R2" level="project" />
<orderEntry type="library" name="Maven: com.sk89q:jchronic:0.2.4a" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.8.1" level="project" />
<orderEntry type="library" name="Maven: com.sk89q:commandbook:2.1" level="project" />
<orderEntry type="library" name="Maven: net.sf.opencsv:opencsv:2.0" level="project" />
<orderEntry type="library" name="Maven: com.nijikokun:iconomy:5.0" level="project" />
<orderEntry type="library" name="Maven: org.khelekore:prtree:1.5.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:10.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
</component>
</module>

33 changes: 23 additions & 10 deletions src/main/java/com/bitlimit/Tweaks/Tweaks.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.bitlimit.Tweaks;

import com.sk89q.worldedit.bukkit.BukkitBiomeType;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;

import java.util.HashMap;
import java.util.List;

public class Tweaks extends JavaPlugin {
private int weatherId;

Expand All @@ -29,13 +34,16 @@ public void saveConfig() {

this.getConfig().options().copyDefaults(true);
this.reloadConfig();
setRepeatingTaskEnabled(this.getConfig().getConfigurationSection("preferences").getBoolean("weather"));
setRepeatingTaskEnabled(this.getConfig().getConfigurationSection("weather").getBoolean("enabled"));
}

public void setRepeatingTaskEnabled(boolean enabled) {
Server server = this.getServer();
BukkitScheduler scheduler = server.getScheduler();
if (enabled && this.weatherId == 0) {
final long baseDuration = 1200L;

if (enabled && this.weatherId == 0)
{
class BitLimitRecurringTask implements Runnable {
Plugin plugin;

Expand All @@ -44,18 +52,23 @@ class BitLimitRecurringTask implements Runnable {
}

public void run() {
World world = this.plugin.getServer().getWorld(plugin.getConfig().getConfigurationSection("meta").getConfigurationSection("weather").getString("world"));
for (HashMap<String, Object> worldDefinition : (List<HashMap<String, Object>>)this.plugin.getConfig().getConfigurationSection("weather").getList("worlds"))
{
String worldName = (String)worldDefinition.get("name");
World world = this.plugin.getServer().getWorld(worldName);

if (!world.hasStorm()) {
int weatherDuration = world.getWeatherDuration();
double ratio = 0.75; // 75% less often.
int calculatedAddback = (int)(1200 * ratio);
world.setWeatherDuration(weatherDuration + calculatedAddback);
}
if (!world.hasStorm())
{
int weatherDuration = world.getWeatherDuration();
Double ratio = (Double)worldDefinition.get("reduction");
int counterAmount = (int)(baseDuration * ratio);
world.setWeatherDuration(weatherDuration + counterAmount);
}
}
}
}

this.weatherId = scheduler.scheduleSyncRepeatingTask(this, new BitLimitRecurringTask(this), 1200L, 1200L);
this.weatherId = scheduler.scheduleSyncRepeatingTask(this, new BitLimitRecurringTask(this), baseDuration, baseDuration);
} else if (this.weatherId != 0) {
scheduler.cancelTask(this.weatherId);
this.weatherId = 0;
Expand Down
49 changes: 33 additions & 16 deletions src/main/java/com/bitlimit/Tweaks/TweaksCommandExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,32 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return false;
}
boolean newValue = parsedBooleanInput(args[1]);
ConfigurationSection configurationSection = config.getConfigurationSection("preferences");

if (args[0].toLowerCase().equals("tnt")) {
configurationSection.set("tnt", newValue);
} else if (args[0].toLowerCase().equals("weather")) {
configurationSection.set("weather", newValue);
} else if (args[0].toLowerCase().equals("slimes")) {
configurationSection.set("slimes", newValue);
} else if (args[0].toLowerCase().equals("spawnitems")) {
String modified = args[0].toLowerCase();

if (modified.equals("tnt") || modified.equals("weather") || modified.equals("slimes"))
{
config.getConfigurationSection(modified).set("enabled", newValue);
}
else if (args[0].toLowerCase().equals("spawnitems"))
{
if (args[1].toLowerCase().equals("location")) {

try {
ConfigurationSection section = config.getConfigurationSection("meta").createSection("spawnItems").createSection("location");

if (sender instanceof Player) {
ConfigurationSection section = null;
ConfigurationSection spawnItemsSection = config.getConfigurationSection("spawnItems");

if (spawnItemsSection.contains("location"))
{
section = spawnItemsSection.getConfigurationSection("location");
}
else
{
section = spawnItemsSection.createSection("location");
}

if (sender instanceof Player)
{
Player player = (Player)sender;
this.putLocationInSection(player.getLocation(), section);
sender.sendMessage(ChatColor.GREEN + "Location set successfully.");
Expand All @@ -63,7 +73,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

} else {
configurationSection.set("spawnItems", newValue);
config.getConfigurationSection("spawnItems").set("enabled", newValue);
}
} else {
sender.sendMessage(ChatColor.RED + "Invalid parameter. Expected TNT, weather, or slimes.");
Expand All @@ -79,14 +89,21 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
String newValueString = newValue ? "enabled" : "disabled";
sender.sendMessage(ChatColor.AQUA + argument + " tweaks are now " + ChatColor.GOLD + newValueString +ChatColor.AQUA + ".");
} else if (args.length == 1) {
String argument = args[0].toLowerCase();
if (argument.equals("tnt") || argument.equals("weather") || argument.equals("slimes") || argument.equals("spawnItems")) {
boolean enabled = config.getBoolean("enabled-" + argument);
String argument = args[0];
if (argument.equals("tnt") || argument.equals("weather") || argument.equals("slimes") || argument.equals("spawnItems"))
{
boolean enabled = config.getConfigurationSection(argument).getBoolean("enabled");
if (argument.equals("tnt")) {
argument = "TNT";
} else {
}
else if (argument.equals("spawnItems"))
{
argument = "Item-spawning";
}
else {
argument = capitalizedString(argument);
}

if (enabled) {
sender.sendMessage(ChatColor.AQUA + argument + ChatColor.GREEN + " tweaks are currently enabled.");
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/bitlimit/Tweaks/TweaksListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void onCreatureSpawnEvent(CreatureSpawnEvent event) {
// CreatureSpawnEvent (Entity spawnee, CreatureType type, Location loc, SpawnReason reason

FileConfiguration config = this.plugin.getConfig();
if (!config.getConfigurationSection("preferences").getBoolean("slimes"))
if (!config.getConfigurationSection("slimes").getBoolean("enabled"))
return;

// Gather information to determine if these are the slimes we are looking for.
Expand All @@ -79,7 +79,7 @@ public void onBlockPlaceEvent(BlockPlaceEvent event) {
// Event reference
// BlockPlaceEvent(Block placedBlock, BlockState replacedBlockState, Block placedAgainst, ItemStack itemInHand, Player thePlayer, boolean canBuild)

boolean confinementEnabled = this.plugin.getConfig().getConfigurationSection("preferences").getBoolean("tnt");
boolean confinementEnabled = this.plugin.getConfig().getConfigurationSection("tnt").getBoolean("enabled");

if (event.getItemInHand().getType() == Material.TNT && confinementEnabled) {
WorldGuardPlugin worldGuard = getWorldGuard();
Expand Down Expand Up @@ -561,10 +561,10 @@ public void onExplosionEvent(EntityExplodeEvent event)
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerJoinEvent(PlayerJoinEvent event) {
if (!event.getPlayer().hasPlayedBefore()) {
if (!this.plugin.getConfig().getConfigurationSection("preferences").getBoolean("spawnItems"))
if (!this.plugin.getConfig().getConfigurationSection("spawnItems").getBoolean("enabled"))
return;

Location location = this.parseLocation(this.plugin.getConfig().getConfigurationSection("meta").getConfigurationSection("spawnItems").getConfigurationSection("location"));
Location location = this.parseLocation(this.plugin.getConfig().getConfigurationSection("spawnItems").getConfigurationSection("location"));
Block block = location.getWorld().getBlockAt(location);

if (block.getType() == Material.CHEST) {
Expand Down
22 changes: 14 additions & 8 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
tnt:
enabled: true

preferences:
tnt: true
weather: true
slimes: true
spawnItems: false
meta:
weather:
world: world
weather:
enabled: true
worlds:
-
name : world
reduction: 0.75

slimes:
enabled: true

spawnItems:
enabled: false
6 changes: 3 additions & 3 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
main: com.bitlimit.Tweaks.Tweaks
name: Tweaks
version: 1.6.3
version: 1.6.4
author: Kolin Krewinkel & BitLimit Team
description: Code-level runtime tweaks for BitLimit Private Survival.
description: Gameplay tweaks for BitLimit Private Survival.
website: http://github.com/BitLimit/Tweaks/
commands:
tweaks:
description: /tweaks [tnt|slimes|weather] [state] to set the state or omit the state to return the current config status.
description: /tweaks [tnt|slimes|weather|spawnItems] [state] to set the state or omit the state to return the current config status.
permissions:
tweaks.*:
description: Gives all permissions of BitLimit Tweaks plugin toggling.
Expand Down

0 comments on commit 7d78c5d

Please sign in to comment.