Add interval and stack size to drop sign

This commit is contained in:
Daniel Saukel 2016-06-21 14:17:11 +02:00
parent fccaed5bb9
commit d7dce66347
2 changed files with 67 additions and 2 deletions

View File

@ -18,7 +18,9 @@ package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.caliburn.item.UniversalItem;
import io.github.dre2n.commons.util.NumberUtil;
import io.github.dre2n.dungeonsxl.task.DropItemTask;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.inventory.ItemStack;
@ -31,6 +33,7 @@ public class DropSign extends DSign {
private DSignType type = DSignTypeDefault.DROP;
private ItemStack item;
private double interval = -1;
public DropSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
@ -61,13 +64,27 @@ public class DropSign extends DSign {
@Override
public void onInit() {
UniversalItem item = plugin.getCaliburnAPI().getItems().getById(lines[1]);
this.item = item.toItemStack(NumberUtil.parseInt(lines[2], 1));
String[] attributes = lines[2].split(",");
if (attributes.length >= 1) {
this.item = item.toItemStack(NumberUtil.parseInt(attributes[0], 1));
}
if (attributes.length == 2) {
interval = NumberUtil.parseDouble(attributes[1]);
}
getSign().getBlock().setType(Material.AIR);
}
@Override
public void onTrigger() {
getSign().getWorld().dropItem(getSign().getLocation(), item);
Location spawnLocation = getSign().getLocation().add(0.5, 0, 0.5);
if (interval < 0) {
getSign().getWorld().dropItem(spawnLocation, item);
} else {
new DropItemTask(item, spawnLocation).runTaskTimer(plugin, 0, (long) interval * 20);
}
}
@Override

View File

@ -0,0 +1,48 @@
/*
* Copyright (C) 2012-2016 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 io.github.dre2n.dungeonsxl.task;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
/**
* @author Frank Baumann, Daniel Saukel
*/
public class DropItemTask extends BukkitRunnable {
DungeonsXL plugin = DungeonsXL.getInstance();
private ItemStack item;
private Location location;
public DropItemTask(ItemStack item, Location location) {
this.item = item;
this.location = location;
}
@Override
public void run() {
try {
location.getWorld().dropItem(location, item);
} catch (NullPointerException exception) {
cancel();
}
}
}