Skip to content

Commit

Permalink
Add LWC integration; resolves #393
Browse files Browse the repository at this point in the history
  • Loading branch information
Sataniel98 committed Jun 8, 2018
1 parent d165467 commit 2438149
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
<version>2.6.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.griefcraft</groupId>
<artifactId>entitylwc</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/de/erethon/dungeonsxl/global/GameSign.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package de.erethon.dungeonsxl.global;

import com.griefcraft.lwc.LWC;
import com.griefcraft.model.Protection;
import de.erethon.caliburn.category.Category;
import de.erethon.caliburn.item.VanillaItem;
import de.erethon.commons.chat.MessageUtil;
Expand All @@ -24,6 +26,7 @@
import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.game.Game;
import de.erethon.dungeonsxl.player.DGroup;
import de.erethon.dungeonsxl.util.LWCUtil;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand Down Expand Up @@ -232,6 +235,8 @@ public static GameSign tryToCreate(Block startSign, String identifier, int maxGr
}
GameSign sign = new GameSign(DungeonsXL.getInstance().getGlobalProtections().generateId(GameSign.class, world), startSign, identifier, maxGroupsPerGame);

LWCUtil.removeProtection(startSign);

return sign;
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/de/erethon/dungeonsxl/global/GroupSign.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DGroup;
import de.erethon.dungeonsxl.util.LWCUtil;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand Down Expand Up @@ -217,6 +218,8 @@ public static GroupSign tryToCreate(Block startSign, String identifier, int maxP
}
GroupSign sign = new GroupSign(DungeonsXL.getInstance().getGlobalProtections().generateId(GroupSign.class, world), startSign, identifier, maxPlayersPerGroup, groupName);

LWCUtil.removeProtection(startSign);

return sign;
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/de/erethon/dungeonsxl/global/LeaveSign.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DGamePlayer;
import de.erethon.dungeonsxl.player.DGroup;
import de.erethon.dungeonsxl.util.LWCUtil;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.ChatColor;
Expand All @@ -47,6 +48,8 @@ public LeaveSign(int id, Sign sign) {

this.sign = sign;
setText();

LWCUtil.removeProtection(sign.getBlock());
}

/* Getters and setters */
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/de/erethon/dungeonsxl/util/LWCUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package de.erethon.dungeonsxl.util;

import com.griefcraft.lwc.LWC;
import com.griefcraft.model.Protection;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;

/**
* @author Daniel Saukel
*/
public class LWCUtil {

public static void removeProtection(Block block) {
if (!isLWCLoaded()) {
return;
}
Protection protection = LWC.getInstance().getProtectionCache().getProtection(block);
if (protection != null) {
protection.remove();
}
}

/**
* @return
* true if LWC is loaded
*/
public static boolean isLWCLoaded() {
return Bukkit.getPluginManager().getPlugin("LWC") != null;
}

}
4 changes: 4 additions & 0 deletions src/main/java/de/erethon/dungeonsxl/world/DWorldCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.MainConfig;
import de.erethon.dungeonsxl.config.MainConfig.BackupMode;
import de.erethon.dungeonsxl.util.LWCUtil;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -60,6 +61,9 @@ public DWorldCache(File folder) {

startWorldUnloadTask(1200L);
Bukkit.getPluginManager().registerEvents(new DWorldListener(this), plugin);
if (LWCUtil.isLWCLoaded()) {
new LWCIntegration(plugin);
}
}

/* Getters and setters */
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/de/erethon/dungeonsxl/world/LWCIntegration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2012-2018 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.erethon.dungeonsxl.world;

import com.griefcraft.lwc.LWC;
import com.griefcraft.scripting.JavaModule;
import com.griefcraft.scripting.event.LWCProtectionRegisterEvent;
import de.erethon.dungeonsxl.DungeonsXL;

/**
* @author Daniel Saukel
*/
public class LWCIntegration extends JavaModule {

DungeonsXL plugin;

public LWCIntegration(DungeonsXL plugin) {
this.plugin = plugin;
LWC.getInstance().getModuleLoader().registerModule(plugin, this);
}

@Override
public void onRegisterProtection(LWCProtectionRegisterEvent event) {
DInstanceWorld instance = plugin.getDWorlds().getInstanceByWorld(event.getBlock().getWorld());
if (instance != null) {
event.setCancelled(true);
}
}

}

0 comments on commit 2438149

Please sign in to comment.