Skip to content

Commit 90386f1

Browse files
committed
Initial commit
0 parents  commit 90386f1

File tree

7 files changed

+404
-0
lines changed

7 files changed

+404
-0
lines changed

.gitignore

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# User-specific stuff
2+
.idea/
3+
4+
*.iml
5+
*.ipr
6+
*.iws
7+
8+
# IntelliJ
9+
out/
10+
11+
# Compiled class file
12+
*.class
13+
14+
# Log file
15+
*.log
16+
17+
# BlueJ files
18+
*.ctxt
19+
20+
# Package Files #
21+
*.jar
22+
*.war
23+
*.nar
24+
*.ear
25+
*.zip
26+
*.tar.gz
27+
*.rar
28+
29+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
30+
hs_err_pid*
31+
32+
*~
33+
34+
# temporary files which can be created if a process still has a handle open of a deleted file
35+
.fuse_hidden*
36+
37+
# KDE directory preferences
38+
.directory
39+
40+
# Linux trash folder which might appear on any partition or disk
41+
.Trash-*
42+
43+
# .nfs files are created when an open file is removed but is still being accessed
44+
.nfs*
45+
46+
# General
47+
.DS_Store
48+
.AppleDouble
49+
.LSOverride
50+
51+
# Icon must end with two \r
52+
Icon
53+
54+
# Thumbnails
55+
._*
56+
57+
# Files that might appear in the root of a volume
58+
.DocumentRevisions-V100
59+
.fseventsd
60+
.Spotlight-V100
61+
.TemporaryItems
62+
.Trashes
63+
.VolumeIcon.icns
64+
.com.apple.timemachine.donotpresent
65+
66+
# Directories potentially created on remote AFP share
67+
.AppleDB
68+
.AppleDesktop
69+
Network Trash Folder
70+
Temporary Items
71+
.apdisk
72+
73+
# Windows thumbnail cache files
74+
Thumbs.db
75+
Thumbs.db:encryptable
76+
ehthumbs.db
77+
ehthumbs_vista.db
78+
79+
# Dump file
80+
*.stackdump
81+
82+
# Folder config file
83+
[Dd]esktop.ini
84+
85+
# Recycle Bin used on file shares
86+
$RECYCLE.BIN/
87+
88+
# Windows Installer files
89+
*.cab
90+
*.msi
91+
*.msix
92+
*.msm
93+
*.msp
94+
95+
# Windows shortcuts
96+
*.lnk
97+
98+
target/
99+
100+
pom.xml.tag
101+
pom.xml.releaseBackup
102+
pom.xml.versionsBackup
103+
pom.xml.next
104+
105+
release.properties
106+
dependency-reduced-pom.xml
107+
buildNumber.properties
108+
.mvn/timing.properties
109+
.mvn/wrapper/maven-wrapper.jar
110+
.flattened-pom.xml
111+
112+
# Common working directory
113+
run/

