Skip to content

Commit 970bcbd

Browse files
committed
Clip to Magazine, to be more accurate.
1 parent 0729588 commit 970bcbd

File tree

19 files changed

+415
-415
lines changed

19 files changed

+415
-415
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ If you enable them in config, players can get guns using the following simple co
1010

1111
**/gun** -- presents a menu with all configured guns
1212

13-
**/clip** -- some guns aren't loaded directly, but via "clips" or magazines of bullets, this command brings up a menu to pick 'em
13+
**/magazine** -- some guns aren't loaded directly, but via "magazines" of bullets, this command brings up a menu to pick 'em
1414

1515
**/bullet** -- guns need bullets to fire, brings up a menu showing all configured bullets.
1616

1717
### Loading
1818
-----------
1919

20-
To load bullets into guns or clips, pick up the bullets. While holding them, right click the clip, or gun, as indicated.
20+
To load bullets into guns or magazines, pick up the bullets. While holding them, right click the magazine, or gun, as indicated.
2121

22-
Pay attention to the lore on the gun / clip -- it'll tell you if it can hold the bullets you've picked up or not.
22+
Pay attention to the lore on the gun / magazine -- it'll tell you if it can hold the bullets you've picked up or not.
2323

24-
To load clips into guns, pick up the clip, and right click the gun. If a clip is already loaded, it will be swapped out with the one you are holding.
24+
To load magazines into guns, pick up the magazine, and right click the gun. If a magazine is already loaded, it will be swapped out with the one you are holding.
2525

26-
If you've "locked" a clip to a particular bullet type, but the clip is now empty, right click the clip with nothing in your hand, to "free it" for other
26+
If you've "locked" a magazine to a particular bullet type, but the magazine is now empty, right click the magazine with nothing in your hand, to "free it" for other
2727
kinds of bullets.
2828

2929
### Repair

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>com.programmerdan.minecraft</groupId>
66
<artifactId>addgun</artifactId>
77
<packaging>jar</packaging>
8-
<version>0.1.0</version>
8+
<version>0.2.0</version>
99
<name>AddGun</name>
1010
<url>https://github.com/ProgrammerDan/AddGun</url>
1111

@@ -98,7 +98,7 @@
9898
<dependency>
9999
<groupId>org.spigotmc</groupId>
100100
<artifactId>spigot</artifactId>
101-
<version>1.12-R0.1-SNAPSHOT</version>
101+
<version>1.12.2-R0.1-SNAPSHOT</version>
102102
<scope>provided</scope>
103103
</dependency>
104104
<dependency>

src/main/java/com/programmerdan/minecraft/addgun/AddGun.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.google.common.reflect.ClassPath;
2222
import com.programmerdan.minecraft.addgun.ammo.Bullet;
2323
import com.programmerdan.minecraft.addgun.ammo.Bullets;
24-
import com.programmerdan.minecraft.addgun.ammo.Clip;
24+
import com.programmerdan.minecraft.addgun.ammo.Magazine;
2525
import com.programmerdan.minecraft.addgun.commands.CommandHandler;
2626
import com.programmerdan.minecraft.addgun.guns.BasicGun;
2727
import com.programmerdan.minecraft.addgun.guns.Guns;
@@ -186,22 +186,22 @@ private void addBullets(FileConfiguration config) {
186186
}
187187
}
188188

