1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 05:55:27 +01:00

Added firework shoot when leveling up

- Fixed NPE when entered /jobs playerinfo command, #456
This commit is contained in:
montlikadani 2019-06-08 18:27:23 +02:00
parent a9155efbc2
commit 3b42627cb8
8 changed files with 185 additions and 36 deletions

View File

@ -23,9 +23,9 @@
<dependency>
<groupId>de.Keyle.MyPet</groupId>
<artifactId>MyPet</artifactId>
<version>3.1-SNAPSHOT-B1433</version>
<version>3.2</version>
<scope>system</scope>
<systemPath>${basedir}/libs/MyPet-3.1-SNAPSHOT-B1433.jar</systemPath>
<systemPath>${basedir}/libs/MyPet-3.2.jar</systemPath>
</dependency>
<!-- McMMO -->
<dependency>

View File

@ -998,16 +998,16 @@ public class Jobs extends JavaPlugin {
Boost boost = getPlayerManager().getFinalBonus(jPlayer, noneJob);
JobsPrePaymentEvent JobsPrePaymentEvent = new JobsPrePaymentEvent(jPlayer.getPlayer(), noneJob, income, pointAmount);
Bukkit.getServer().getPluginManager().callEvent(JobsPrePaymentEvent);
// If event is canceled, don't do anything
if (JobsPrePaymentEvent.isCancelled()) {
income = 0D;
pointAmount = 0D;
} else {
income = JobsPrePaymentEvent.getAmount();
pointAmount = JobsPrePaymentEvent.getPoints();
}
JobsPrePaymentEvent JobsPrePaymentEvent = new JobsPrePaymentEvent(jPlayer.getPlayer(), noneJob, income, pointAmount);
Bukkit.getServer().getPluginManager().callEvent(JobsPrePaymentEvent);
// If event is canceled, don't do anything
if (JobsPrePaymentEvent.isCancelled()) {
income = 0D;
pointAmount = 0D;
} else {
income = JobsPrePaymentEvent.getAmount();
pointAmount = JobsPrePaymentEvent.getPoints();
}
// Calculate income
@ -1116,12 +1116,12 @@ public class Jobs extends JavaPlugin {
Bukkit.getServer().getPluginManager().callEvent(JobsPrePaymentEvent);
// If event is canceled, don't do anything
if (JobsPrePaymentEvent.isCancelled()) {
income = 0D;
pointAmount = 0D;
} else {
income = 0D;
pointAmount = 0D;
} else {
income = JobsPrePaymentEvent.getAmount();
pointAmount = JobsPrePaymentEvent.getPoints();
}
}
// Calculate income
if (income != 0D) {

View File

@ -22,17 +22,24 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Sound;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Firework;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta;
import com.gamingmesh.jobs.CMILib.ItemReflection;
import com.gamingmesh.jobs.CMILib.VersionChecker.Version;
@ -58,6 +65,7 @@ import com.gamingmesh.jobs.economy.PaymentData;
import com.gamingmesh.jobs.economy.PointsData;
import com.gamingmesh.jobs.stuff.Debug;
import com.gamingmesh.jobs.stuff.PerformCommands;
import com.gamingmesh.jobs.stuff.Util;
public class PlayerManager {
@ -544,6 +552,71 @@ public class PlayerManager {
} catch (Throwable e) {
}
if (Jobs.getGCManager().FireworkLevelupUse) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Jobs.getInstance(), new Runnable() {
@Override
public void run() {
Firework f = (Firework) player.getWorld().spawn(player.getLocation(), Firework.class);
FireworkMeta fm = f.getFireworkMeta();
if (Jobs.getGCManager().UseRandom) {
Random r = new Random();
int rt = r.nextInt(4) + 1;
Type type = Type.BALL;
if (rt == 1) type = Type.BALL;
if (rt == 2) type = Type.BALL_LARGE;
if (rt == 3) type = Type.BURST;
if (rt == 4) type = Type.CREEPER;
if (rt == 5) type = Type.STAR;
int r1i = r.nextInt(17) + 1;
int r2i = r.nextInt(17) + 1;
Color c1 = Util.getColor(r1i);
Color c2 = Util.getColor(r2i);
FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build();
fm.addEffect(effect);
int rp = r.nextInt(2) + 1;
fm.setPower(rp);
} else {
Pattern comma = Pattern.compile(",", 16);
List<String> colorStrings = Jobs.getGCManager().FwColors;
Color[] colors = new Color[colorStrings.size()];
for (int s = 0; s < colorStrings.size(); s++) {
String colorString = colorStrings.get(s);
String[] sSplit = comma.split(colorString);
if (sSplit.length < 3) {
Jobs.consoleMsg("[Jobs] &cInvalid color " + colorString + "! Colors must be 3 comma-separated numbers ranging from 0 to 255.");
return;
}
int[] colorRGB = new int[3];
for (int i = 0; i < 3; i++) {
String colorInt = sSplit[i];
try {
colorRGB[i] = Integer.valueOf(colorInt).intValue();
} catch (NumberFormatException e) {
Jobs.consoleMsg("[Jobs] &cInvalid color component " + colorInt + ", it must be an integer.");
}
}
try {
colors[s] = Color.fromRGB(colorRGB[0], colorRGB[1], colorRGB[2]);
} catch (IllegalArgumentException e) {
e.printStackTrace();
Jobs.consoleMsg("[Jobs] &cFailed to add color! " + e);
}
}
fm.addEffect(FireworkEffect.builder()
.flicker(Jobs.getGCManager().UseFlicker)
.trail(Jobs.getGCManager().UseTrail)
.with(Type.valueOf(Jobs.getGCManager().FireworkType))
.withColor(colors)
.withFade(colors)
.build());
fm.setPower(Jobs.getGCManager().FireworkPower);
}
f.setFireworkMeta(fm);
}
}, Jobs.getGCManager().ShootTime);
}
String message;
if (Jobs.getGCManager().isBroadcastingLevelups())
message = Jobs.getLanguage().getMessage("message.levelup.broadcast");

View File

@ -3,8 +3,6 @@ package com.gamingmesh.jobs.api;
import com.gamingmesh.jobs.container.Job;
import org.bukkit.OfflinePlayer;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable {
private OfflinePlayer offlinePlayer;
@ -14,43 +12,43 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable
private boolean cancelled = false;
public JobsPrePaymentEvent(OfflinePlayer offlinePlayer, Job job, double money, double points) {
this.job = job;
this.offlinePlayer = offlinePlayer;
this.money = money;
this.points = points;
this.job = job;
this.offlinePlayer = offlinePlayer;
this.money = money;
this.points = points;
}
public OfflinePlayer getPlayer() {
return offlinePlayer;
return offlinePlayer;
}
public double getAmount() {
return money;
return money;
}
public double getPoints() {
return points;
return points;
}
public Job getJob() {
return job;
return job;
}
public void setAmount(double money) {
this.money = money;
this.money = money;
}
public void setPoints(double points) {
this.points = points;
this.points = points;
}
@Override
public boolean isCancelled() {
return cancelled;
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
this.cancelled = cancelled;
}
}

View File

@ -20,9 +20,12 @@ public class playerinfo implements Cmd {
}
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
if (jPlayer == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0]));
return true;
}
String jobName = args[1];
Job job = Jobs.getJob(jobName);
Job job = Jobs.getJob(args[1]);
if (job == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job"));
return true;

View File

@ -105,6 +105,11 @@ public class GeneralConfigManager {
EmptyServerAccountActionBar, ActionBarsMessageByDefault, ShowTotalWorkers, ShowPenaltyBonus, useDynamicPayment,
JobsGUIOpenOnBrowse, JobsGUIShowChatBrowse, JobsGUISwitcheButtons, JobsGUIOpenOnJoin;
public boolean FireworkLevelupUse, UseRandom, UseFlicker, UseTrail;
public String FireworkType;
public List<String> FwColors = new ArrayList<>();
public int FireworkPower, ShootTime;
private int JobsGUIRows, JobsGUIBackButton,
JobsGUIStartPosition,
JobsGUIGroupAmount,
@ -870,6 +875,21 @@ public class GeneralConfigManager {
SoundTitleChangeVolume = c.get("Sounds.TitleChange.volume", 1);
SoundTitleChangePitch = c.get("Sounds.TitleChange.pitch", 3);
c.addComment("Fireworks", "Extra firework shooting in some events");
FireworkLevelupUse = c.get("Fireworks.LevelUp.use", false);
c.addComment("Fireworks.LevelUp.Random", "Makes the firework to randomize, such as random colors, type, power and so on.",
"These are under settings will not be work, when this enabled.");
UseRandom = c.get("Fireworks.LevelUp.Random", true);
UseFlicker = c.get("Fireworks.LevelUp.flicker", true);
UseTrail = c.get("Fireworks.LevelUp.trail", true);
c.addComment("Fireworks.LevelUp.type", "Firework types",
"All types can be found in https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/FireworkEffect.Type.html");
FireworkType = c.get("Fireworks.LevelUp.type", "STAR");
FwColors = c.get("Fireworks.LevelUp.colors", Arrays.asList("230,0,0", "0,90,0", "0,0,104"));
FireworkPower = c.get("Fireworks.LevelUp.power", 1);
c.addComment("Fireworks.LevelUp.ShootTime", "Fire shooting time in ticks.", "Example: 20 tick = 1 second");
ShootTime = c.get("Fireworks.LevelUp.ShootTime", 20);
c.addComment("Signs", "You can disable this to save SMALL amount of server resources");
SignsEnabled = c.get("Signs.Enable", true);
SignsColorizeJobName = c.get("Signs.Colors.ColorizeJobName", true);

View File

@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.UUID;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
@ -21,9 +22,6 @@ import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial;
public class Util {
public Util() {
}
private static HashMap<UUID, String> jobsEditorMap = new HashMap<>();
@SuppressWarnings("deprecation")
@ -33,7 +31,7 @@ public class Util {
ItemStack testis = CMIMaterial.SPAWNER.newItemStack();
ItemMeta meta = testis.getItemMeta();
useMeta = meta instanceof BlockStateMeta;
} catch (Exception e) {
} catch (Throwable e) {
useMeta = false;
}
@ -90,6 +88,7 @@ public class Util {
distance = 15 * 16;
if (distance < 1)
distance = 1;
ArrayList<Block> blocks = new ArrayList<>();
Iterator<Block> itr = new BlockIterator(player, distance);
while (itr.hasNext()) {
@ -115,4 +114,60 @@ public class Util {
}
return !blocks.isEmpty() ? blocks.get(blocks.size() - 1) : null;
}
public static Color getColor(int a) {
Color c = null;
if (a == 1)
c = Color.AQUA;
if (a == 2)
c = Color.BLACK;
if (a == 3)
c = Color.BLUE;
if (a == 4)
c = Color.FUCHSIA;
if (a == 5)
c = Color.GRAY;
if (a == 6)
c = Color.GREEN;
if (a == 7)
c = Color.LIME;
if (a == 8)
c = Color.MAROON;
if (a == 9)
c = Color.NAVY;
if (a == 10)
c = Color.OLIVE;
if (a == 11)
c = Color.ORANGE;
if (a == 12)
c = Color.PURPLE;
if (a == 13)
c = Color.RED;
if (a == 14)
c = Color.SILVER;
if (a == 15)
c = Color.TEAL;
if (a == 16)
c = Color.WHITE;
if (a == 17)
c = Color.YELLOW;
return c == null ? Color.BLACK : c;
}
}