2013-01-16 11:33:14 +00:00
|
|
|
package de.jaschastarke.minecraft.limitedcreative;
|
|
|
|
|
2013-02-09 19:09:57 +00:00
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
|
|
|
|
2013-01-16 11:33:14 +00:00
|
|
|
import de.jaschastarke.bukkit.lib.CoreModule;
|
2013-02-09 19:09:57 +00:00
|
|
|
import de.jaschastarke.bukkit.lib.commands.AliasHelpedCommand;
|
2013-02-10 21:12:31 +00:00
|
|
|
import de.jaschastarke.minecraft.limitedcreative.regions.BlockListener;
|
2013-02-09 19:09:57 +00:00
|
|
|
import de.jaschastarke.minecraft.limitedcreative.regions.Flags;
|
|
|
|
import de.jaschastarke.minecraft.limitedcreative.regions.PlayerData;
|
2013-02-10 21:12:31 +00:00
|
|
|
import de.jaschastarke.minecraft.limitedcreative.regions.PlayerListener;
|
2013-02-09 19:09:57 +00:00
|
|
|
import de.jaschastarke.minecraft.limitedcreative.regions.RegionConfig;
|
2013-02-10 21:12:31 +00:00
|
|
|
import de.jaschastarke.minecraft.limitedcreative.regions.RegionListener;
|
2013-02-09 19:09:57 +00:00
|
|
|
import de.jaschastarke.minecraft.limitedcreative.regions.RegionsCommand;
|
|
|
|
import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.CustomRegionManager;
|
|
|
|
import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.FlagList;
|
2013-02-10 21:12:31 +00:00
|
|
|
import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.PlayerRegionListener;
|
2013-02-09 19:09:57 +00:00
|
|
|
import de.jaschastarke.modularize.IModule;
|
|
|
|
import de.jaschastarke.modularize.ModuleEntry;
|
|
|
|
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
|
2013-01-16 11:33:14 +00:00
|
|
|
|
2013-01-18 21:51:08 +00:00
|
|
|
public class ModRegions extends CoreModule<LimitedCreative> {
|
2013-02-09 19:09:57 +00:00
|
|
|
private CustomRegionManager mgr;
|
|
|
|
private WorldGuardPlugin wg;
|
|
|
|
private PlayerData pdata;
|
|
|
|
private FeatureBlockItemSpawn blockDrops = null;
|
|
|
|
private RegionConfig config;
|
|
|
|
private RegionsCommand command;
|
|
|
|
|
2013-01-18 21:51:08 +00:00
|
|
|
public ModRegions(LimitedCreative plugin) {
|
2013-01-16 11:33:14 +00:00
|
|
|
super(plugin);
|
|
|
|
}
|
2013-03-25 16:51:01 +00:00
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return "Regions";
|
|
|
|
}
|
2013-02-09 19:09:57 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initialize(ModuleEntry<IModule> pEntry) {
|
|
|
|
super.initialize(pEntry);
|
|
|
|
|
|
|
|
blockDrops = plugin.getModule(FeatureBlockItemSpawn.class);
|
|
|
|
if (blockDrops == null)
|
|
|
|
blockDrops = plugin.addModule(new FeatureBlockItemSpawn(plugin)).getModule();
|
|
|
|
|
|
|
|
config = plugin.getPluginConfig().registerSection(new RegionConfig(this, entry));
|
|
|
|
|
2013-03-25 16:51:01 +00:00
|
|
|
if (!plugin.getServer().getPluginManager().isPluginEnabled("WorldGuard")) {
|
|
|
|
if (config.getEnabled())
|
|
|
|
getLog().warn(plugin.getLocale().trans("region.warning.worldguard_not_found", getName()));
|
|
|
|
entry.initialState = ModuleState.NOT_INITIALIZED;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-09 19:09:57 +00:00
|
|
|
command = new RegionsCommand(this);
|
2013-02-10 21:12:31 +00:00
|
|
|
|
2013-03-23 16:59:14 +00:00
|
|
|
listeners.addListener(new PlayerListener(this));
|
|
|
|
listeners.addListener(new BlockListener(this));
|
|
|
|
listeners.addListener(new RegionListener(this));
|
|
|
|
listeners.addListener(new PlayerRegionListener(this)); // Fires Custom-Events listen by RegionListener
|
2013-02-09 19:09:57 +00:00
|
|
|
|
|
|
|
FlagList.addFlags(Flags.getList());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
|
|
|
super.onEnable();
|
|
|
|
|
|
|
|
mgr = new CustomRegionManager(new File(plugin.getDataFolder(), "regions.yml"), this);
|
|
|
|
wg = (WorldGuardPlugin) plugin.getServer().getPluginManager().getPlugin("WorldGuard");
|
2013-03-20 16:11:32 +00:00
|
|
|
if (wg == null)
|
|
|
|
throw new IllegalAccessError("Missing Plugin WorldGuard");
|
|
|
|
|
|
|
|
plugin.getCommandHandler().registerCommand(command);
|
|
|
|
plugin.getMainCommand().registerCommand(new AliasHelpedCommand<RegionsCommand>(command, "region", new String[]{"r"}));
|
|
|
|
|
2013-02-09 19:09:57 +00:00
|
|
|
pdata = new PlayerData(this);
|
|
|
|
getLog().info(plugin.getLocale().trans("basic.loaded.module"));
|
|
|
|
}
|
|
|
|
|
2013-03-20 16:11:32 +00:00
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
|
|
|
super.onDisable();
|
|
|
|
|
|
|
|
plugin.getCommandHandler().removeCommand(command);
|
|
|
|
plugin.getMainCommand().removeCommand(command);
|
|
|
|
}
|
|
|
|
|
2013-02-09 19:09:57 +00:00
|
|
|
public RegionConfig getConfig() {
|
|
|
|
return config;
|
|
|
|
}
|
2013-01-16 11:33:14 +00:00
|
|
|
|
2013-02-09 19:09:57 +00:00
|
|
|
public WorldGuardPlugin getWorldGuard() {
|
|
|
|
return wg;
|
|
|
|
}
|
|
|
|
public CustomRegionManager getRegionManager() {
|
|
|
|
return mgr;
|
|
|
|
}
|
|
|
|
public PlayerData getPlayerData() {
|
|
|
|
return pdata;
|
|
|
|
}
|
|
|
|
public PlayerData.Data getPlayerData(Player player) {
|
|
|
|
return pdata.getData(player);
|
|
|
|
}
|
|
|
|
public FeatureBlockItemSpawn getBlockSpawn() {
|
|
|
|
return blockDrops;
|
|
|
|
}
|
2013-01-16 11:33:14 +00:00
|
|
|
}
|