Skip to content

Commit

Permalink
It now runs
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Aug 13, 2018
1 parent 2e8d14c commit b10cf6a
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 16 deletions.
Expand Up @@ -40,7 +40,11 @@ public static WorldGuard getInstance() {
return instance;
}

public WorldGuard() {
private WorldGuard() {
}

public void setup() {
getPlatform().load();
Flags.registerAll();
}

Expand Down
Expand Up @@ -27,8 +27,8 @@

public abstract class YamlWorldConfiguration extends WorldConfiguration {

@Unreported private YAMLProcessor parentConfig;
@Unreported private YAMLProcessor config;
@Unreported protected YAMLProcessor parentConfig;
@Unreported protected YAMLProcessor config;

public boolean getBoolean(String node, boolean def) {
boolean val = parentConfig.getBoolean(node, def);
Expand Down
Expand Up @@ -96,6 +96,11 @@ public interface WorldGuardPlatform {
*/
void broadcastNotification(String message);

/**
* Load the platform
*/
void load();

/**
* Unload the platform
*/
Expand Down
Expand Up @@ -43,6 +43,7 @@ public class BukkitConfigurationManager extends YamlConfigurationManager {
*/
public BukkitConfigurationManager(WorldGuardPlugin plugin) {
super();
this.plugin = plugin;
}

@Override
Expand Down
Expand Up @@ -66,8 +66,6 @@ public class BukkitWorldConfiguration extends YamlWorldConfiguration {
@Unreported private WorldGuardPlugin plugin;

@Unreported private String worldName;
@Unreported private YAMLProcessor parentConfig;
@Unreported private YAMLProcessor config;

@Unreported private ChestProtection chestProtection = new SignChestProtection();

Expand Down
Expand Up @@ -42,14 +42,10 @@
public class BukkitWorldGuardPlatform implements WorldGuardPlatform {

private SessionManager sessionManager;
private final BukkitConfigurationManager configuration;
private final BukkitRegionContainer regionContainer;
private BukkitConfigurationManager configuration;
private BukkitRegionContainer regionContainer;

public BukkitWorldGuardPlatform() {
sessionManager = new BukkitSessionManager(WorldGuardPlugin.inst());
configuration = new BukkitConfigurationManager(WorldGuardPlugin.inst());
regionContainer = new BukkitRegionContainer(WorldGuardPlugin.inst());
regionContainer.initialize();
}

@Override
Expand Down Expand Up @@ -108,6 +104,15 @@ public void broadcastNotification(String message) {
WorldGuard.logger.info(message);
}

@Override
public void load() {
sessionManager = new BukkitSessionManager(WorldGuardPlugin.inst());
configuration = new BukkitConfigurationManager(WorldGuardPlugin.inst());
configuration.load();
regionContainer = new BukkitRegionContainer(WorldGuardPlugin.inst());
regionContainer.initialize();
}

@Override
public void unload() {
configuration.unload();
Expand Down
Expand Up @@ -126,7 +126,7 @@ public class WorldGuardPlugin extends JavaPlugin {
private static WorldGuardPlugin inst;
private static BukkitWorldGuardPlatform platform;
private final CommandsManager<CommandSender> commands;
private final GlobalRegionManager globalRegionManager = new GlobalRegionManager((BukkitRegionContainer) WorldGuard.getInstance().getPlatform().getRegionContainer());
private GlobalRegionManager globalRegionManager;
private final Supervisor supervisor = new SimpleSupervisor();
private ListeningExecutorService executorService;
private ProfileService profileService;
Expand Down Expand Up @@ -168,7 +168,9 @@ public void onEnable() {
executorService = MoreExecutors.listeningDecorator(EvenMoreExecutors.newBoundedCachedThreadPool(0, 1, 20));

WorldGuard.getInstance().setPlatform(platform = new BukkitWorldGuardPlatform()); // Initialise WorldGuard
WorldGuard.getInstance().setup();
BukkitSessionManager sessionManager = (BukkitSessionManager) platform.getSessionManager();
globalRegionManager = new GlobalRegionManager(WorldGuard.getInstance().getPlatform().getRegionContainer());

// Set the proper command injector
commands.setInjector(new SimpleInjector(this));
Expand Down
Expand Up @@ -106,16 +106,16 @@ public void onBreakBlock(final BreakBlockEvent event) {
@EventHandler(ignoreCancelled = true)
public void onUseBlock(final UseBlockEvent event) {
final Player player = event.getCause().getFirstPlayer();
final LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);

final BukkitWorldConfiguration wcfg = getWorldConfig(localPlayer);
final BukkitWorldConfiguration wcfg = getWorldConfig(BukkitAdapter.adapt(event.getWorld()));

// Early guard
if (!wcfg.signChestProtection) {
return;
}

if (player != null) {
final LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
event.filter(target -> {
if (wcfg.isChestProtected(BukkitAdapter.adapt(target.getBlock().getLocation()), localPlayer)) {
sendMessage(event, player, ChatColor.DARK_RED + "This chest is protected.");
Expand Down
Expand Up @@ -80,9 +80,10 @@ public void onPlayerMove(PlayerMoveEvent event) {
LocalPlayer localPlayer = plugin.wrapPlayer(player);

Session session = WorldGuard.getInstance().getPlatform().getSessionManager().get(localPlayer);
final Location override = BukkitAdapter.adapt(session.testMoveTo(localPlayer, BukkitAdapter.adapt(event.getTo()), MoveType.MOVE));
com.sk89q.worldedit.util.Location weLocation = session.testMoveTo(localPlayer, BukkitAdapter.adapt(event.getTo()), MoveType.MOVE);

if (override != null) {
if (weLocation != null) {
final Location override = BukkitAdapter.adapt(weLocation);
override.setX(override.getBlockX() + 0.5);
override.setY(override.getBlockY());
override.setZ(override.getBlockZ() + 0.5);
Expand Down

0 comments on commit b10cf6a

Please sign in to comment.