Adding Redstone function signs for events.

This commit is contained in:
Sarah 2015-09-05 20:38:51 +02:00
parent 503b68da2f
commit 5712af8ddc
2 changed files with 327 additions and 29 deletions

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import mineplex.core.common.util.F;
@ -23,6 +24,7 @@ import mineplex.core.disguise.disguises.DisguiseChicken;
import mineplex.core.disguise.disguises.DisguiseEnderman;
import mineplex.core.disguise.disguises.DisguiseWither;
import mineplex.core.gadget.event.GadgetActivateEvent;
import mineplex.core.give.Give;
import mineplex.core.mount.event.MountActivateEvent;
import mineplex.core.recharge.Recharge;
import mineplex.core.shop.item.SalesPackageBase;
@ -34,7 +36,6 @@ import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.games.event.kits.KitPlayer;
import nautilus.game.arcade.game.games.skywars.TeamSkywars.TeamColors;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.managers.GameHostManager;
@ -51,6 +52,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
@ -79,6 +81,7 @@ public class EventGame extends Game
private HashSet<SalesPackageBase> _gadgetWhitelist = new HashSet<SalesPackageBase>();
private HashMap<Sign, Long> _functionSigns;
private ArrayList<Sign> _powerdedSigns;
public EventGame(ArcadeManager manager)
{
@ -125,6 +128,7 @@ public class EventGame extends Game
_mps = manager.GetGameHostManager();
_functionSigns = new HashMap<>();
_powerdedSigns = new ArrayList<>();
this.CreatureAllow = true;
}
@ -514,25 +518,23 @@ public class EventGame extends Game
return losers;
}
@EventHandler
/*@EventHandler
public void signCheck(BlockRedstoneEvent event)
{
if(event.getBlock().getType() != Material.SIGN_POST && event.getBlock().getType() != Material.WALL_SIGN)
return;
return;
useSign(((Sign) event.getBlock().getState()).getLines());
}
}*/
@EventHandler
public void signClock(UpdateEvent event)
{
if(event.getType() != UpdateType.SEC)
if(event.getType() != UpdateType.TICK)
return;
for(Sign sign : _functionSigns.keySet())
{
if(sign.getBlock().getRelative(BlockFace.DOWN).getType() != Material.IRON_BLOCK)
continue;
Sign cooldown = null;
@ -542,42 +544,243 @@ public class EventGame extends Game
continue;
if(sign.getBlock().getRelative(BlockFace.DOWN).getRelative(face).getType() == Material.WALL_SIGN)
{
{
cooldown = (Sign) sign.getBlock().getRelative(BlockFace.DOWN).getRelative(face).getState();
break;
}
}
if(cooldown == null)
{
if(!sign.getBlock().isBlockPowered())
{
_powerdedSigns.remove(sign);
continue;
}
if(_powerdedSigns.contains(sign))
continue;
useSign(sign, ((Sign) sign.getBlock().getState()).getLines());
if(sign.getBlock().isBlockPowered())
{
if(!_powerdedSigns.contains(sign))
{
_powerdedSigns.add(sign);
}
}
continue;
}
if(!sign.getBlock().isBlockPowered() && !UtilTime.elapsed(_functionSigns.get(sign), Long.parseLong(cooldown.getLine(0)) * 1000))
continue;
if(!UtilTime.elapsed(_functionSigns.get(sign), Long.parseLong(cooldown.getLine(0)) * 1000))
if(!sign.getBlock().isBlockPowered())
{
_powerdedSigns.remove(sign);
}
if(_powerdedSigns.contains(sign))
continue;
_functionSigns.put(sign, System.currentTimeMillis());
useSign(sign.getLines());
useSign(sign, ((Sign) sign.getBlock().getState()).getLines());
if(sign.getBlock().isBlockPowered())
{
if(!_powerdedSigns.contains(sign))
{
_powerdedSigns.add(sign);
}
}
}
}
public void useSign(String[] args)
public void useSign(final Sign sign, String[] args)
{
String command = args[0];
String playerName = args[1];
command.replace("[", "").replaceAll("]", "");
if(command.contentEquals("BC"))
HashMap<Integer, ArrayList<Player>> varMap = new HashMap<>();
int i = 0;
for(String varArgs : args)
{
ArrayList<Player> players = new ArrayList<>();
if(Bukkit.getPlayer(playerName) != null)
players.add(Bukkit.getPlayer(playerName));
if(playerName.contentEquals("@p"))
{
for(Player player : GetPlayers(true))
{
boolean found = true;
for(Player otherPlayer : GetPlayers(true))
{
if(UtilMath.offset(sign.getLocation(), player.getLocation()) >= UtilMath.offset(sign.getLocation(), otherPlayer.getLocation()))
{
found = false;
break;
}
}
if(found = true)
{
players.add(player);
break;
}
}
}
if(playerName.contains("@a"))
{
int radius = 0;
if(playerName.contains("r="))
{
try
{
radius = Integer.parseInt(playerName.split("=")[1]);
}
catch (Exception e) {}
}
for(Player player : GetPlayers(true))
{
if(UtilMath.offset(sign.getLocation(), player.getLocation()) <= radius || radius <= 0)
players.add(player);
}
}
varMap.put(i, players);
i++;
}
if(command.contentEquals("[BC]"))
{
String message = args[1];
for(int i = 2; i <= 3; i++)
message += " " + args[i];
for(int e = 2; e <= 3; e++)
message += " " + args[e];
String colored = ChatColor.translateAlternateColorCodes('&', message);
this.Announce(F.main("Event", colored), true);
}
if(command.contentEquals("[TELEPORT]"))
{
for(Player player : varMap.get(1))
{
if(Bukkit.getPlayer(args[2]) != null)
{
player.teleport(Bukkit.getPlayer(args[2]));
}
else
{
String[] coords = args[2].split(" ");
int x = Integer.parseInt(coords[0]);
int y = Integer.parseInt(coords[1]);
int z = Integer.parseInt(coords[2]);
player.teleport(new Location(sign.getWorld(), x, y, z));
}
}
}
if(command.contentEquals("[MESSAGE]"))
{
String message = args[2];
message += " " + args[3];
String colored = ChatColor.translateAlternateColorCodes('&', message);
for(Player player : varMap.get(1))
{
UtilPlayer.message(player, F.main("Event", colored));
}
}
if(command.contentEquals("[SETBLOCK]"))
{
Material mat = Material.getMaterial(args[1]);
String[] coords = args[2].split(" ");
int x = Integer.parseInt(coords[0]);
int y = Integer.parseInt(coords[1]);
int z = Integer.parseInt(coords[2]);
sign.getWorld().getBlockAt(new Location(sign.getWorld(), x, y, z)).setType(mat);
}
if(command.contentEquals("[TESTFOR]"))
{
boolean redstone = false;
Material mat = Material.getMaterial(args[1]);
if(args[2].contains("r="))
{
int radius = 0;
try
{
radius = Integer.parseInt(args[2].split("=")[1]);
if(radius >= 30)
radius = 30;
for(int x = -radius + sign.getLocation().getBlockX(); x < radius + sign.getLocation().getBlockX(); x++)
{
for(int y = -radius + sign.getLocation().getBlockY(); y < radius + sign.getLocation().getBlockY(); y++)
{
for(int z = -radius + sign.getLocation().getBlockZ(); z < radius + sign.getLocation().getBlockZ(); z++)
{
if(sign.getWorld().getBlockAt(new Location(sign.getWorld(), x, y, z)).getType() == mat)
{
redstone = true;
}
}
}
}
}
catch (Exception e) {}
}
else
{
String[] coords = args[2].split(" ");
int x = Integer.parseInt(coords[0]);
int y = Integer.parseInt(coords[1]);
int z = Integer.parseInt(coords[2]);
if(sign.getWorld().getBlockAt(new Location(sign.getWorld(), x, y, z)).getType() == mat)
{
redstone = true;
}
}
if(redstone)
{
for(final BlockFace face : BlockFace.values())
{
if(face != BlockFace.UP
&& face != BlockFace.NORTH_WEST
&& face != BlockFace.NORTH_EAST
&& face != BlockFace.SOUTH_EAST
&& face != BlockFace.SOUTH_WEST)
{
continue;
}
if(sign.getBlock().getRelative(face).getType() != Material.AIR)
continue;
if(sign.getBlock().getRelative(face).isBlockPowered())
continue;
sign.getBlock().getRelative(face).setType(Material.REDSTONE_BLOCK);
Manager.runSyncLater(new Runnable()
{
Player player = Bukkit.getPlayer(playerName);
if(player == null)
@Override
public void run()
{
sign.getBlock().getRelative(face).setType(Material.AIR);
}
}, 3L);
}
}
}
if(varMap.get(1).isEmpty())
return;
String[] vars = new String[args.length - 1];
@ -585,9 +788,84 @@ public class EventGame extends Game
vars[1] = args[2];
vars[2] = args[3];
if(command.contentEquals("MOB"))
String tempArgs = "";
for(String str : vars)
{
Manager.GetEventModule().commandMob(player, vars);
for(String string : str.split(" "))
{
tempArgs += string + " ";
}
}
String[] commandArgs = tempArgs.split(" ");
if(command.contentEquals("[MOB]"))
{
for(Player player : varMap.get(1))
Manager.GetEventModule().commandMob(player, commandArgs);
}
if(command.contentEquals("[SCORE]"))
{
for(Player player : varMap.get(1))
Manager.GetEventModule().commandScoreboard(player, vars);
}
if(command.contentEquals("[GIVE]"))
{
try
{
for(Player player : varMap.get(1))
{
String[] newArgs = new String[commandArgs.length-1];
for (int e=0 ; e<newArgs.length ; e++)
newArgs[e] = commandArgs[e+1];
newArgs[0] = player.getName();
Give.Instance.parseInput(Manager.GetGameHostManager().getHost(), newArgs);
}
} catch (Exception e)
{
}
}
if(command.contentEquals("[DOUBLEJUMP]"))
{
for(Player player : varMap.get(1))
Manager.GetEventModule().commandDoubleJump(player, vars);
}
if(command.contentEquals("[EFFECT]"))
{
try
{
Manager.GetEventModule().commandEffect(Manager.GetGameHostManager().getHost(), commandArgs, varMap.get(1));
} catch (Exception e)
{
}
}
if(command.contentEquals("[KIT]"))
{
for(Player player : varMap.get(1))
Manager.GetEventModule().commandKit(player, commandArgs);
}
}
@EventHandler
public void signBreak(BlockBreakEvent event)
{
if(event.getBlock().getType() == Material.SIGN_POST || event.getBlock().getType() == Material.WALL_SIGN || event.getBlock().getType() == Material.SIGN)
{
Iterator<Sign> signIter = _functionSigns.keySet().iterator();
while(signIter.hasNext())
{
Sign sign = signIter.next();
if(sign.getLocation().getBlockX() == event.getBlock().getLocation().getBlockX()
&& sign.getLocation().getBlockY() == event.getBlock().getLocation().getBlockY()
&& sign.getLocation().getBlockZ() == event.getBlock().getLocation().getBlockZ())
{
signIter.remove();
}
}
}
}

