mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 14:05:25 +01:00
Lets update signs and heads in hard way and lets make it more optimized
This commit is contained in:
parent
84681df41a
commit
c3ccf30b6d
@ -3,19 +3,24 @@ package com.gamingmesh.jobs.Signs;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.Skull;
|
import org.bukkit.block.Skull;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import com.gamingmesh.jobs.Jobs;
|
import com.gamingmesh.jobs.Jobs;
|
||||||
|
import com.gamingmesh.jobs.CMILib.CMIChatColor;
|
||||||
import com.gamingmesh.jobs.config.CommentedYamlConfiguration;
|
import com.gamingmesh.jobs.config.CommentedYamlConfiguration;
|
||||||
import com.gamingmesh.jobs.container.TopList;
|
import com.gamingmesh.jobs.container.TopList;
|
||||||
|
import com.gamingmesh.jobs.stuff.Debug;
|
||||||
|
|
||||||
public class SignUtil {
|
public class SignUtil {
|
||||||
|
|
||||||
@ -102,37 +107,43 @@ public class SignUtil {
|
|||||||
if (!Jobs.getGCManager().SignsEnabled)
|
if (!Jobs.getGCManager().SignsEnabled)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
List<com.gamingmesh.jobs.Signs.Sign> Copy = new ArrayList<>(Signs.GetAllSigns().size());
|
|
||||||
for (com.gamingmesh.jobs.Signs.Sign foo : Signs.GetAllSigns()) {
|
|
||||||
Copy.add(foo);
|
|
||||||
}
|
|
||||||
int timelapse = 1;
|
int timelapse = 1;
|
||||||
for (com.gamingmesh.jobs.Signs.Sign one : Copy) {
|
|
||||||
|
List<TopList> PlayerList = new ArrayList<>();
|
||||||
|
|
||||||
|
if (JobName.equalsIgnoreCase("gtoplist"))
|
||||||
|
PlayerList = Jobs.getJobsDAO().getGlobalTopList(0);
|
||||||
|
|
||||||
|
for (com.gamingmesh.jobs.Signs.Sign one : new ArrayList<>(Signs.GetAllSigns())) {
|
||||||
String SignJobName = one.GetJobName();
|
String SignJobName = one.GetJobName();
|
||||||
|
|
||||||
if (JobName.equalsIgnoreCase(SignJobName)) {
|
if (!JobName.equalsIgnoreCase(SignJobName))
|
||||||
String SignsWorld = one.GetWorld();
|
continue;
|
||||||
|
|
||||||
|
World world = Bukkit.getWorld(one.GetWorld());
|
||||||
|
if (world == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
double SignsX = one.GetX();
|
double SignsX = one.GetX();
|
||||||
double SignsY = one.GetY();
|
double SignsY = one.GetY();
|
||||||
double SignsZ = one.GetZ();
|
double SignsZ = one.GetZ();
|
||||||
int number = one.GetNumber() - 1;
|
int number = one.GetNumber() - 1;
|
||||||
|
|
||||||
List<TopList> PlayerList = new ArrayList<>();
|
|
||||||
if (!JobName.equalsIgnoreCase("gtoplist")) {
|
if (!JobName.equalsIgnoreCase("gtoplist")) {
|
||||||
PlayerList = Jobs.getJobsDAO().toplist(SignJobName, number);
|
PlayerList = Jobs.getJobsDAO().toplist(SignJobName, number);
|
||||||
} else {
|
|
||||||
PlayerList = Jobs.getJobsDAO().getGlobalTopList(number);
|
|
||||||
}
|
}
|
||||||
if (PlayerList.size() != 0) {
|
|
||||||
World world = Bukkit.getWorld(SignsWorld);
|
if (PlayerList.isEmpty())
|
||||||
if (world == null)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Location nloc = new Location(world, SignsX, SignsY, SignsZ);
|
Location nloc = new Location(world, SignsX, SignsY, SignsZ);
|
||||||
Block block = nloc.getBlock();
|
Block block = nloc.getBlock();
|
||||||
if (!(block.getState() instanceof org.bukkit.block.Sign)) {
|
if (!(block.getState() instanceof org.bukkit.block.Sign)) {
|
||||||
Signs.GetAllSigns().remove(one);
|
Signs.GetAllSigns().remove(one);
|
||||||
saveSigns();
|
saveSigns();
|
||||||
} else {
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
org.bukkit.block.Sign sign = (org.bukkit.block.Sign) block.getState();
|
org.bukkit.block.Sign sign = (org.bukkit.block.Sign) block.getState();
|
||||||
if (!one.isSpecial()) {
|
if (!one.isSpecial()) {
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
@ -156,9 +167,14 @@ public class SignUtil {
|
|||||||
sign.setLine(i, line);
|
sign.setLine(i, line);
|
||||||
}
|
}
|
||||||
sign.update();
|
sign.update();
|
||||||
UpdateHead(sign, PlayerList.get(0).getPlayerName(), timelapse);
|
if (!UpdateHead(sign, PlayerList.get(0).getPlayerName(), timelapse))
|
||||||
|
timelapse--;
|
||||||
} else {
|
} else {
|
||||||
String PlayerName = PlayerList.get(0).getPlayerName();
|
|
||||||
|
TopList pl = PlayerList.get(one.GetNumber() - 1);
|
||||||
|
|
||||||
|
String PlayerName = pl.getPlayerName();
|
||||||
|
|
||||||
if (PlayerName.length() > 8) {
|
if (PlayerName.length() > 8) {
|
||||||
String PlayerNameStrip = PlayerName.split("(?<=\\G.{7})")[0];
|
String PlayerNameStrip = PlayerName.split("(?<=\\G.{7})")[0];
|
||||||
PlayerName = PlayerNameStrip + "~";
|
PlayerName = PlayerNameStrip + "~";
|
||||||
@ -166,7 +182,7 @@ public class SignUtil {
|
|||||||
String line1 = Jobs.getLanguage().getMessage("signs.SpecialList.p" + one.GetNumber(),
|
String line1 = Jobs.getLanguage().getMessage("signs.SpecialList.p" + one.GetNumber(),
|
||||||
"[number]", one.GetNumber() + number + 1,
|
"[number]", one.GetNumber() + number + 1,
|
||||||
"[player]", PlayerName,
|
"[player]", PlayerName,
|
||||||
"[level]", PlayerList.get(0).getLevel(),
|
"[level]", pl.getLevel(),
|
||||||
"[job]", JobName);
|
"[job]", JobName);
|
||||||
|
|
||||||
sign.setLine(0, line1);
|
sign.setLine(0, line1);
|
||||||
@ -174,7 +190,7 @@ public class SignUtil {
|
|||||||
line1 = Jobs.getLanguage().getMessage("signs.SpecialList.name",
|
line1 = Jobs.getLanguage().getMessage("signs.SpecialList.name",
|
||||||
"[number]", one.GetNumber() + number + 1,
|
"[number]", one.GetNumber() + number + 1,
|
||||||
"[player]", PlayerName,
|
"[player]", PlayerName,
|
||||||
"[level]", PlayerList.get(0).getLevel(),
|
"[level]", pl.getLevel(),
|
||||||
"[job]", JobName);
|
"[job]", JobName);
|
||||||
|
|
||||||
sign.setLine(1, line1);
|
sign.setLine(1, line1);
|
||||||
@ -182,7 +198,7 @@ public class SignUtil {
|
|||||||
line1 = Jobs.getLanguage().getMessage("signs.SpecialList.level",
|
line1 = Jobs.getLanguage().getMessage("signs.SpecialList.level",
|
||||||
"[number]", one.GetNumber() + number + 1,
|
"[number]", one.GetNumber() + number + 1,
|
||||||
"[player]", PlayerName,
|
"[player]", PlayerName,
|
||||||
"[level]", PlayerList.get(0).getLevel(),
|
"[level]", pl.getLevel(),
|
||||||
"[job]", JobName);
|
"[job]", JobName);
|
||||||
|
|
||||||
sign.setLine(2, line1);
|
sign.setLine(2, line1);
|
||||||
@ -190,36 +206,33 @@ public class SignUtil {
|
|||||||
line1 = Jobs.getLanguage().getMessage("signs.SpecialList.bottom",
|
line1 = Jobs.getLanguage().getMessage("signs.SpecialList.bottom",
|
||||||
"[number]", one.GetNumber() + number + 1,
|
"[number]", one.GetNumber() + number + 1,
|
||||||
"[player]", PlayerName,
|
"[player]", PlayerName,
|
||||||
"[level]", PlayerList.get(0).getLevel(),
|
"[level]", pl.getLevel(),
|
||||||
"[job]", JobName);
|
"[job]", JobName);
|
||||||
|
|
||||||
sign.setLine(3, line1);
|
sign.setLine(3, line1);
|
||||||
sign.update();
|
sign.update();
|
||||||
UpdateHead(sign, PlayerList.get(0).getPlayerName(), timelapse);
|
|
||||||
|
if (!UpdateHead(sign, PlayerName, timelapse))
|
||||||
|
timelapse--;
|
||||||
}
|
}
|
||||||
|
|
||||||
timelapse++;
|
timelapse++;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateHead(final org.bukkit.block.Sign sign, final String Playername, final int timelapse) {
|
public boolean UpdateHead(final org.bukkit.block.Sign sign, final String Playername, int timelapse) {
|
||||||
|
try {
|
||||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
timelapse = timelapse < 1 ? 1 : timelapse;
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
|
|
||||||
org.bukkit.material.Sign signMat = (org.bukkit.material.Sign) sign.getData();
|
org.bukkit.material.Sign signMat = (org.bukkit.material.Sign) sign.getData();
|
||||||
BlockFace directionFacing = signMat.getFacing();
|
BlockFace directionFacing = signMat.getFacing();
|
||||||
|
|
||||||
Location loc = sign.getLocation().clone();
|
final Location loc = sign.getLocation().clone();
|
||||||
loc.add(0, 1, 0);
|
loc.add(0, 1, 0);
|
||||||
|
|
||||||
if (Playername == null)
|
if (Playername == null)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
Block block = loc.getBlock();
|
Block block = loc.getBlock();
|
||||||
|
|
||||||
@ -229,18 +242,46 @@ public class SignUtil {
|
|||||||
block = loc.getBlock();
|
block = loc.getBlock();
|
||||||
|
|
||||||
if (block == null || !(block.getState() instanceof Skull))
|
if (block == null || !(block.getState() instanceof Skull))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
Skull skull = (Skull) block.getState();
|
Skull skull = (Skull) block.getState();
|
||||||
|
|
||||||
if (skull == null)
|
if (skull == null)
|
||||||
return;
|
return false;
|
||||||
|
if (skull.getOwner() != null && skull.getOwner().equalsIgnoreCase(Playername))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
Block b = loc.getBlock();
|
||||||
|
final Material type = b.getType();
|
||||||
|
final BlockData data = b.getBlockData();
|
||||||
|
|
||||||
|
b.setType(Material.AIR);
|
||||||
|
|
||||||
|
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Block b = loc.getBlock();
|
||||||
|
|
||||||
|
b.setType(type);
|
||||||
|
b.setBlockData(data);
|
||||||
|
Skull skull = (Skull) b.getState();
|
||||||
|
if (skull == null)
|
||||||
|
return;
|
||||||
skull.setOwner(Playername);
|
skull.setOwner(Playername);
|
||||||
skull.update();
|
skull.update();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}, 1L);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}, timelapse * Jobs.getGCManager().InfoUpdateInterval * 20L);
|
}, timelapse * Jobs.getGCManager().InfoUpdateInterval * 20L);
|
||||||
|
} catch (Exception | Error e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,7 +342,7 @@ public class LanguageManager {
|
|||||||
|
|
||||||
c.get("command.give.help.info", "Gives item by jobs name and item category name. Player name is optional");
|
c.get("command.give.help.info", "Gives item by jobs name and item category name. Player name is optional");
|
||||||
c.get("command.give.help.args", "[playername] [jobname] [items/limiteditems] [jobitemname]");
|
c.get("command.give.help.args", "[playername] [jobname] [items/limiteditems] [jobitemname]");
|
||||||
Jobs.getGCManager().commandArgs.put("give", Arrays.asList("[playername]", "[jobname]", "[jobitemname]"));
|
Jobs.getGCManager().commandArgs.put("give", Arrays.asList("[playername]", "[jobname]%%[jobitemname]", "[jobitemname]"));
|
||||||
c.get("command.give.output.notonline", "&4Player [%playername%] is not online!");
|
c.get("command.give.output.notonline", "&4Player [%playername%] is not online!");
|
||||||
c.get("command.give.output.noitem", "&4Can't find any item by given name!");
|
c.get("command.give.output.noitem", "&4Can't find any item by given name!");
|
||||||
|
|
||||||
|
@ -51,14 +51,18 @@ public class TabComplete implements TabCompleter {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
String arg = ArgsList.get(i - 1);
|
String arg = ArgsList.get(i - 1);
|
||||||
List<String> temp = new ArrayList<>();
|
List<String> t2 = new ArrayList<>();
|
||||||
|
|
||||||
if (arg.contains("%%"))
|
if (arg.contains("%%"))
|
||||||
for (String one : arg.split("%%")) {
|
for (String one : arg.split("%%")) {
|
||||||
temp.add(one);
|
t2.add(one);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
t2.add(arg);
|
||||||
|
|
||||||
switch (arg) {
|
List<String> temp = new ArrayList<>();
|
||||||
|
for (String ar : t2) {
|
||||||
|
switch (ar) {
|
||||||
case "[jobname]":
|
case "[jobname]":
|
||||||
List<Job> Jobsai = Jobs.getJobs();
|
List<Job> Jobsai = Jobs.getJobs();
|
||||||
for (Job one : Jobsai) {
|
for (Job one : Jobsai) {
|
||||||
@ -76,11 +80,10 @@ public class TabComplete implements TabCompleter {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "[jobitemname]":
|
case "[jobitemname]":
|
||||||
if (args[3].equals("items")) {
|
|
||||||
for (Entry<String, JobItems> one : ItemBoostManager.getItems().entrySet()) {
|
for (Entry<String, JobItems> one : ItemBoostManager.getItems().entrySet()) {
|
||||||
temp.add(one.getValue().getNode());
|
temp.add(one.getValue().getNode());
|
||||||
}
|
}
|
||||||
} else if (args[3].equals("limiteditems")) {
|
if (args.length > 3 && args[3].equals("limiteditems")) {
|
||||||
Job oneJob = Jobs.getJob(args[i - 1]);
|
Job oneJob = Jobs.getJob(args[i - 1]);
|
||||||
if (oneJob != null)
|
if (oneJob != null)
|
||||||
if (args[3].equals("limiteditems")) {
|
if (args[3].equals("limiteditems")) {
|
||||||
@ -118,6 +121,10 @@ public class TabComplete implements TabCompleter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
temp.add(ar);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StringUtil.copyPartialMatches(PartOfCommand, temp, completionList);
|
StringUtil.copyPartialMatches(PartOfCommand, temp, completionList);
|
||||||
|
Loading…
Reference in New Issue
Block a user