Skip to content

Commit 941fd4e

Browse files
Pablete1234twizmwazin
authored andcommitted
Add applied regions
1 parent 5443aac commit 941fd4e

31 files changed

+1507
-493
lines changed

src/main/java/in/twizmwaz/cardinal/module/apply/AppliedModule.java

+618
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/*
2+
* Copyright (c) 2016, Kevin Phoenix
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
package in.twizmwaz.cardinal.module.apply;
27+
28+
import ee.ellytr.chat.component.formattable.UnlocalizedComponent;
29+
import in.twizmwaz.cardinal.module.filter.Filter;
30+
import in.twizmwaz.cardinal.module.filter.FilterState;
31+
import in.twizmwaz.cardinal.module.kit.Kit;
32+
import in.twizmwaz.cardinal.module.kit.KitRemovable;
33+
import in.twizmwaz.cardinal.module.region.Region;
34+
import in.twizmwaz.cardinal.module.region.RegionBounds;
35+
import in.twizmwaz.cardinal.util.Channels;
36+
import in.twizmwaz.cardinal.util.Components;
37+
import lombok.AccessLevel;
38+
import lombok.AllArgsConstructor;
39+
import lombok.Getter;
40+
import net.md_5.bungee.api.chat.BaseComponent;
41+
import org.bukkit.block.Block;
42+
import org.bukkit.entity.Player;
43+
import org.bukkit.util.Vector;
44+
45+
import java.util.Collection;
46+
47+
@AllArgsConstructor(access = AccessLevel.PRIVATE)
48+
public class AppliedRegion implements Region, Filter, KitRemovable {
49+
50+
@Getter
51+
private final ApplyType type;
52+
private final Region region;
53+
private final Filter filter;
54+
55+
private final Kit kit;
56+
private final Vector velocity;
57+
@Getter
58+
private final BaseComponent message;
59+
@Getter
60+
private final boolean earlyWarning;
61+
62+
public AppliedRegion(ApplyType type, Region region, Filter filter, String message) {
63+
this(type, region, filter, message, false);
64+
}
65+
66+
public AppliedRegion(ApplyType type, Region region, Filter filter, String message, boolean earlyWarning) {
67+
this(type, region, filter, message == null ? null : new UnlocalizedComponent(message), earlyWarning);
68+
}
69+
70+
public AppliedRegion(ApplyType type, Region region, Filter filter, BaseComponent message) {
71+
this(type, region, filter, message, false);
72+
}
73+
74+
public AppliedRegion(ApplyType type, Region region, Filter filter, BaseComponent message, boolean earlyWarning) {
75+
this(type, region, filter, null, null, message == null ? null : Components.getWarningComponent(message),
76+
earlyWarning);
77+
}
78+
79+
public AppliedRegion(ApplyType type, Region region, Filter filter, Kit kit) {
80+
this(type, region, filter, kit, null, null, false);
81+
}
82+
83+
public AppliedRegion(Region region, Filter filter, Vector velocity) {
84+
this(ApplyType.VELOCITY, region, filter, null, velocity, null, false);
85+
}
86+
87+
public boolean isType(ApplyType type) {
88+
return this.type.equals(type);
89+
}
90+
91+
/**
92+
* Sends the message for this region to the player as long as both message and player aren't null.
93+
* @param player The player to send the message to.
94+
*/
95+
public void sendMessage(Player player) {
96+
if (message != null && player != null) {
97+
Channels.getPlayerChannel(player).sendMessage(message);
98+
}
99+
}
100+
101+
/**
102+
* Applies the effects in this region (kits or velocity) to a player if the filter allows it.
103+
* @param player The player to apply effect on.
104+
* @param objects The object to pass to the filter.
105+
*/
106+
public void applyEffects(Player player, Object... objects) {
107+
if (evaluate(objects).toBoolean()) {
108+
if (isType(ApplyType.VELOCITY)) {
109+
player.applyImpulse(velocity);
110+
} else if (kit != null) {
111+
kit.apply(player, false);
112+
}
113+
}
114+
}
115+
116+
/* KitRemovable interface */
117+
@Override
118+
public void apply(Player player, boolean force) {
119+
kit.apply(player, force);
120+
}
121+
122+
@Override
123+
public void remove(Player player) {
124+
if (isType(ApplyType.KIT_LEND) && kit instanceof KitRemovable) {
125+
((KitRemovable) kit).remove(player);
126+
}
127+
}
128+
129+
/* Filter interface */
130+
@Override
131+
public FilterState evaluate(Object... objects) {
132+
return filter.evaluate(objects);
133+
}
134+
135+
/* Region interface */
136+
@Override
137+
public boolean contains(Vector vector) {
138+
return region.contains(vector);
139+
}
140+
141+
@Override
142+
public boolean isRandomizable() {
143+
return region.isRandomizable();
144+
}
145+
146+
@Override
147+
public boolean isBounded() {
148+
return region.isBounded();
149+
}
150+
151+
@Override
152+
public RegionBounds getBounds() {
153+
return region.getBounds();
154+
}
155+
156+
@Override
157+
public Collection<Block> getBlocks() {
158+
return region.getBlocks();
159+
}
160+
161+
@Override
162+
public Vector getRandomPoint() {
163+
return region.getRandomPoint();
164+
}
165+
166+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2016, Kevin Phoenix
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
package in.twizmwaz.cardinal.module.apply;
27+
28+
import lombok.AllArgsConstructor;
29+
30+
@AllArgsConstructor
31+
public enum ApplyType {
32+
33+
ENTER("enter"),
34+
LEAVE("leave"),
35+
BLOCK("block"),
36+
BLOCK_PLACE("block-place"),
37+
BLOCK_PLACE_AGAINST("block-place-against"),
38+
BLOCK_BREAK("block-break"),
39+
BLOCK_PHYSICS("block-physics"),
40+
USE("use"),
41+
MOBS("mobs"),
42+
KIT("filter", "kit"),
43+
KIT_LEND("filter", "lend-kit"),
44+
VELOCITY("filter", "velocity");
45+
46+
public final String filterAttr;
47+
public final String otherAttr;
48+
public final boolean filterOnly;
49+
50+
private ApplyType(String filterAttr) {
51+
this(filterAttr, null, true);
52+
}
53+
54+
private ApplyType(String filterAttr, String otherAttr) {
55+
this(filterAttr, otherAttr, false);
56+
}
57+
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright (c) 2016, Kevin Phoenix
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
package in.twizmwaz.cardinal.module.apply.regions;
27+
28+
import ee.ellytr.chat.ChatConstant;
29+
import ee.ellytr.chat.component.builder.LocalizedComponentBuilder;
30+
import in.twizmwaz.cardinal.component.TeamComponentBuilder;
31+
import in.twizmwaz.cardinal.module.apply.AppliedRegion;
32+
import in.twizmwaz.cardinal.module.apply.ApplyType;
33+
import in.twizmwaz.cardinal.module.filter.type.MaterialFilter;
34+
import in.twizmwaz.cardinal.module.filter.type.TeamFilter;
35+
import in.twizmwaz.cardinal.module.filter.type.modifiers.AllFilter;
36+
import in.twizmwaz.cardinal.module.objective.wool.Wool;
37+
import in.twizmwaz.cardinal.module.team.Team;
38+
import in.twizmwaz.cardinal.util.Channels;
39+
import in.twizmwaz.cardinal.util.Components;
40+
import in.twizmwaz.cardinal.util.MaterialPattern;
41+
import net.md_5.bungee.api.ChatColor;
42+
import net.md_5.bungee.api.chat.BaseComponent;
43+
import org.bukkit.Material;
44+
import org.bukkit.entity.Player;
45+
46+
47+
public class WoolMonumentPlace extends AppliedRegion {
48+
49+
private final Team team;
50+
private final BaseComponent wrongTeam;
51+
private final boolean show;
52+
53+
/**
54+
* Will create a wool monument applied region, that allows only the wool type to be placed by the correct team.
55+
* Custom messages for wrong team and wrong block will be sent to the player only if {@link Wool#isShow()};
56+
*
57+
* @param wool The wool to make the applied region for.
58+
*/
59+
public WoolMonumentPlace(Wool wool) {
60+
super(ApplyType.BLOCK_PLACE, wool.getMonument(),
61+
new AllFilter(
62+
new MaterialFilter(
63+
MaterialPattern.getSingleMaterialPattern(Material.WOOL, (int) wool.getColor().getWoolData())),
64+
new TeamFilter(wool.getTeam())),
65+
new LocalizedComponentBuilder(
66+
ChatConstant.getConstant("objective.wool.error.block"),
67+
wool.getComponent()
68+
).color(ChatColor.RED).build());
69+
team = wool.getTeam();
70+
wrongTeam = Components.getWarningComponent(new LocalizedComponentBuilder(
71+
ChatConstant.getConstant("objective.wool.error.team"),
72+
new TeamComponentBuilder(wool.getTeam()).build(),
73+
wool.getComponent()
74+
).color(ChatColor.RED).build());
75+
show = wool.isShow();
76+
}
77+
78+
@Override
79+
public void sendMessage(Player player) {
80+
if (!show) {
81+
return;
82+
}
83+
if (team.hasPlayer(player)) {
84+
super.sendMessage(player);
85+
} else {
86+
Channels.getPlayerChannel(player).sendMessage(wrongTeam);
87+
}
88+
}
89+
90+
}

src/main/java/in/twizmwaz/cardinal/module/channel/ChannelModule.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import in.twizmwaz.cardinal.module.event.ModuleLoadCompleteEvent;
3939
import in.twizmwaz.cardinal.module.rotation.RotationModule;
4040
import in.twizmwaz.cardinal.module.team.Team;
41+
import in.twizmwaz.cardinal.module.team.TeamModule;
4142
import lombok.NonNull;
4243
import org.bukkit.entity.Player;
4344
import org.bukkit.event.EventHandler;
@@ -49,7 +50,7 @@
4950
import java.util.List;
5051
import java.util.Map;
5152

52-
@ModuleEntry(depends = {RotationModule.class})
53+
@ModuleEntry(depends = {RotationModule.class, TeamModule.class})
5354
public class ChannelModule extends AbstractModule implements Listener {
5455

5556
private Map<MatchThread, GlobalChannel> globalChannels = Maps.newHashMap();
@@ -108,6 +109,7 @@ public boolean loadMatch(@NonNull Match match) {
108109
Cardinal.registerEvents(channel);
109110
teamChannels.add(channel);
110111
}
112+
this.teamChannels.put(match, teamChannels);
111113
return true;
112114
}
113115

src/main/java/in/twizmwaz/cardinal/module/filter/type/CreatureFilter.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.bukkit.entity.Creature;
2929
import org.bukkit.entity.Entity;
30+
import org.bukkit.entity.EntityType;
3031

3132
public class CreatureFilter extends ObjectTypeFilter<Entity> {
3233

@@ -37,7 +38,7 @@ public Class<Entity> getType() {
3738

3839
@Override
3940
public Boolean evaluate(Entity entity) {
40-
return entity instanceof Creature;
41+
return entity instanceof Creature || entity.getType().equals(EntityType.SLIME); // Slimes extend Living entity
4142
}
4243

4344
}

src/main/java/in/twizmwaz/cardinal/module/filter/type/MaterialFilter.java

+8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
import lombok.AllArgsConstructor;
3131
import org.bukkit.Material;
3232
import org.bukkit.block.Block;
33+
import org.bukkit.block.BlockState;
3334
import org.bukkit.inventory.ItemStack;
35+
import org.bukkit.material.MaterialData;
3436

3537
@AllArgsConstructor
3638
public class MaterialFilter extends SingleObjectFilter {
@@ -44,6 +46,12 @@ public FilterState evaluate(Object evaluating) {
4446
return FilterState.fromBoolean(material.contains(block.getType(), block.getData()));
4547
} else if (evaluating instanceof Material) {
4648
return FilterState.fromBoolean(material.contains((Material) evaluating, -1));
49+
} else if (evaluating instanceof BlockState) {
50+
return FilterState.fromBoolean(
51+
material.contains(((BlockState) evaluating).getMaterial(), ((BlockState) evaluating).getRawData()));
52+
} else if (evaluating instanceof MaterialData) {
53+
return FilterState.fromBoolean(
54+
material.contains(((MaterialData) evaluating).getItemType(), ((MaterialData) evaluating).getData()));
4755
} else if (evaluating instanceof ItemStack) {
4856
return FilterState.fromBoolean(material.contains((ItemStack) evaluating));
4957
}

src/main/java/in/twizmwaz/cardinal/module/filter/type/MonsterFilter.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package in.twizmwaz.cardinal.module.filter.type;
2727

2828
import org.bukkit.entity.Entity;
29+
import org.bukkit.entity.EntityType;
2930
import org.bukkit.entity.Monster;
3031

3132
public class MonsterFilter extends ObjectTypeFilter<Entity> {
@@ -37,7 +38,7 @@ public Class<Entity> getType() {
3738

3839
@Override
3940
public Boolean evaluate(Entity entity) {
40-
return entity instanceof Monster;
41+
return entity instanceof Monster || entity.getType().equals(EntityType.SLIME); // Slimes extend Living entity
4142
}
4243

4344
}

0 commit comments

Comments
 (0)