Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Cleanup scorebox parsing & fix regions only parsing first child
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablete1234 committed Jun 2, 2016
1 parent a24c24f commit 9d764e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static RegionModule getRegion(Element element, Document document) {
return region;
case "union":
case "regions":
region = new UnionRegion( new CombinationParser(element, document));
region = new UnionRegion(new CombinationParser(element, document));
if (region.getName() != null) GameHandler.getGameHandler().getMatch().getModules().add(region);
return region;
case "translate":
Expand Down Expand Up @@ -145,8 +145,8 @@ public static RegionModule getRegion(Element element, Document document) {
return regionModule;
}
}
} else {
return getRegion(element.getChildren().get(0));
} else if (element.getChildren().size() > 0) {
return new UnionRegion(new CombinationParser(element, document));
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import in.twizmwaz.cardinal.module.Module;
import in.twizmwaz.cardinal.module.modules.filter.FilterModule;
import in.twizmwaz.cardinal.module.modules.filter.FilterState;
import in.twizmwaz.cardinal.module.modules.observers.ObserverModule;
import in.twizmwaz.cardinal.module.modules.regions.RegionModule;
import in.twizmwaz.cardinal.module.modules.score.ScoreModule;
import in.twizmwaz.cardinal.module.modules.team.TeamModule;
Expand Down Expand Up @@ -44,7 +45,7 @@ public void unload() {
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerMove(PlayerMoveEvent event) {
if (GameHandler.getGameHandler().getMatch().isRunning() && region.contains(event.getTo().toVector()) && !region.contains(event.getFrom().toVector()) &&
(filter == null || filter.evaluate(event.getPlayer()).equals(FilterState.ALLOW)) && event.getPlayer().getHealth() > 0) {
(filter == null || filter.evaluate(event.getPlayer()).equals(FilterState.ALLOW)) && !ObserverModule.testObserverOrDead(event.getPlayer())) {
int points = 0;
if (redeemables.size() > 0) {
for (ItemStack item : redeemables.keySet()) {
Expand All @@ -64,15 +65,14 @@ public void onPlayerMove(PlayerMoveEvent event) {
if (points != 0 && playerTeam.isPresent()) {
for (ScoreModule score : GameHandler.getGameHandler().getMatch().getModules().getModules(ScoreModule.class)) {
if (score.getTeam() == playerTeam.get()) {
score.setScore(score.getScore() + points);
ChatUtil.getGlobalChannel().sendLocalizedMessage(new UnlocalizedChatMessage(ChatColor.GRAY + "{0}",
new LocalizedChatMessage(ChatConstant.UI_SCORED_FOR,
new UnlocalizedChatMessage(playerTeam.get().getColor() + event.getPlayer().getName() + ChatColor.GRAY),
new UnlocalizedChatMessage(ChatColor.DARK_AQUA + "{0}" + ChatColor.GRAY, points == 1 ? new LocalizedChatMessage(ChatConstant.UI_ONE_POINT) : new LocalizedChatMessage(ChatConstant.UI_POINTS, points + "" + ChatColor.GRAY)),
new UnlocalizedChatMessage(playerTeam.get().getCompleteName()))));
score.addScore(points);
}
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import in.twizmwaz.cardinal.module.modules.filter.FilterModuleBuilder;
import in.twizmwaz.cardinal.module.modules.regions.RegionModule;
import in.twizmwaz.cardinal.module.modules.regions.RegionModuleBuilder;
import in.twizmwaz.cardinal.module.modules.regions.type.combinations.UnionRegion;
import in.twizmwaz.cardinal.util.Numbers;
import in.twizmwaz.cardinal.util.Parser;
import org.bukkit.inventory.ItemStack;
Expand All @@ -22,30 +21,9 @@ public ModuleCollection<Scorebox> load(Match match) {
ModuleCollection<Scorebox> results = new ModuleCollection<>();
for (Element score : match.getDocument().getRootElement().getChildren("score")) {
for (Element box : score.getChildren("box")) {
RegionModule region;
if (box.getAttributeValue("region") != null) {
region = RegionModuleBuilder.getRegion(box);
} else {
ModuleCollection<RegionModule> queued = new ModuleCollection<>();
for (Element child : box.getChildren()) {
queued.add(RegionModuleBuilder.getRegion(child));
}
region = new UnionRegion(null, queued);
}
int points = 0;
if (box.getAttributeValue("points") != null) {
points = Numbers.parseInt(box.getAttributeValue("points"));
} else if (box.getAttributeValue("value") != null) {
points = Numbers.parseInt(box.getAttributeValue("value"));
}
FilterModule filter = null;
if (box.getAttributeValue("filter") != null) {
filter = FilterModuleBuilder.getFilter(box.getAttributeValue("filter"));
} else {
for (Element child : box.getChildren("filter")) {
filter = FilterModuleBuilder.getFilter(child);
}
}
RegionModule region = RegionModuleBuilder.getAttributeOrChild("region", box);
int points = Numbers.parseInt(Parser.getOrderedAttribute("points", box), Numbers.parseInt(box.getAttributeValue("value"), 0));
FilterModule filter = FilterModuleBuilder.getAttributeOrChild("filter", box);
HashMap<ItemStack, Integer> redeemables = new HashMap<>();
for (Element child : box.getChildren("redeemables")) {
for (Element item : child.getChildren("item")) {
Expand Down

0 comments on commit 9d764e9

Please sign in to comment.