Skip to content

Commit d1fbac1

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents e51e791 + 0dd7a1a commit d1fbac1

File tree

10 files changed

+285
-2
lines changed

10 files changed

+285
-2
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.miketheshadow.complexproficiencies.Boosters;
2+
3+
import de.tr7zw.nbtapi.NBTItem;
4+
import org.bukkit.ChatColor;
5+
import org.bukkit.Material;
6+
import org.bukkit.inventory.ItemStack;
7+
import org.bukkit.inventory.meta.ItemMeta;
8+
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
12+
public class BoosterNBT {
13+
14+
public static boolean isBooster(NBTItem item) {
15+
return item.hasKey("boost");
16+
}
17+
18+
public static double getBoost(NBTItem item) {
19+
return item.getDouble("boost");
20+
}
21+
22+
public static int getTime(NBTItem item) {
23+
return item.getInteger("time");
24+
}
25+
26+
public static NBTItem createBoosterItem(NBTItem item, double boost, int minutes) {
27+
item.setDouble("boost", boost);
28+
item.setInteger("time", minutes);
29+
return item;
30+
}
31+
32+
public static ItemStack createBoosterItemStack(double boost, int minutes) {
33+
ItemStack stack = new ItemStack(Material.EXP_BOTTLE);
34+
ItemMeta meta = stack.getItemMeta();
35+
meta.setDisplayName(ChatColor.GREEN + "Global XP Booster");
36+
meta.setLore(createBoosterLore(boost, minutes));
37+
return stack;
38+
}
39+
40+
public static List<String> createBoosterLore(double boost, int minutes) {
41+
List<String> lore = new ArrayList<>();
42+
String multiplierString = ChatColor.BLUE + "Multiplier: " + ChatColor.WHITE + boost;
43+
String durationString = ChatColor.BLUE + "Duration: " + ChatColor.WHITE + minutes + " Minute(s)";
44+
lore.add(multiplierString);
45+
lore.add(durationString);
46+
return lore;
47+
}
48+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.miketheshadow.complexproficiencies.Boosters;
2+
3+
import com.miketheshadow.complexproficiencies.ComplexProficiencies;
4+
import org.bukkit.Bukkit;
5+
import org.bukkit.ChatColor;
6+
import org.bukkit.scheduler.BukkitRunnable;
7+
8+
public class BoosterTask extends BukkitRunnable {
9+
10+
private final double boost;
11+
12+
public BoosterTask(ComplexProficiencies complexProficiencies, double boost) {
13+
this.boost = boost;
14+
}
15+
16+
@Override
17+
public void run() {
18+
BoosterUtil.decreaseBoost(boost);
19+
Bukkit.broadcastMessage(ChatColor.WHITE + "" + boost + "x Boost " + ChatColor.GREEN + "has ended.");
20+
}
21+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.miketheshadow.complexproficiencies.Boosters;
2+
3+
import com.miketheshadow.complexproficiencies.ComplexProficiencies;
4+
import de.tr7zw.nbtapi.NBTItem;
5+
import org.bukkit.Bukkit;
6+
import org.bukkit.ChatColor;
7+
import org.bukkit.inventory.ItemStack;
8+
import org.bukkit.scheduler.BukkitTask;
9+
10+
public class BoosterUtil {
11+
12+
static ComplexProficiencies complexProficiencies = ComplexProficiencies.INSTANCE;
13+
14+
public static void runBooster(ComplexProficiencies complexProficiencies, ItemStack stack, NBTItem item) {
15+
double boost = BoosterNBT.getBoost(item);
16+
int time = BoosterNBT.getTime(item);
17+
18+
increaseBoost(boost);
19+
20+
BukkitTask task = new BoosterTask(complexProficiencies, boost).runTaskLater(complexProficiencies, time * 1200L);
21+
Bukkit.broadcastMessage(ChatColor.WHITE + "" + boost + "x Boost "
22+
+ ChatColor.GREEN + "has been enabled for "
23+
+ ChatColor.WHITE + (time) + " Minute(s)!");
24+
}
25+
26+
public static void increaseBoost(double boost) {
27+
double currentBoost = ComplexProficiencies.boost;
28+
if (currentBoost == 1) {
29+
ComplexProficiencies.boost = boost;
30+
} else {
31+
ComplexProficiencies.boost = currentBoost + boost;
32+
}
33+
}
34+
35+
public static void decreaseBoost(double boost) {
36+
double newBoost = ComplexProficiencies.boost - boost;
37+
ComplexProficiencies.boost = Math.max(newBoost, 1);
38+
}
39+
40+
public static void setBoost(double boost, int time) {
41+
ComplexProficiencies.boost = boost;
42+
if (time < 1) return;
43+
BukkitTask task = new BoosterTask(complexProficiencies, boost).runTaskLater(complexProficiencies, time * 1200L);
44+
}
45+
}

src/main/java/com/miketheshadow/complexproficiencies/ComplexProficiencies.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public class ComplexProficiencies extends JavaPlugin {
6565
//version
6666
public static String VERSION = "3.1.1";
6767

68+
//XP Booster
69+
public static double boost;
70+
6871
//economy
6972
public static Economy econ;
7073

@@ -94,6 +97,9 @@ public void onEnable() {
9497
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "WARNING RESET MODE IS ENABLED! PLEASE DISABLE IN THE CONFIG IF THIS WAS NOT INTENDED!");
9598
}
9699

100+
//XP Booster
101+
boost = 1;
102+
97103
//Duels
98104
duelsApi = (Duels) Bukkit.getServer().getPluginManager().getPlugin("Duels");
99105

@@ -106,6 +112,7 @@ public void onEnable() {
106112
pluginManager.registerEvents(new EntityDeathListener(),this);
107113
pluginManager.registerEvents(new PlayerVehicleListener(),this);
108114
pluginManager.registerEvents(new PlayerCraftListener(),this);
115+
pluginManager.registerEvents(new PlayerInteractListener(), this);
109116
//regrade listener
110117
pluginManager.registerEvents(new OpenRegradeWindowListener(),this);
111118
pluginManager.registerEvents(new RegradeInventoryListener(),this);
@@ -128,6 +135,10 @@ public void onEnable() {
128135
new SetLevelCommand();
129136
new AddExperienceCommand();
130137
new AddPartyExperienceCommand();
138+
//booster commands
139+
new SetBoostCommand();
140+
new ClearBoostCommand();
141+
new CreateBoosterCommand();
131142
//Only command that needs to be registered goes here
132143
new ComplexDebugCommand();
133144
new ComplexRecipeCommand();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.miketheshadow.complexproficiencies.command.experience;
2+
3+
import com.miketheshadow.complexproficiencies.command.ComplexCommand;
4+
import com.miketheshadow.complexproficiencies.Boosters.BoosterUtil;
5+
import org.bukkit.ChatColor;
6+
import org.bukkit.command.CommandSender;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
public class ClearBoostCommand extends ComplexCommand {
10+
11+
public ClearBoostCommand() {
12+
super("ClearBoost");
13+
}
14+
15+
@Override
16+
public boolean onCommand(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command cmd, @NotNull String label, String[] args) {
17+
if (cmd.getName().equalsIgnoreCase("ClearBoost")) {
18+
BoosterUtil.setBoost(1, 0);
19+
sender.sendMessage(ChatColor.GREEN + "The Global Boost has been reset.");
20+
}
21+
return true;
22+
}
23+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.miketheshadow.complexproficiencies.command.experience;
2+
3+
import com.miketheshadow.complexproficiencies.command.ComplexCommand;
4+
import com.miketheshadow.complexproficiencies.Boosters.BoosterNBT;
5+
import de.tr7zw.nbtapi.NBTItem;
6+
import org.bukkit.ChatColor;
7+
import org.bukkit.command.CommandSender;
8+
import org.bukkit.entity.Player;
9+
import org.bukkit.inventory.Inventory;
10+
import org.bukkit.inventory.ItemStack;
11+
import org.jetbrains.annotations.NotNull;
12+
13+
import java.util.HashMap;
14+
import java.util.Optional;
15+
16+
public class CreateBoosterCommand extends ComplexCommand {
17+
18+
public CreateBoosterCommand() {
19+
super("CreateBooster");
20+
}
21+
22+
@Override
23+
public boolean onCommand(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command cmd, @NotNull String label, String[] args) {
24+
if (!(sender instanceof Player)) {
25+
sender.sendMessage(ChatColor.RED + "This command cannot be executed from console");
26+
return true;
27+
}
28+
if (cmd.getName().equalsIgnoreCase("CreateBooster")) {
29+
Player player = (Player) sender;
30+
try {
31+
double boost = Double.parseDouble(args[0]);
32+
Optional<Integer> time = Optional.of(Integer.parseInt(args[1]));
33+
NBTItem item = BoosterNBT.createBoosterItem(new NBTItem(BoosterNBT.createBoosterItemStack(boost, time.get())), boost, time.get());
34+
ItemStack booster = item.getItem();
35+
Inventory inventory = player.getInventory();
36+
HashMap<Integer, ItemStack> hashmap = inventory.addItem(booster);
37+
if (hashmap.isEmpty()) return true;
38+
player.sendMessage(ChatColor.RED + "Not enough space in inventory.");
39+
40+
} catch (Exception Ignored) {
41+
sender.sendMessage(ChatColor.RED + "Illegal Arguments!");
42+
}
43+
}
44+
return false;
45+
}
46+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.miketheshadow.complexproficiencies.command.experience;
2+
3+
import com.miketheshadow.complexproficiencies.command.ComplexCommand;
4+
import com.miketheshadow.complexproficiencies.Boosters.BoosterUtil;
5+
import org.bukkit.ChatColor;
6+
import org.bukkit.command.CommandSender;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
import java.util.Optional;
10+
11+
public class SetBoostCommand extends ComplexCommand {
12+
13+
public SetBoostCommand() {
14+
super("SetBoostCommand");
15+
}
16+
17+
public boolean onCommand(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command cmd, @NotNull String label, String[] args) {
18+
if (cmd.getName().equalsIgnoreCase("SetBoost")) {
19+
double boost;
20+
Optional<Integer> time;
21+
try {
22+
boost = Double.parseDouble(args[0]);
23+
time = Optional.of(Integer.parseInt(args[1]));
24+
if (boost < 0 || boost > 1.5) {
25+
sender.sendMessage(ChatColor.RED + "The boost must be between 0 or 1.5");
26+
}
27+
BoosterUtil.setBoost(boost, time.get());
28+
} catch(Exception Ignored) {
29+
sender.sendMessage("Illegal Arguments!");
30+
}
31+
}
32+
return true;
33+
}
34+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.miketheshadow.complexproficiencies.listener;
2+
3+
import com.miketheshadow.complexproficiencies.ComplexProficiencies;
4+
import com.miketheshadow.complexproficiencies.Boosters.BoosterNBT;
5+
import com.miketheshadow.complexproficiencies.Boosters.BoosterUtil;
6+
import de.tr7zw.nbtapi.NBTItem;
7+
import org.bukkit.ChatColor;
8+
import org.bukkit.Sound;
9+
import org.bukkit.entity.Player;
10+
import org.bukkit.event.EventHandler;
11+
import org.bukkit.event.Listener;
12+
import org.bukkit.event.player.PlayerInteractEvent;
13+
import org.bukkit.inventory.ItemStack;
14+
15+
public class PlayerInteractListener implements Listener {
16+
17+
ComplexProficiencies complexProficiencies = ComplexProficiencies.INSTANCE;
18+
double boost = ComplexProficiencies.boost;
19+
20+
@EventHandler
21+
public void onPlayerInteractEvent(PlayerInteractEvent event) {
22+
if (event.hasItem()) {
23+
Player player = event.getPlayer();
24+
ItemStack stack = event.getItem();
25+
NBTItem item = new NBTItem(stack);
26+
if (BoosterNBT.isBooster(item)) {
27+
event.setCancelled(true);
28+
if (boost == 1) {
29+
BoosterUtil.runBooster(complexProficiencies, stack, item);
30+
player.sendMessage(ChatColor.GREEN + "You have activated a booster!");
31+
player.playSound(player.getLocation(), Sound.ENTITY_FIREWORK_BLAST, 1f, 1f);
32+
} else {
33+
player.sendMessage(ChatColor.RED + "Global Boost is at maximum value!");
34+
}
35+
}
36+
}
37+
}
38+
}

src/main/java/com/miketheshadow/complexproficiencies/utils/ExperienceUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
public class ExperienceUtil
3838
{
39+
3940
/*
4041
public static void addPartyExperience(CustomUser user, Player player, int level, boolean mute, boolean isVanilla) {
4142
int addition = level * 5;

src/main/resources/plugin.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ main: com.miketheshadow.complexproficiencies.ComplexProficiencies
44
api-version: 1.13
55
authors: [MikeTheShadow]
66
description: Creates complex proficiencies For MC.
7-
depend: [NBTAPI,WorldGuard,XPBoost,Vault,Duels]
7+
depend: [NBTAPI,WorldGuard,Vault,Duels]
88
commands:
99
crecipe:
1010
description: Recipe modification command
@@ -115,4 +115,20 @@ commands:
115115
description: Adds experience to the party.
116116
usage: /<addpartyexperience> [player] level [levelNumber]
117117
permission: ComplexProficiencies.levelAdmin
118-
permission-message: You don't have ComplexProficiencies.levelAdmin permission
118+
permission-message: You don't have ComplexProficiencies.levelAdmin permission
119+
##EXPBOOSTERS
120+
setboost:
121+
description: Sets the current boost
122+
usage: /<setboost> [amount] [time]
123+
permission: ComplexProficiencies.levelAdmin
124+
permission-message: You don't have ComplexProficiencies.levelAdmin permission
125+
clearboost:
126+
description: Clears the current boost
127+
usage: /<clearboost>
128+
permission: ComplexProficiencies.levelAdmin
129+
permission-message: You don't have ComplexProficiencies.levelAdmin permission
130+
createbooster:
131+
description: Generates a booster item
132+
usage: /<createbooster> [amount] [time]
133+
permission: ComplexProficiencies.levelAdmin
134+
permission-message: You don't have ComplexProficiencies.levelAdmin permission

0 commit comments

Comments
 (0)