View File

@ -257,7 +257,7 @@ public class EventModule extends MiniPlugin
}
else if (args[0].equalsIgnoreCase("effect"))
{
commandEffect(event.getPlayer(), args);
commandEffect(event.getPlayer(), args, null);
}
else if (args[0].equalsIgnoreCase("kit"))
{
@ -987,7 +987,7 @@ public class EventModule extends MiniPlugin
lineText += " ";
}
((EventGame) Manager.GetGame()).getSideText()[line] = lineText;
((EventGame) Manager.GetGame()).getSideText()[line] = ChatColor.translateAlternateColorCodes('&', lineText);
UtilPlayer.message(player, F.main("Scoreboard", "Set Line " + F.elem(line+"") + " to " + F.elem(lineText) + "."));
@ -1533,7 +1533,7 @@ public class EventModule extends MiniPlugin
commandHelp(caller);
}
public void commandEffect(Player caller, String[] args)
public void commandEffect(Player caller, String[] args, ArrayList<Player> players)
{
//Clear
if (args.length >= 3 && args[2].equalsIgnoreCase("clear"))
@ -1551,9 +1551,19 @@ public class EventModule extends MiniPlugin
}
else
{
targets = UtilPlayer.matchOnline(caller, args[1], true);
if (targets.isEmpty())
return;
if(players == null)
{
targets = UtilPlayer.matchOnline(caller, args[1], true);
if (targets.isEmpty())
return;
}
else
{
targets = new LinkedList<>();
for(Player player : players)
targets.add(player);
}
}
for (Player player : targets)
@ -1647,10 +1657,20 @@ public class EventModule extends MiniPlugin
_potionEffectsMult.put(type, mult);
}
else
{
targets = UtilPlayer.matchOnline(caller, args[1], true);
if (targets.isEmpty())
return;
{
if(players == null)
{
targets = UtilPlayer.matchOnline(caller, args[1], true);
if (targets.isEmpty())
return;
}
else
{
targets = new LinkedList<>();
for(Player player : players)
targets.add(player);
}
}
//Apply