Per player msg, easier trigger creation, fixes

This commit is contained in:
Sn0wStorm 2013-04-12 18:58:19 +02:00
parent 9da8f21a9b
commit c054d5b48b
7 changed files with 110 additions and 26 deletions

View File

@ -14,6 +14,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.EntityCombustByEntityEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -30,6 +31,16 @@ import com.dre.dungeonsxl.game.DMob;
import com.dre.dungeonsxl.game.GameWorld;
public class EntityListener implements Listener{
//Remove drops from breaking Signs
@EventHandler(priority = EventPriority.HIGH)
public void onItemSpawn(ItemSpawnEvent event){
if(GameWorld.get(event.getLocation().getWorld()) != null){
if(event.getEntity().getItemStack().getTypeId()==323){
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onCreatureSpawn(CreatureSpawnEvent event){

View File

@ -69,10 +69,8 @@ public class PlayerListener implements Listener{
}
}
}
}
//Block invisible Redstone signs
if(GameWorld.get(player.getWorld())!=null){
GameWorld gworld = GameWorld.get(player.getWorld());
if(!gworld.untouchable.isEmpty()){
if(event.getAction()==Action.RIGHT_CLICK_BLOCK){

View File

@ -26,6 +26,7 @@ public class SIGNMob extends DSign{
private int interval = 0;
private int amount = 1;
private boolean initialized;
private boolean active;
private int id = -1;
public SIGNMob(Sign sign, GameWorld gworld) {
@ -62,10 +63,14 @@ public class SIGNMob extends DSign{
public void onUpdate(int type,boolean powered) {
if(initialized){
setPowered(type,powered);
if(!isDistanceTrigger()){
if(isPowered()){
if(isPowered()){
if(!isDistanceTrigger()){
onTrigger();
}
} else {
killTask();
interval = 0;
active = false;
}
}
}
@ -73,27 +78,28 @@ public class SIGNMob extends DSign{
@Override
public void onTrigger() {
if(initialized){
MobSpawnScheduler scheduler = new MobSpawnScheduler(this);
id = p.getServer().getScheduler().scheduleSyncRepeatingTask(p, scheduler, 0L, 20L);
scheduler.id = id;
initialized = false;
if(!active){
MobSpawnScheduler scheduler = new MobSpawnScheduler(this);
id = p.getServer().getScheduler().scheduleSyncRepeatingTask(p, scheduler, 0L, 20L);
active = true;
}
}
}
@Override
public void killTask(){
//if(initialized){
if(initialized && active){
if(id != -1){
p.getServer().getScheduler().cancelTask(id);
id = -1;
}
//}
}
}
public class MobSpawnScheduler implements Runnable{
private SIGNMob sign;
public int id;
public MobSpawnScheduler(SIGNMob sign){
this.sign = sign;
@ -133,8 +139,8 @@ public class SIGNMob extends DSign{
if(amount>1){
amount--;
}else{
p.getServer().getScheduler().cancelTask(this.id);
sign.gworld.dSigns.remove(this);
killTask();
sign.gworld.dSigns.remove(sign);
}
}

View File

@ -1,5 +1,7 @@
package com.dre.dungeonsxl.signs;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.game.GameWorld;
@ -13,6 +15,7 @@ public class SIGNMsg extends DSign{
//Variables
private String msg;
private boolean initialized;
private CopyOnWriteArrayList<Player> done = new CopyOnWriteArrayList<Player>();
public SIGNMsg(Sign sign, GameWorld gworld) {
super(sign, gworld);
@ -56,10 +59,17 @@ public class SIGNMsg extends DSign{
public void onTrigger() {
if(initialized){
for(Player player : gworld.world.getPlayers()){
p.msg(player, msg);
if(!done.contains(player)){
if(!isDistanceTrigger() || player.getLocation().distance(sign.getLocation()) < getDtDistance()){
p.msg(player, msg);
done.add(player);
}
}
}
this.gworld.dSigns.remove(this);
if(done.size() >= gworld.world.getPlayers().size()){
this.gworld.dSigns.remove(this);
}
}
}

View File

@ -29,9 +29,7 @@ public class SIGNRedstone extends DSign{
@Override
public boolean check() {
if(isRedstoneTrigger()){
if(sign.getBlock().getType() != Material.WALL_SIGN){
return false;
}
return false;
}
return true;
@ -87,6 +85,7 @@ public class SIGNRedstone extends DSign{
public void onDiscover(){
if(initialized && active){
P.p.getServer().getScheduler().scheduleSyncDelayedTask(p, new DiscoveryTask(), 1);
P.p.getServer().getScheduler().scheduleSyncDelayedTask(p, new DiscoveryTask(), 5);
}
}
@ -110,6 +109,7 @@ public class SIGNRedstone extends DSign{
active = true;
if(task == null){
task = P.p.getServer().getScheduler().runTaskTimer(p, new DiscoveryTask(), 1, 60);
P.p.getServer().getScheduler().scheduleSyncDelayedTask(p, new DiscoveryTask(), 5);
}
}
}
@ -134,7 +134,9 @@ public class SIGNRedstone extends DSign{
public void run() {
if(initialized && active){
for(DPlayer dplayer:DPlayer.players){
dplayer.player.sendBlockChange(sign.getBlock().getLocation(),0,(byte)0);
if(!dplayer.isEditing){
dplayer.player.sendBlockChange(sign.getBlock().getLocation(),0,(byte)0);
}
}
}
}

View File

@ -1,5 +1,7 @@
package com.dre.dungeonsxl.signs;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.getspout.spoutapi.Spout;
@ -18,6 +20,7 @@ public class SIGNSoundMsg extends DSign{
//Variables
private boolean initialized;
private String msg;
private CopyOnWriteArrayList<Player> done = new CopyOnWriteArrayList<Player>();
public SIGNSoundMsg(Sign sign, GameWorld gworld) {
super(sign, gworld);
@ -62,14 +65,21 @@ public class SIGNSoundMsg extends DSign{
if(initialized){
if(P.p.isSpoutEnabled){
for(Player player : gworld.world.getPlayers()){
SpoutPlayer sPlayer = Spout.getServer().getPlayer(player.getName());
if(sPlayer.isSpoutCraftEnabled()){
SpoutManager.getSoundManager().playCustomMusic(P.p, sPlayer, this.msg, false, this.sign.getLocation());
if(!done.contains(player)){
if(!isDistanceTrigger() || player.getLocation().distance(sign.getLocation()) < getDtDistance()){
done.add(player);
SpoutPlayer sPlayer = Spout.getServer().getPlayer(player.getName());
if(sPlayer.isSpoutCraftEnabled()){
SpoutManager.getSoundManager().playCustomMusic(P.p, sPlayer, this.msg, false, this.sign.getLocation());
}
}
}
}
}
this.gworld.dSigns.remove(this);
if(done.size() >= gworld.world.getPlayers().size()){
this.gworld.dSigns.remove(this);
}
}
}

View File

@ -1,13 +1,19 @@
package com.dre.dungeonsxl.signs;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.block.Sign;
import org.bukkit.block.Block;
import com.dre.dungeonsxl.game.GameWorld;
import com.dre.dungeonsxl.EditWorld;
public class SIGNTrigger extends DSign{
public static String name = "Trigger";
public String buildPermissions = "dxl.sign.trigger";
public boolean onDungeonInit = false;
public static Set<Integer> used = new HashSet<Integer>();
//Variables
private int triggerId;
@ -19,6 +25,36 @@ public class SIGNTrigger extends DSign{
@Override
public boolean check() {
used.clear();
for(Block block : EditWorld.get(sign.getLocation().getWorld()).sign) {
if(block.getState() instanceof Sign){
Sign rsign = (Sign) block.getState();
if(rsign != null){
if(rsign.getLine(0).equalsIgnoreCase("["+name+"]")){
used.add(p.parseInt(rsign.getLine(1)));
}
}
}
}
int id = 1;
if(sign.getLine(1).equalsIgnoreCase("")){
if(used.size() != 0){
while(used.contains(id)){
id++;
}
}
} else {
id = p.parseInt(sign.getLine(1));
if(used.contains(id)){
return false;
} else {
return true;
}
}
sign.setLine(1, id+"");
p.getServer().getScheduler().scheduleSyncDelayedTask(p, new UpdateTask(), 2);
return true;
}
@ -34,7 +70,7 @@ public class SIGNTrigger extends DSign{
public void onUpdate(int type,boolean powered) {
if(initialized){
setPowered(type,powered);
if(!isDistanceTrigger()){
if(!isDistanceTrigger() || !isPowered()){
for(DSign dsign : this.gworld.dSigns){
if(dsign != null){
if(dsign.isSignTrigger()){
@ -72,4 +108,15 @@ public class SIGNTrigger extends DSign{
public boolean isOnDungeonInit() {
return onDungeonInit;
}
public class UpdateTask implements Runnable {
public UpdateTask() {
}
@Override
public void run() {
sign.update();
}
}
}