use of au.com.mineauz.minigamesregions.executors.RegionExecutor in project Minigames by AddstarMC.
the class RegionModule method save.
@Override
public void save(FileConfiguration config) {
Set<String> rs = regions.keySet();
for (String name : rs) {
Region r = regions.get(name);
Map<String, Object> sloc = MinigameUtils.serializeLocation(r.getFirstPoint());
for (String i : sloc.keySet()) {
if (!i.equals("yaw") && !i.equals("pitch"))
config.set(getMinigame() + ".regions." + name + ".point1." + i, sloc.get(i));
}
sloc = MinigameUtils.serializeLocation(r.getSecondPoint());
for (String i : sloc.keySet()) {
if (!i.equals("yaw") && !i.equals("pitch"))
config.set(getMinigame() + ".regions." + name + ".point2." + i, sloc.get(i));
}
if (r.getTickDelay() != 20) {
config.set(getMinigame() + ".regions." + name + ".tickDelay", r.getTickDelay());
}
int c = 0;
for (RegionExecutor ex : r.getExecutors()) {
String path = getMinigame() + ".regions." + name + ".executors." + c;
config.set(path + ".trigger", ex.getTrigger().getName());
int acc = 0;
for (ActionInterface act : ex.getActions()) {
config.set(path + ".actions." + acc + ".type", act.getName());
act.saveArguments(config, path + ".actions." + acc + ".arguments");
acc++;
}
acc = 0;
for (ConditionInterface con : ex.getConditions()) {
config.set(path + ".conditions." + acc + ".type", con.getName());
con.saveArguments(config, path + ".conditions." + acc + ".arguments");
acc++;
}
if (ex.isTriggerPerPlayer())
config.set(path + ".isTriggeredPerPlayer", ex.isTriggerPerPlayer());
if (ex.getTriggerCount() != 0)
config.set(path + ".triggerCount", ex.getTriggerCount());
c++;
}
}
Set<String> ns = nodes.keySet();
for (String name : ns) {
Node n = nodes.get(name);
Map<String, Object> sloc = MinigameUtils.serializeLocation(n.getLocation());
for (String i : sloc.keySet()) {
config.set(getMinigame() + ".nodes." + name + ".point." + i, sloc.get(i));
}
int c = 0;
for (NodeExecutor ex : n.getExecutors()) {
String path = getMinigame() + ".nodes." + name + ".executors." + c;
config.set(path + ".trigger", ex.getTrigger().getName());
int acc = 0;
for (ActionInterface act : ex.getActions()) {
config.set(path + ".actions." + acc + ".type", act.getName());
act.saveArguments(config, path + ".actions." + acc + ".arguments");
acc++;
}
acc = 0;
for (ConditionInterface con : ex.getConditions()) {
config.set(path + ".conditions." + acc + ".type", con.getName());
con.saveArguments(config, path + ".conditions." + acc + ".arguments");
acc++;
}
if (ex.isTriggerPerPlayer())
config.set(path + ".isTriggeredPerPlayer", ex.isTriggerPerPlayer());
if (ex.getTriggerCount() != 0)
config.set(path + ".triggerCount", ex.getTriggerCount());
c++;
}
}
}
use of au.com.mineauz.minigamesregions.executors.RegionExecutor in project Minigames by AddstarMC.
the class RegionModule method load.
@Override
public void load(FileConfiguration config) {
if (config.contains(getMinigame() + ".regions")) {
Set<String> rs = config.getConfigurationSection(getMinigame() + ".regions").getKeys(false);
for (String name : rs) {
String cloc1 = getMinigame() + ".regions." + name + ".point1.";
String cloc2 = getMinigame() + ".regions." + name + ".point2.";
World w1 = Minigames.plugin.getServer().getWorld(config.getString(cloc1 + "world"));
World w2 = Minigames.plugin.getServer().getWorld(config.getString(cloc2 + "world"));
double x1 = config.getDouble(cloc1 + "x");
double x2 = config.getDouble(cloc2 + "x");
double y1 = config.getDouble(cloc1 + "y");
double y2 = config.getDouble(cloc2 + "y");
double z1 = config.getDouble(cloc1 + "z");
double z2 = config.getDouble(cloc2 + "z");
Location loc1 = new Location(w1, x1, y1, z1);
Location loc2 = new Location(w2, x2, y2, z2);
regions.put(name, new Region(name, loc1, loc2));
Region r = regions.get(name);
if (config.contains(getMinigame() + ".regions." + name + ".tickDelay")) {
r.changeTickDelay(config.getLong(getMinigame() + ".regions." + name + ".tickDelay"));
}
if (config.contains(getMinigame() + ".regions." + name + ".executors")) {
Set<String> ex = config.getConfigurationSection(getMinigame() + ".regions." + name + ".executors").getKeys(false);
for (String i : ex) {
String path = getMinigame() + ".regions." + name + ".executors." + i;
RegionExecutor rex = new RegionExecutor(Triggers.getTrigger(config.getString(path + ".trigger")));
if (config.contains(path + ".actions")) {
for (String a : config.getConfigurationSection(path + ".actions").getKeys(false)) {
ActionInterface ai = Actions.getActionByName(config.getString(path + ".actions." + a + ".type"));
ai.loadArguments(config, path + ".actions." + a + ".arguments");
rex.addAction(ai);
}
}
if (config.contains(path + ".conditions")) {
for (String c : config.getConfigurationSection(path + ".conditions").getKeys(false)) {
ConditionInterface ci = Conditions.getConditionByName(config.getString(path + ".conditions." + c + ".type"));
ci.loadArguments(config, path + ".conditions." + c + ".arguments");
rex.addCondition(ci);
}
}
if (config.contains(path + ".isTriggeredPerPlayer"))
rex.setTriggerPerPlayer(config.getBoolean(path + ".isTriggeredPerPlayer"));
if (config.contains(path + ".triggerCount"))
rex.setTriggerCount(config.getInt(path + ".triggerCount"));
r.addExecutor(rex);
}
}
}
}
if (config.contains(getMinigame() + ".nodes")) {
Set<String> rs = config.getConfigurationSection(getMinigame() + ".nodes").getKeys(false);
for (String name : rs) {
String cloc1 = getMinigame() + ".nodes." + name + ".point.";
World w1 = Minigames.plugin.getServer().getWorld(config.getString(cloc1 + "world"));
double x1 = config.getDouble(cloc1 + "x");
double y1 = config.getDouble(cloc1 + "y");
double z1 = config.getDouble(cloc1 + "z");
float yaw = 0f;
float pitch = 0f;
if (config.contains(cloc1 + "yaw")) {
//TODO: Remove check after next dev build
yaw = ((Double) config.getDouble(cloc1 + "yaw")).floatValue();
pitch = ((Double) config.getDouble(cloc1 + "pitch")).floatValue();
}
Location loc1 = new Location(w1, x1, y1, z1, yaw, pitch);
nodes.put(name, new Node(name, loc1));
Node n = nodes.get(name);
if (config.contains(getMinigame() + ".nodes." + name + ".executors")) {
Set<String> ex = config.getConfigurationSection(getMinigame() + ".nodes." + name + ".executors").getKeys(false);
for (String i : ex) {
String path = getMinigame() + ".nodes." + name + ".executors." + i;
NodeExecutor rex = new NodeExecutor(Triggers.getTrigger(config.getString(path + ".trigger")));
if (config.contains(path + ".actions")) {
for (String a : config.getConfigurationSection(path + ".actions").getKeys(false)) {
ActionInterface ai = Actions.getActionByName(config.getString(path + ".actions." + a + ".type"));
ai.loadArguments(config, path + ".actions." + a + ".arguments");
rex.addAction(ai);
}
}
if (config.contains(path + ".conditions")) {
for (String c : config.getConfigurationSection(path + ".conditions").getKeys(false)) {
ConditionInterface ci = Conditions.getConditionByName(config.getString(path + ".conditions." + c + ".type"));
ci.loadArguments(config, path + ".conditions." + c + ".arguments");
rex.addCondition(ci);
}
}
if (config.contains(path + ".isTriggeredPerPlayer"))
rex.setTriggerPerPlayer(config.getBoolean(path + ".isTriggeredPerPlayer"));
if (config.contains(path + ".triggerCount"))
rex.setTriggerCount(config.getInt(path + ".triggerCount"));
n.addExecutor(rex);
}
}
}
}
}
use of au.com.mineauz.minigamesregions.executors.RegionExecutor in project Minigames by AddstarMC.
the class RegionEvents method playerQuit.
@EventHandler(ignoreCancelled = true)
private void playerQuit(QuitMinigameEvent event) {
MinigamePlayer ply = event.getMinigamePlayer();
if (ply == null)
return;
Minigame mg = ply.getMinigame();
for (Region r : RegionModule.getMinigameModule(mg).getRegions()) {
if (r.hasPlayer(ply))
r.removePlayer(ply);
}
for (Node node : RegionModule.getMinigameModule(event.getMinigame()).getNodes()) {
node.execute(Triggers.getTrigger("GAME_QUIT"), event.getMinigamePlayer());
if (event.getMinigame().getPlayers().size() > 1) {
for (NodeExecutor exec : node.getExecutors()) exec.removeTrigger(event.getMinigamePlayer());
} else {
for (NodeExecutor exec : node.getExecutors()) exec.clearTriggers();
node.setEnabled(true);
}
}
for (Region region : RegionModule.getMinigameModule(event.getMinigame()).getRegions()) {
if (region.playerInRegion(ply))
region.execute(Triggers.getTrigger("GAME_QUIT"), event.getMinigamePlayer());
if (event.getMinigame().getPlayers().size() > 1) {
for (RegionExecutor exec : region.getExecutors()) exec.removeTrigger(event.getMinigamePlayer());
} else {
for (RegionExecutor exec : region.getExecutors()) {
exec.clearTriggers();
}
region.removeTickTask();
region.setEnabled(true);
}
}
}
use of au.com.mineauz.minigamesregions.executors.RegionExecutor in project Minigames by AddstarMC.
the class RegionEvents method playerJoin.
@EventHandler(ignoreCancelled = true)
private void playerJoin(JoinMinigameEvent event) {
final MinigamePlayer ply = event.getMinigamePlayer();
if (ply == null)
return;
final Minigame mg = event.getMinigame();
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
executeRegionChanges(mg, ply);
for (Node node : RegionModule.getMinigameModule(mg).getNodes()) {
node.execute(Triggers.getTrigger("GAME_JOIN"), ply);
}
for (Region region : RegionModule.getMinigameModule(mg).getRegions()) {
if (region.hasPlayer(ply))
region.execute(Triggers.getTrigger("GAME_JOIN"), ply);
}
}
});
if (event.getMinigame().getPlayers().size() == 0) {
for (Region region : RegionModule.getMinigameModule(event.getMinigame()).getRegions()) {
for (RegionExecutor ex : region.getExecutors()) {
if (ex.getTrigger().getName().equalsIgnoreCase("TICK")) {
region.startTickTask();
break;
}
}
}
}
}
use of au.com.mineauz.minigamesregions.executors.RegionExecutor in project Minigames by AddstarMC.
the class MenuItemRegion method createMenu.
public static Menu createMenu(MinigamePlayer viewer, Menu previousPage, Region region) {
Menu m = new Menu(3, "Region: " + region.getName(), viewer);
m.setPreviousPage(previousPage);
List<MenuItem> items = new ArrayList<>();
for (RegionExecutor ex : region.getExecutors()) {
items.add(new MenuItemRegionExecutor(region, ex));
}
if (previousPage != null) {
m.addItem(new MenuItemPage("Back", Material.REDSTONE_TORCH_ON, previousPage), m.getSize() - 9);
}
m.addItem(new MenuItemRegionExecutorAdd("Add Executor", Material.ITEM_FRAME, region), m.getSize() - 1);
m.addItems(items);
return m;
}
Aggregations