-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98ab6ae
commit 28d9104
Showing
16 changed files
with
724 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package net.avicus.atlas.sets.competitve.objectives.zones; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import lombok.ToString; | ||
import net.avicus.atlas.match.Match; | ||
import net.avicus.atlas.module.checks.Check; | ||
import net.avicus.atlas.module.checks.CheckContext; | ||
import net.avicus.atlas.module.checks.variable.LocationVariable; | ||
import net.avicus.atlas.module.checks.variable.PlayerVariable; | ||
import net.avicus.atlas.module.groups.Competitor; | ||
import net.avicus.atlas.module.groups.GroupsModule; | ||
import net.avicus.atlas.module.objectives.ObjectivesModule; | ||
import net.avicus.atlas.module.zones.Zone; | ||
import net.avicus.atlas.module.zones.ZoneMessage; | ||
import net.avicus.atlas.util.Messages; | ||
import net.avicus.compendium.TextStyle; | ||
import net.avicus.compendium.inventory.SingleMaterialMatcher; | ||
import net.avicus.compendium.locale.text.Localizable; | ||
import net.avicus.compendium.locale.text.LocalizedNumber; | ||
import net.avicus.compendium.locale.text.UnlocalizedText; | ||
import net.avicus.compendium.number.NumberAction; | ||
import net.avicus.magma.util.region.Region; | ||
import org.bukkit.Location; | ||
import org.bukkit.Material; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.player.PlayerTeleportEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
import tc.oc.tracker.event.PlayerCoarseMoveEvent; | ||
|
||
@ToString | ||
public class ScoreZone extends Zone { | ||
|
||
private final int points; | ||
private final NumberAction scoreModifier; | ||
private final Optional<Double> pointsGrowth; | ||
private final Optional<Check> check; | ||
private final Optional<HashMap<Material, HashMap<SingleMaterialMatcher, Integer>>> itemRewards; | ||
private double nextPoints; | ||
|
||
public ScoreZone(Match match, Region region, Optional<ZoneMessage> message, int points, | ||
NumberAction scoreModifier, Optional<Double> pointsGrowth, Optional<Check> check, | ||
Optional<HashMap<Material, HashMap<SingleMaterialMatcher, Integer>>> itemRewards) { | ||
super(match, region, message); | ||
this.points = points; | ||
this.scoreModifier = scoreModifier; | ||
this.pointsGrowth = pointsGrowth; | ||
this.check = check; | ||
this.itemRewards = itemRewards; | ||
this.nextPoints = points; | ||
} | ||
|
||
@Override | ||
public boolean isActive() { | ||
return this.points > 0; | ||
} | ||
|
||
public int reward(Match match, Competitor competitor, Player player) { | ||
int points = (int) Math.floor(this.nextPoints); | ||
|
||
if (this.itemRewards.isPresent()) { | ||
// Top level generic material in order to easily find in a list of ItemStacks | ||
// We then retrieve the material matcher in order to narrow down the result scope | ||
// If the material matcher passes, the points associated with the material are added to the points value. | ||
HashMap<Material, HashMap<SingleMaterialMatcher, Integer>> rewardStacks = itemRewards.get(); | ||
List<ItemStack> invContents = Arrays.asList(player.getInventory().getContents()); | ||
List<ItemStack> armorContents = Arrays.asList(player.getInventory().getArmorContents()); | ||
|
||
// Prevent sneaky players from spreading out | ||
// items across multiple slots in order to gain more points. | ||
List<ItemStack> found = new ArrayList<>(); | ||
|
||
List<ItemStack> contents = new ArrayList<>(); | ||
contents.addAll(invContents); | ||
contents.addAll(armorContents); | ||
|
||
for (ItemStack stack : contents) { | ||
if (stack == null || stack.getType().equals(Material.AIR)) { | ||
continue; | ||
} | ||
|
||
if (!rewardStacks.containsKey(stack.getType()) || found.contains(stack)) { | ||
continue; | ||
} | ||
|
||
HashMap<SingleMaterialMatcher, Integer> matcherPointMap = rewardStacks.get(stack.getType()); | ||
|
||
for (Map.Entry<SingleMaterialMatcher, Integer> entry : matcherPointMap.entrySet()) { | ||
if (entry.getKey().matches(stack.getType(), stack.getData().getData())) { | ||
points = points + entry.getValue(); | ||
found.add(stack); | ||
} | ||
} | ||
} | ||
} | ||
|
||
match.getRequiredModule(ObjectivesModule.class) | ||
.score(competitor, points, scoreModifier, player); | ||
|
||
if (this.pointsGrowth.isPresent()) { | ||
this.nextPoints *= this.pointsGrowth.get(); | ||
} | ||
return points; | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) | ||
public void onMove(PlayerCoarseMoveEvent event) { | ||
handle(event.getPlayer(), event.getFrom(), event.getTo()); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) | ||
public void onTP(PlayerTeleportEvent event) { | ||
handle(event.getPlayer(), event.getFrom(), event.getTo()); | ||
} | ||
|
||
public void handle(Player player, Location fromLoc, Location toLoc) { | ||
if (isObserving(this.match, player)) { | ||
return; | ||
} | ||
|
||
boolean from = getRegion().contains(fromLoc); | ||
|
||
if (from) { | ||
return; | ||
} | ||
|
||
boolean to = getRegion().contains(toLoc); | ||
|
||
if (to) { | ||
Competitor competitor = match.getRequiredModule(GroupsModule.class).getCompetitorOf(player) | ||
.orElse(null); | ||
|
||
if (competitor == null) { | ||
return; | ||
} | ||
|
||
if (this.check.isPresent()) { | ||
CheckContext context = new CheckContext(this.match); | ||
context.add(new PlayerVariable(player)); | ||
context.add(new LocationVariable(toLoc)); | ||
if (this.check.get().test(context).fails()) { | ||
return; | ||
} | ||
} | ||
|
||
int scored = reward(this.match, competitor, player); | ||
|
||
if (this.scoreModifier.equals(NumberAction.ADD)) { | ||
Localizable points = new LocalizedNumber(scored, | ||
TextStyle.ofColor(competitor.getChatColor())); | ||
Localizable name = new UnlocalizedText(player.getName(), | ||
TextStyle.ofColor(competitor.getChatColor())); | ||
|
||
if (scored == 1) { | ||
this.match.broadcast(Messages.GENERIC_OBJECTIVE_SCORED.with(points, name)); | ||
} else { | ||
this.match.broadcast(Messages.GENERIC_OBJECTIVE_SCORED_PLURAL.with(points, name)); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.row-fluid | ||
.span4 | ||
%h4 Miscellaneous | ||
%p Name | ||
= f.text_field :name, :disabled => @editable.include?(:name) ? nil : '' | ||
%p Inheritance | ||
%select{name: 'rank[inheritance_id]', :disabled => @editable.include?(:inheritance) ? nil : ''} | ||
%option{:value => '', :selected => (@rank.inheritance.nil? ? '' : nil)} | ||
\- No Inheritance - | ||
- Rank.all.order('priority DESC').each do |r| | ||
- next if r == @rank | ||
%option{:value => r.id, :selected => (@rank.inheritance_id == r.id ? '' : nil)}=r.name | ||
%p Priority | ||
= f.text_field :priority, :style => 'width: 57px;', :disabled => @editable.include?(:priority) ? nil : '' | ||
%p Appear on staff page | ||
= f.check_box :is_staff, :disabled => @editable.include?(:is_staff) ? nil : '' | ||
.span4 | ||
%h4 Website Display | ||
%p HTML Color Code (With the #) | ||
= f.text_field :html_color, :style => 'width: 77px;', :disabled => @editable.include?(:html_color) ? nil : '' | ||
%p Badge HTML Color Code (With the #) | ||
= f.text_field :badge_color, :style => 'width: 77px;', :disabled => @editable.include?(:badge_color) ? nil : '' | ||
%p Badge Text HTML Color Code (With the #) | ||
= f.text_field :badge_text_color, :style => 'width: 77px;', :disabled => @editable.include?(:badge_text_color) ? nil : '' | ||
.span4 | ||
%h4 In Game | ||
%p Prefix | ||
= f.text_field :mc_prefix, :style => 'width: 97px;', :disabled => @editable.include?(:mc_prefix) ? nil : '' | ||
%p Suffix | ||
= f.text_field :mc_suffix, :style => 'width: 97px;', :disabled => @editable.include?(:mc_suffix) ? nil : '' | ||
%br | ||
= f.submit :class => 'btn btn-primary' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
= content_for :title, 'Rank Management' | ||
|
||
= render 'admin/heads/index', subject: 'Rank' | ||
|
||
%section.section-padded | ||
.container-fluid | ||
.table-responsive | ||
%table.table.table-striped.table-bordered | ||
%thead | ||
%tr | ||
%th{:style => 'width: 80px'} Perms Only | ||
%th Name | ||
%th{:style => 'width: 50px'} Priority | ||
%th{:style => 'width: 30px'} Staff | ||
%th{:style => 'width: 150px'} Permanent Members | ||
%th{:style => 'width: 110px'} Timed Members | ||
%th | ||
%tbody | ||
- @ranks.each do |rank| | ||
- next unless (rank.can_execute?(current_user, :rank, :update) || rank.can_execute?(current_user, :rank, :destroy)) | ||
%tr | ||
%td | ||
= boolean_to_symbol(rank.perms_only?, true) | ||
%td{:style => "color: #{rank.html_color}" } | ||
= rank.name | ||
%td | ||
= rank.priority | ||
%td | ||
= boolean_to_symbol(rank.is_staff, true) | ||
%td | ||
= rank.members.size | ||
%td | ||
= rank.timed_members.size | ||
%td | ||
- if rank.can_execute?(current_user, :rank, :update) | ||
= link_to 'Edit', admin_rank_path(rank), :class => 'btn btn-mini btn-info' | ||
- if rank.can_execute?(current_user, :rank, :create) | ||
= link_to 'Copy', admin_rank_copy_path(rank), class: 'btn btn-mini btn-primary' | ||
- if rank.can_execute?(current_user, :rank, :destroy) | ||
= link_to 'Delete', [:admin, rank], method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-mini btn-danger' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
- content_for :title, 'Admin - Ranks - New' | ||
|
||
%section.section-dark.main-header | ||
.container-fluid | ||
.row-fluid | ||
.span12 | ||
%h1 | ||
New Rank | ||
|
||
%br | ||
= @rank.errors.full_messages.each do |msg| | ||
%li #{msg} | ||
%section | ||
.container-fluid | ||
.alert.alert-info.no-margin{:style => 'margin: 0'} | ||
More options will be available after rank creation | ||
= form_for [:admin, @rank] do |f| | ||
= render 'admin/ranks/misc', :f => f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
- members = @api_gen.parent_group.members | ||
- members.sort! { |a,b| a.text.downcase <=> b.text.downcase } | ||
.span2 | ||
%ul.nav.nav-pills.nav-stacked{:role => 'tablist'} | ||
%li{:role => 'presentation'} | ||
- members.each do |api_class| | ||
- next unless api_class.is_a?(PermissionGroup) | ||
%li{:role => 'presentation'} | ||
%a{'aria-controls' => "#{api_class.ident.to_s}", 'data-toggle' => 'tab', :href => "##{api_class.ident.to_s}", :role => 'tab'}=api_class.text | ||
.tab-content | ||
- members.each do |api_class| | ||
- next unless api_class.is_a?(PermissionGroup) | ||
.tab-pane{:id => "#{api_class.ident.to_s}", :role => 'tabpanel'} | ||
= perm_group(api_class) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.span2 | ||
%ul.nav.nav-pills.nav-stacked{:role => 'tablist'} | ||
%li{:role => 'presentation'} | ||
%a{'aria-controls' => "#{@global_cat.id.to_s}", 'data-toggle' => 'tab', :href => "##{@global_cat.id.to_s}", :role => 'tab'}=@global_cat.name | ||
- @forums.each do |forum| | ||
- next if forum.categories.all.nil? | ||
= forum.name | ||
- forum.categories.all.each do |cat| | ||
%li{:role => 'presentation'} | ||
%a{'aria-controls' => "#{cat.id.to_s}", 'data-toggle' => 'tab', :href => "##{cat.id.to_s}", :role => 'tab'}=cat.name | ||
.tab-content | ||
.tab-pane{:id => "#{@global_cat.id.to_s}", :role => 'tabpanel'} | ||
= perm_group(@forum_gen, true, 'all') | ||
- Category.all.each do |cat| | ||
.tab-pane{:id => "#{cat.id.to_s}", :role => 'tabpanel'} | ||
= perm_group(@forum_gen, true, cat.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.span2 | ||
%ul.nav.nav-pills.nav-stacked{:role => 'tablist'} | ||
- ServerCategory.all.each do |cat| | ||
%li{:role => 'presentation'} | ||
%a{'aria-controls' => "ig-special-#{cat.id.to_s}", 'data-toggle' => 'tab', :href => "#ig-special-#{cat.id.to_s}", :role => 'tab'}=cat.name | ||
.tab-content | ||
- ServerCategory.all.each do |cat| | ||
.tab-pane{:id => "ig-special-#{cat.id.to_s}", :role => 'tabpanel'} | ||
%h4 These permissions apply to any server in the #{cat.name} category | ||
- val = @special_perms[cat.id.to_s] | ||
- val = val.nil? ? '' : val.join("\n") | ||
%textarea{name: "rank[special][#{cat.id}]", style: 'width: 560px; height: 366px;'}= val | ||
|
||
%br |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.span2 | ||
%ul.nav.nav-pills.nav-stacked{:role => 'tablist'} | ||
- Avicus::Application.config.web_perms.each do |g| | ||
- next if g.id_based | ||
- next if g == @api_gen | ||
%li{:role => 'presentation'} | ||
- human = g.parent_group.text unless g.parent_group.text.nil? | ||
- human = g.model_name.pluralize.tr('::', ' ').tr('_', ' ') if human.nil? | ||
%a{'aria-controls' => "misc-#{g.model_name.downcase.tr('::', '_').tr(' ', '_').tr('/', '_')}", 'data-toggle' => 'tab', :href => "#misc-#{g.model_name.to_s.downcase.tr('::', '_').tr(' ', '_').tr('/', '_')}", :role => 'tab'}=titleize(human) | ||
.tab-content | ||
- Avicus::Application.config.web_perms.each do |g| | ||
- next if g.id_based | ||
- next if g == @api_gen | ||
.tab-pane{:id => "misc-#{g.model_name.downcase.tr('::', '_').tr(' ', '_').tr('/', '_')}", :role => 'tabpanel'} | ||
= perm_group(g) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.span2 | ||
%ul.nav.nav-pills.nav-stacked{:role => 'tablist'} | ||
- @ranks.each do |rank| | ||
%li{:role => 'presentation'} | ||
%a{'aria-controls' => "rank-#{rank.id}", 'data-toggle' => 'tab', :href => "#rank-#{rank.id}", :role => 'tab'}=rank.name | ||
.tab-content | ||
- @ranks.each do |rank| | ||
.tab-pane{:id => "rank-#{rank.id}", :role => 'tabpanel'} | ||
= perm_group(@rank_gen, true, rank.id == 0? 'all' : rank.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.span3 | ||
- if text == desc | ||
= titleize(text) | ||
- else | ||
%p{:rel => 'tooltip', :title => desc} | ||
= titleize(text) | ||
- selection = @rank.get_permission_raw(path) | ||
- selection = default if selection.nil? | ||
- if options.include?(:USER_VALUE) | ||
%input{:name => "rank[web_perms]#{string_path}", :style => 'width: 150px', :type => 'text', :value => "#{selection}"} | ||
- else | ||
%select{:name => "rank[web_perms]#{string_path}"} | ||
- options.each do |opt| | ||
- text = determine_text(opt) | ||
%option{:value => opt, :selected => (selection.to_s == opt.to_s ? '' : nil)} | ||
= titleize(text) |
Oops, something went wrong.