Add LWC integration; resolves #393

This commit is contained in:
Daniel Saukel 2018-06-09 00:03:19 +02:00
parent d1654670ab
commit 2438149bd1
7 changed files with 101 additions and 0 deletions

View File

@ -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>

View File

@ -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;
@ -24,6 +26,7 @@ import de.erethon.dungeonsxl.DungeonsXL;
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;
@ -232,6 +235,8 @@ public class GameSign extends JoinSign {
}
GameSign sign = new GameSign(DungeonsXL.getInstance().getGlobalProtections().generateId(GameSign.class, world), startSign, identifier, maxGroupsPerGame);
LWCUtil.removeProtection(startSign);
return sign;
}

View File

@ -23,6 +23,7 @@ import de.erethon.commons.misc.NumberUtil;
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;
@ -217,6 +218,8 @@ public class GroupSign extends JoinSign {
}
GroupSign sign = new GroupSign(DungeonsXL.getInstance().getGlobalProtections().generateId(GroupSign.class, world), startSign, identifier, maxPlayersPerGroup, groupName);
LWCUtil.removeProtection(startSign);
return sign;
}

View File

@ -22,6 +22,7 @@ import de.erethon.dungeonsxl.DungeonsXL;
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;
@ -47,6 +48,8 @@ public class LeaveSign extends GlobalProtection {
this.sign = sign;
setText();
LWCUtil.removeProtection(sign.getBlock());
}
/* Getters and setters */

View File

@ -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;
}
}

View File

@ -21,6 +21,7 @@ import de.erethon.commons.misc.NumberUtil;
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;
@ -60,6 +61,9 @@ public class DWorldCache {
startWorldUnloadTask(1200L);
Bukkit.getPluginManager().registerEvents(new DWorldListener(this), plugin);
if (LWCUtil.isLWCLoaded()) {
new LWCIntegration(plugin);
}
}
/* Getters and setters */

View File

@ -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);
}
}
}