189-
ConfigurationSection clips = config.getConfigurationSection("clips");
190-
if (clips == null || clips.getKeys(false) == null) {
191-
this.warning("No clips enabled.");
189+
ConfigurationSection magazines = config.getConfigurationSection("magazines");
190+
if (magazines == null || magazines.getKeys(false) == null) {
191+
this.warning("No magazines enabled.");
192192
}
193193

194-
for (String clipName : clips.getKeys(false)) {
194+
for (String magName : magazines.getKeys(false)) {
195195
try {
196-
Clip clip = new Clip(clips.getConfigurationSection(clipName));
196+
Magazine magazine = new Magazine(magazines.getConfigurationSection(magName));
197197

198-
this.ammo.registerClip(clip);
198+
this.ammo.registerMagazine(magazine);
199199
} catch (Exception e) {
200-
warning("Failed to register clip {0} due to error {1}", clipName, e);
200+
warning("Failed to register magazine {0} due to error {1}", magName, e);
201201
}
202202
}
203203

204-
if (this.ammo.hasClips()) {
204+
if (this.ammo.hasMagazines()) {
205205
this.getServer().getPluginManager().registerEvents(this.ammo, this);
206206
}
207207
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.programmerdan.minecraft.addgun.ammo;
22

33
public enum AmmoType {
4-
CLIP,
4+
MAGAZINE,
55
BULLET,
66
INVENTORY
77
}

src/main/java/com/programmerdan/minecraft/addgun/ammo/Bullet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import com.programmerdan.minecraft.addgun.guns.HitPart;
4141

4242
/**
43-
* Represents a single bullet type that can match against standard ammo, be aggregated into clips or directly loaded into a gun.
43+
* Represents a single bullet type that can match against standard ammo, be aggregated into magazines or directly loaded into a gun.
4444
*
4545
* @author ProgrammerDan
4646
*

src/main/java/com/programmerdan/minecraft/addgun/ammo/Bullets.java

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616

1717
import com.google.common.collect.Sets;
1818
import com.programmerdan.minecraft.addgun.AddGun;
19-
import com.programmerdan.minecraft.addgun.events.LoadClipEvent;
19+
import com.programmerdan.minecraft.addgun.events.LoadMagazineEvent;
2020
import com.programmerdan.minecraft.addgun.events.LoadGunEvent;
2121
import com.programmerdan.minecraft.addgun.guns.StandardGun;
2222

2323
/**
2424
* Intent here is this class holds configurations of bullets and provides easy accessors.
2525
* Each gun will have a list of bullets that it can use.
2626
*
27-
* Bullets and clips are constructed from config.
27+
* Bullets and magazines are constructed from config.
2828
*
2929
* @author ProgrammerDan
3030
*
@@ -33,15 +33,15 @@ public class Bullets implements Listener {
3333

3434
private Map<String, Bullet> tagMap = new ConcurrentHashMap<>();
3535

36-
private Map<String, Clip> clipTagMap = new ConcurrentHashMap<>();
36+
private Map<String, Magazine> magazineTagMap = new ConcurrentHashMap<>();
3737

3838
private Map<String, Bullet> nameMap = new ConcurrentHashMap<>();
3939

40-
private Map<String, Clip> clipMap = new ConcurrentHashMap<>();
40+
private Map<String, Magazine> magazineMap = new ConcurrentHashMap<>();
4141

4242
private Map<Material, Set<Bullet>> map = new ConcurrentHashMap<>();
4343

44-
private Map<Material, Set<Clip>> clips = new ConcurrentHashMap<>();
44+
private Map<Material, Set<Magazine>> magazines = new ConcurrentHashMap<>();
4545

4646
/**
4747
* Register a bullet. Handles all index mapping.
@@ -65,24 +65,24 @@ public void registerBullet(Bullet bullet) {
6565
}
6666

6767
/**
68-
* Registers a clip. Handles all index mapping.
68+
* Registers a magazine. Handles all index mapping.
6969
*
70-
* @param clip the clip to regsiter
70+
* @param magazine the magazine to regsiter
7171
*/
72-
public void registerClip(Clip clip) {
73-
if (clip == null) return;
72+
public void registerMagazine(Magazine magazine) {
73+
if (magazine == null) return;
7474

75-
clipMap.put(clip.getName(), clip);
75+
magazineMap.put(magazine.getName(), magazine);
7676

77-
clips.compute(clip.getMaterialType(), (k, s) -> {
77+
magazines.compute(magazine.getMaterialType(), (k, s) -> {
7878
if (s == null) {
7979
s = Sets.newConcurrentHashSet();
8080
}
81-
s.add(clip);
81+
s.add(magazine);
8282
return s;
8383
});
8484

85-
clipTagMap.put(clip.getTag(), clip);
85+
magazineTagMap.put(magazine.getTag(), magazine);
8686
}
8787

8888
/**
@@ -124,50 +124,50 @@ public Bullet getBulletByTag(String tag) {
124124
}
125125

126126
/**
127-
* Using a supplied item, identifies which clip, or if none, null.
127+
* Using a supplied item, identifies which magazine, or if none, null.
128128
*
129-
* @param clip the ItemStack to check
130-
* @return a Clip or null.
129+
* @param magazine the ItemStack to check
130+
* @return a Magazine or null.
131131
*/
132-
public Clip findClip(ItemStack clip) {
133-
if (clip == null) return null;
134-
Set<Clip> set = clips.get(clip.getType());
132+
public Magazine findMagazine(ItemStack magazine) {
133+
if (magazine == null) return null;
134+
Set<Magazine> set = magazines.get(magazine.getType());
135135
if (set == null) return null;
136136
// TODO: Can we do better?
137-
for (Clip sclip : set) {
138-
if (sclip.isClip(clip)) {
139-
return sclip;
137+
for (Magazine smag : set) {
138+
if (smag.isMagazine(magazine)) {
139+
return smag;
140140
}
141141
}
142142
return null;
143143
}
144144

145145
/**
146-
* Using the provided name, gets the clip, or null.
147-
* @param name the name of the clip
148-
* @return the Clip or null if no match
146+
* Using the provided name, gets the magazine, or null.
147+
* @param name the name of the magazine
148+
* @return the Magazine or null if no match
149149
*/
150-
public Clip getClip(String name) {
151-
return clipMap.get(name);
150+
public Magazine getMagazine(String name) {
151+
return magazineMap.get(name);
152152
}
153153

154154
/**
155-
* Using the provided loretag, gets the clip, or null.
155+
* Using the provided loretag, gets the magazine, or null.
156156
*
157-
* @param tag the loretag of the clip
158-
* @return the Clip or null if no match
157+
* @param tag the loretag of the magazine
158+
* @return the Magazine or null if no match
159159
*/
160-
public Clip getClipByTag(String tag) {
161-
return clipTagMap.get(tag);
160+
public Magazine getMagazineByTag(String tag) {
161+
return magazineTagMap.get(tag);
162162
}
163163

164164
/**
165-
* Returns a representation of all the clips configured by names
165+
* Returns a representation of all the magazines configured by names
166166
*
167-
* @return a set of clip names
167+
* @return a set of magazine names
168168
*/
169-
public Set<String> allClipNames() {
170-
return clipMap.keySet();
169+
public Set<String> allMagazineNames() {
170+
return magazineMap.keySet();
171171
}
172172

173173
/**
@@ -186,7 +186,7 @@ public Set<String> allBulletNames() {
186186
*
187187
*/
188188
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false)
189-
public void interactClipEvent(InventoryClickEvent event) {
189+
public void interactMagazineEvent(InventoryClickEvent event) {
190190
if (!(InventoryAction.SWAP_WITH_CURSOR.equals(event.getAction()) ||
191191
InventoryAction.PICKUP_ALL.equals(event.getAction()) ||
192192
InventoryAction.PICKUP_HALF.equals(event.getAction()) ||
@@ -200,39 +200,39 @@ public void interactClipEvent(InventoryClickEvent event) {
200200
ItemStack current = event.getCurrentItem();
201201
ItemStack cursor = event.getCursor();
202202

203-
Clip currentClip = findClip(current);
204-
if (currentClip == null) return;
203+
Magazine currentMag = findMagazine(current);
204+
if (currentMag == null) return;
205205

206206
Bullet cursorBullet = null;
207207

208208
if (cursor != null && !Material.AIR.equals(cursor.getType())) {
209209
cursorBullet = findBullet(cursor);
210210
if (cursorBullet != null) {
211211
// load / swap event.
212-
ItemStack[] outcome = currentClip.loadClip(current, cursorBullet, cursor.getAmount());
212+
ItemStack[] outcome = currentMag.loadMagazine(current, cursorBullet, cursor.getAmount());
213213

214-
LoadClipEvent clipEvent = new LoadClipEvent(currentClip, cursorBullet, cursor.getAmount(), event.getWhoClicked());
215-
Bukkit.getServer().getPluginManager().callEvent(clipEvent);
216-
if (clipEvent.isCancelled()) return;
214+
LoadMagazineEvent magEvent = new LoadMagazineEvent(currentMag, cursorBullet, cursor.getAmount(), event.getWhoClicked());
215+
Bukkit.getServer().getPluginManager().callEvent(magEvent);
216+
if (magEvent.isCancelled()) return;
217217

218218
event.setCurrentItem(outcome[0]);
219219
event.setCursor(outcome[1]); // why tf is this deprecated?!
220220
event.setResult(Result.DENY);
221221
}
222222
} else {
223223
// unload event.
224-
ItemStack[] outcome = currentClip.unloadClip(current);
224+
ItemStack[] outcome = currentMag.unloadMagazine(current);
225225
event.setCurrentItem(outcome[0]);
226226
event.setCursor(outcome[1]); // why tf is this deprecated?!
227227
event.setResult(Result.DENY);
228228
}
229229
}
230230

231231
/**
232-
* Quick check if there are any clips registered
232+
* Quick check if there are any magazines registered
233233
* @return true if yes, otherwise false
234234
*/
235-
public boolean hasClips() {
236-
return !this.clipMap.isEmpty();
235+
public boolean hasMagazines() {
236+
return !this.magazineMap.isEmpty();
237237
}
238238
}

0 commit comments

Comments
 (0)