Skip to content
Permalink
Browse files

Create a config file and a config class.

  • Loading branch information...
bmhm committed Apr 7, 2016
1 parent 26edbaf commit a6964a54c8de08f126ec97e87d0373e002e3f421
Showing with 71 additions and 0 deletions.
  1. +61 −0 src/main/java/de/bmarwell/bukkit/ExamplePluginConfig.java
  2. +10 −0 src/main/resources/config.yml
@@ -0,0 +1,61 @@
package de.bmarwell.bukkit;

import com.google.common.base.Enums;
import com.google.common.base.Optional;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.logging.Logger;

public class ExamplePluginConfig {

private final Logger logger;
private FileConfiguration config;
private final JavaPlugin plugin;

private Optional<TeleportCause> teleportCauseToCancel = null;

/**
* Creates a Plugin config for this plugin.
*
* @param plugin
* enter <i>this</i> from your main class.
*/
public ExamplePluginConfig(final JavaPlugin plugin) {
this.plugin = plugin;
this.config = plugin.getConfig();
this.logger = plugin.getLogger();

reloadConfig();
}

/**
* Force reload the config.
*/
public void reloadConfig() {
plugin.reloadConfig();
this.config = plugin.getConfig();

String cancelCause = config.getRoot().getString("cancel.cause");
this.teleportCauseToCancel = Enums.getIfPresent(TeleportCause.class, cancelCause);
}

public Logger getLogger() {
return logger;
}

public FileConfiguration getConfig() {
return config;
}

public JavaPlugin getPlugin() {
return plugin;
}

public Optional<TeleportCause> getTeleportCauseToCancel() {
return teleportCauseToCancel;
}

}
@@ -0,0 +1,10 @@

cancel:
# Choose which teleport to stop. Possible values:
# - ENDER_PEARL (throwing an ender pearl).
# - PLUGIN (caused by a plugin).
# - COMMAND (like /tp or others).
# - SPECTATE (disables spectator functionality).
# - UNKNOWN (disables teleports with unknown causes).
# Note: Any other value will disable the functionality.
cause: ENDER_PEARL

0 comments on commit a6964a5

Please sign in to comment.
You can’t perform that action at this time.