mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-02 17:00:19 +01:00
Revert redstone signs functionality
This commit is contained in:
parent
d6a2e38375
commit
b4171e3479
@ -34,7 +34,7 @@ import org.bukkit.entity.Player;
|
||||
* @author Frank Baumann, Milan Albrecht, Daniel Saukel
|
||||
*/
|
||||
public class EditCommand extends DCommand {
|
||||
|
||||
|
||||
public EditCommand(DungeonsXL plugin) {
|
||||
super(plugin);
|
||||
setCommand("edit");
|
||||
@ -43,42 +43,42 @@ public class EditCommand extends DCommand {
|
||||
setHelp(DMessage.CMD_EDIT_HELP.getMessage());
|
||||
setPlayerCommand(true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
|
||||
ResourceWorld resource = plugin.getMapRegistry().getFirstIf(d -> d.getName().equalsIgnoreCase(args[1]));
|
||||
if (resource == null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(args[1]));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!resource.isInvitedPlayer(player) && !DPermission.hasPermission(player, DPermission.EDIT)) {
|
||||
MessageUtil.sendMessage(player, CommonMessage.CMD_NO_PERMISSION.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
EditWorld editWorld = resource.getOrInstantiateEditWorld(false);
|
||||
if (editWorld == null) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
PlayerGroup dGroup = plugin.getPlayerGroup(player);
|
||||
GlobalPlayer dPlayer = dPlayers.get(player);
|
||||
|
||||
|
||||
if (dPlayer instanceof InstancePlayer) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (dGroup != null) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_GROUP.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
new DEditPlayer(plugin, player, editWorld);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2020 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.sign.windup;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* @author Frank Baumann, Milan Albrecht, Daniel Saukel
|
||||
*/
|
||||
public class DelayedPowerTask extends BukkitRunnable {
|
||||
|
||||
private RedstoneSign sign;
|
||||
private boolean enable;
|
||||
|
||||
public DelayedPowerTask(RedstoneSign sign, boolean enable) {
|
||||
this.sign = sign;
|
||||
this.enable = enable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (sign.getGameWorld() == null) {
|
||||
sign.getEnableTask().cancel();
|
||||
sign.getDisableTask().cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
sign.power();
|
||||
if (sign.getRepeatsToDo() == 1) {
|
||||
sign.getEnableTask().cancel();
|
||||
}
|
||||
|
||||
} else {
|
||||
sign.unpower();
|
||||
if (sign.getRepeatsToDo() == 1) {
|
||||
sign.getDisableTask().cancel();
|
||||
}
|
||||
sign.setRepeatsToDo(sign.getRepeatsToDo() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -19,21 +19,77 @@ package de.erethon.dungeonsxl.sign.windup;
|
||||
import de.erethon.caliburn.item.VanillaItem;
|
||||
import de.erethon.commons.misc.NumberUtil;
|
||||
import de.erethon.dungeonsxl.api.DungeonsAPI;
|
||||
import de.erethon.dungeonsxl.api.sign.Windup;
|
||||
import de.erethon.dungeonsxl.api.sign.Rocker;
|
||||
import de.erethon.dungeonsxl.api.world.InstanceWorld;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
* @author Frank Baumann, Daniel Saukel
|
||||
*/
|
||||
public class RedstoneSign extends Windup {
|
||||
public class RedstoneSign extends Rocker {
|
||||
|
||||
private BukkitTask enableTask;
|
||||
private BukkitTask disableTask;
|
||||
private long delay = 0;
|
||||
private long offDelay = 0;
|
||||
private int repeat = 1;
|
||||
private int repeatsToDo = 1;
|
||||
|
||||
public RedstoneSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) {
|
||||
super(api, sign, lines, instance);
|
||||
}
|
||||
|
||||
public BukkitTask getEnableTask() {
|
||||
return enableTask;
|
||||
}
|
||||
|
||||
public void setEnableTask(BukkitTask enableTask) {
|
||||
this.enableTask = enableTask;
|
||||
}
|
||||
|
||||
public BukkitTask getDisableTask() {
|
||||
return disableTask;
|
||||
}
|
||||
|
||||
public void setDisableTask(BukkitTask disableTask) {
|
||||
this.disableTask = disableTask;
|
||||
}
|
||||
|
||||
public long getDelay() {
|
||||
return delay;
|
||||
}
|
||||
|
||||
public void setDelay(long delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public long getOffDelay() {
|
||||
return offDelay;
|
||||
}
|
||||
|
||||
public void setOffDelay(long offDelay) {
|
||||
this.offDelay = offDelay;
|
||||
}
|
||||
|
||||
public int getRepeat() {
|
||||
return repeat;
|
||||
}
|
||||
|
||||
public void setRepeat(int repeat) {
|
||||
this.repeat = repeat;
|
||||
}
|
||||
|
||||
public int getRepeatsToDo() {
|
||||
return repeatsToDo;
|
||||
}
|
||||
|
||||
public void setRepeatsToDo(int repeatsToDo) {
|
||||
this.repeatsToDo = repeatsToDo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Redstone";
|
||||
@ -66,23 +122,32 @@ public class RedstoneSign extends Windup {
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
interval = NumberUtil.parseDouble(getLine(1), 0);
|
||||
n = NumberUtil.parseInt(getLine(2), -1);
|
||||
setRunnable(new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (getGameWorld() == null) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
power(!isPowered());
|
||||
if (k < n) {
|
||||
k++;
|
||||
} else {
|
||||
cancel();
|
||||
}
|
||||
int line1 = 0;
|
||||
int line11 = 0;
|
||||
if (!getLine(1).isEmpty()) {
|
||||
String line[] = getLine(1).split(",");
|
||||
line1 = NumberUtil.parseInt(line[0]);
|
||||
if (line.length > 1) {
|
||||
line11 = NumberUtil.parseInt(line[1]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
int line2 = 1;
|
||||
if (!getLine(2).isEmpty()) {
|
||||
line2 = NumberUtil.parseInt(getLine(2));
|
||||
}
|
||||
|
||||
if (line1 > 0) {
|
||||
delay = (long) line1 * 2;
|
||||
if (line11 > 0) {
|
||||
offDelay = (long) line11 * 2;
|
||||
} else {
|
||||
offDelay = delay;
|
||||
}
|
||||
if (line2 >= 0) {
|
||||
repeat = line2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -92,20 +157,44 @@ public class RedstoneSign extends Windup {
|
||||
}
|
||||
|
||||
if (delay > 0) {
|
||||
startTask();
|
||||
enableTask = new DelayedPowerTask(this, true).runTaskTimer(api, delay, delay + offDelay);
|
||||
|
||||
if (repeat != 1) {
|
||||
repeatsToDo = repeat;
|
||||
disableTask = new DelayedPowerTask(this, false).runTaskTimer(api, delay + offDelay, delay + offDelay);
|
||||
}
|
||||
|
||||
} else {
|
||||
power(true);
|
||||
power();
|
||||
}
|
||||
|
||||
active = true;
|
||||
}
|
||||
|
||||
public boolean isPowered() {
|
||||
return getSign().getBlock().getType() == VanillaItem.REDSTONE_BLOCK.getMaterial();
|
||||
@Override
|
||||
public void deactivate() {
|
||||
if (!active) {
|
||||
return;
|
||||
}
|
||||
|
||||
unpower();
|
||||
|
||||
if (enableTask != null) {
|
||||
enableTask.cancel();
|
||||
}
|
||||
if (disableTask != null) {
|
||||
disableTask.cancel();
|
||||
}
|
||||
|
||||
active = false;
|
||||
}
|
||||
|
||||
public void power(boolean power) {
|
||||
getSign().getBlock().setType((power ? VanillaItem.REDSTONE_BLOCK : VanillaItem.AIR).getMaterial());
|
||||
public void power() {
|
||||
getSign().getBlock().setType(VanillaItem.REDSTONE_BLOCK.getMaterial());
|
||||
}
|
||||
|
||||
public void unpower() {
|
||||
setToAir();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user