pom.xml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>io.github.nik2143</groupId>
8+
<artifactId>CustomGapple</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<name>CustomGapple</name>
13+
14+
<description>Allow to create custom golden apples with custom effects</description>
15+
<properties>
16+
<java.version>1.8</java.version>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
<build>
21+
<plugins>
22+
<plugin>
23+
<groupId>org.apache.maven.plugins</groupId>
24+
<artifactId>maven-compiler-plugin</artifactId>
25+
<version>3.8.1</version>
26+
<configuration>
27+
<source>${java.version}</source>
28+
<target>${java.version}</target>
29+
</configuration>
30+
</plugin>
31+
<plugin>
32+
<groupId>org.apache.maven.plugins</groupId>
33+
<artifactId>maven-shade-plugin</artifactId>
34+
<version>3.2.4</version>
35+
<executions>
36+
<execution>
37+
<phase>package</phase>
38+
<goals>
39+
<goal>shade</goal>
40+
</goals>
41+
<configuration>
42+
<createDependencyReducedPom>false</createDependencyReducedPom>
43+
<relocations>
44+
<relocation>
45+
<pattern>de.tr7zw.changeme.nbtapi</pattern>
46+
<shadedPattern>io.github.nik2143.customgapple</shadedPattern>
47+
</relocation>
48+
</relocations>
49+
<filters>
50+
<filter>
51+
<artifact>*:*</artifact>
52+
<excludes>
53+
<exclude>META-INF/*.MF</exclude>
54+
<exclude>LICENSE</exclude>
55+
<exclude>META-INF/maven/de.tr7zw/functional-annotations/pom.properties</exclude>
56+
<exclude>META-INF/maven/de.tr7zw/functional-annotations/pom.xml</exclude>
57+
</excludes>
58+
</filter>
59+
</filters>
60+
</configuration>
61+
</execution>
62+
</executions>
63+
</plugin>
64+
</plugins>
65+
<resources>
66+
<resource>
67+
<directory>src/main/resources</directory>
68+
<filtering>true</filtering>
69+
</resource>
70+
</resources>
71+
</build>
72+
73+
<repositories>
74+
<repository>
75+
<id>spigotmc-repo</id>
76+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
77+
</repository>
78+
<repository>
79+
<id>sonatype</id>
80+
<url>https://oss.sonatype.org/content/groups/public/</url>
81+
</repository>
82+
<repository>
83+
<id>codemc-repo</id>
84+
<url>https://repo.codemc.org/repository/maven-public/</url>
85+
<layout>default</layout>
86+
</repository>
87+
</repositories>
88+
89+
<dependencies>
90+
<dependency>
91+
<groupId>org.spigotmc</groupId>
92+
<artifactId>spigot-api</artifactId>
93+
<version>1.8.8-R0.1-SNAPSHOT</version>
94+
<scope>provided</scope>
95+
</dependency>
96+
<dependency>
97+
<groupId>de.tr7zw</groupId>
98+
<artifactId>item-nbt-api</artifactId>
99+
<version>2.5.0</version>
100+
</dependency>
101+
</dependencies>
102+
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.github.nik2143.customgapple;
2+
3+
import io.github.nik2143.customgapple.commands.CustomGappleCommand;
4+
import io.github.nik2143.customgapple.listeners.EatListener;
5+
import org.bukkit.Bukkit;
6+
import org.bukkit.plugin.java.JavaPlugin;
7+
8+
public final class CustomGapple extends JavaPlugin {
9+
10+
@Override
11+
public void onEnable() {
12+
saveDefaultConfig();
13+
this.getCommand("customgapple").setExecutor(new CustomGappleCommand(this));
14+
this.getCommand("customgapple").setTabCompleter(new CustomGappleCommand(this));
15+
Bukkit.getPluginManager().registerEvents(new EatListener(),this);
16+
}
17+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package io.github.nik2143.customgapple.commands;
2+
3+
import de.tr7zw.changeme.nbtapi.NBTItem;
4+
import io.github.nik2143.customgapple.CustomGapple;
5+
import org.apache.commons.lang.StringUtils;
6+
import org.apache.commons.lang.math.NumberUtils;
7+
import org.bukkit.Bukkit;
8+
import org.bukkit.Material;
9+
import org.bukkit.command.Command;
10+
import org.bukkit.command.CommandExecutor;
11+
import org.bukkit.command.CommandSender;
12+
import org.bukkit.command.TabCompleter;
13+
import org.bukkit.entity.Player;
14+
import org.bukkit.inventory.ItemStack;
15+
import org.bukkit.potion.PotionEffectType;
16+
17+
import java.util.ArrayList;
18+
import java.util.Collections;
19+
import java.util.List;
20+
21+
public class CustomGappleCommand implements CommandExecutor, TabCompleter {
22+
23+
private CustomGapple plugin;
24+
25+
public CustomGappleCommand (CustomGapple plugin){
26+
this.plugin = plugin;
27+
}
28+
29+
@Override
30+
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
31+
if (command.getName().equalsIgnoreCase("customgapple")){
32+
if (!(sender instanceof Player)) {
33+
sender.sendMessage("[CustomGapple] You can't use this command from console");
34+
return true;
35+
}
36+
if (!sender.isOp() || !sender.hasPermission("customgapple.use")){
37+
sender.sendMessage("[CustomGapple] You haven't permissions to use this command");
38+
return true;
39+
}
40+
Player player = (Player) sender;
41+
switch (args.length){
42+
case 0:
43+
sender.sendMessage("Wrong sintax. Use /customgapple <Effect> [Duration] [Level] [Amount]");
44+
return true;
45+
case 1:
46+
if (PotionEffectType.getByName(args[0])==null){
47+
sender.sendMessage("Unknown potion effect");
48+
return true;
49+
}
50+
player.getInventory().addItem(CreateGapple(PotionEffectType.getByName(args[0]),plugin.getConfig().getInt("Default-Duration"),1, plugin.getConfig().getInt("Default-Amount")));
51+
break;
52+
case 2:
53+
if (PotionEffectType.getByName(args[0])==null){
54+
sender.sendMessage("Unknown potion effect");
55+
return true;
56+
}
57+
if (!NumberUtils.isNumber(args[1])){
58+
sender.sendMessage(args[1] + " isn't a number");
59+
return true;
60+
}
61+
player.getInventory().addItem(CreateGapple(PotionEffectType.getByName(args[0]), Integer.parseInt(args[1]),1, plugin.getConfig().getInt("Default-Amount")));
62+
break;
63+
case 3:
64+
if (PotionEffectType.getByName(args[0])==null){
65+
sender.sendMessage("Unknown potion effect");
66+
return true;
67+
}
68+
if (!NumberUtils.isNumber(args[1])){
69+
sender.sendMessage(args[1] + " isn't a number");
70+
return true;
71+
}
72+
if (!NumberUtils.isNumber(args[2])){
73+
sender.sendMessage(args[2] + " isn't a number");
74+
return true;
75+
}
76+
player.getInventory().addItem(CreateGapple(PotionEffectType.getByName(args[0]), Integer.parseInt(args[1]),Integer.parseInt(args[2]), plugin.getConfig().getInt("Default-Amount")));
77+
break;
78+
case 4:
79+
if (PotionEffectType.getByName(args[0])==null){
80+
sender.sendMessage("Unknown potion effect");
81+
return true;
82+
}
83+
if (!NumberUtils.isNumber(args[1])){
84+
sender.sendMessage(args[1] + " isn't a number");
85+
return true;
86+
}
87+
if (!NumberUtils.isNumber(args[2])){
88+
sender.sendMessage(args[2] + " isn't a number");
89+
return true;
90+
}
91+
if (!NumberUtils.isNumber(args[3])){
92+
sender.sendMessage(args[3] + " isn't a number");
93+
return true;
94+
}
95+
player.getInventory().addItem(CreateGapple(PotionEffectType.getByName(args[0]), Integer.parseInt(args[1]),Integer.parseInt(args[2]),Integer.parseInt(args[3])));
96+
break;
97+
}
98+
return true;
99+
}
100+
return false;
101+
}
102+
103+
@Override
104+
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
105+
if (command.getName().equalsIgnoreCase("customgapple")){
106+
List<String> autocomplete = new ArrayList<String>();
107+
if (args.length == 1){
108+
for (PotionEffectType effect : PotionEffectType.values()){
109+
if(effect == null) {
110+
continue;
111+
}
112+
autocomplete.add(StringUtils.capitalize(effect.getName().toLowerCase()));
113+
}
114+
return autocomplete;
115+
}
116+
return Collections.emptyList();
117+
}
118+
return Collections.emptyList();
119+
}
120+
121+
private ItemStack CreateGapple (PotionEffectType effect,int duration,int level,int amount){
122+
NBTItem nbti = new NBTItem(new ItemStack(Material.GOLDEN_APPLE, amount));
123+
nbti.addCompound("GappleEffect");
124+
nbti.getCompound("GappleEffect").setString("Effect", effect.getName());
125+
nbti.getCompound("GappleEffect").setInteger("Duration",duration * 20);
126+
nbti.getCompound("GappleEffect").setInteger("Level",level - 1);
127+
return nbti.getItem();
128+
}
129+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.github.nik2143.customgapple.listeners;
2+
3+
import de.tr7zw.changeme.nbtapi.NBTItem;
4+
import org.bukkit.Material;
5+
import org.bukkit.event.EventHandler;
6+
import org.bukkit.event.Listener;
7+
import org.bukkit.event.player.PlayerItemConsumeEvent;
8+
import org.bukkit.inventory.ItemStack;
9+
import org.bukkit.potion.PotionEffect;
10+
import org.bukkit.potion.PotionEffectType;
11+
12+
public class EatListener implements Listener {
13+
14+
@EventHandler
15+
private void GappleEatEvent(PlayerItemConsumeEvent e){
16+
if (e.getItem().getType().equals(Material.GOLDEN_APPLE)){
17+
ItemStack item = e.getItem();
18+
NBTItem nbti = new NBTItem(item);
19+
if (nbti.getCompound("GappleEffect") != null){
20+
e.setCancelled(true);
21+
e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.getByName(nbti.getCompound("GappleEffect").getString("Effect")),
22+
nbti.getCompound("GappleEffect").getInteger("Duration"),
23+
nbti.getCompound("GappleEffect").getInteger("Level")));
24+
item.setAmount(item.getAmount() - 1);
25+
e.getPlayer().getInventory().setItemInHand(item);
26+
}
27+
}
28+
}
29+
30+
}

0 commit comments

Comments
 (0)