Skip to content

Commit

Permalink
Add all sorts of things, read v1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Efnilite committed Jan 5, 2021
1 parent 2141d69 commit 4b92313
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 91 deletions.
99 changes: 57 additions & 42 deletions src/main/java/dev/efnilite/witp/ParkourPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
Expand All @@ -43,18 +44,16 @@ public class ParkourPlayer {
public @Expose Boolean useParticles;
public @Expose Boolean useSpecial;
public @Expose Boolean showDeathMsg;
public @Expose Boolean showScoreboard;
public @Expose Boolean useStructure;
public @Expose String time;
public @Expose String style;
public @Expose String lang;


/**
* The player's points
*/
public UUID openInventory;
private FastBoard board;
private List<Material> possibleStyle;
private final GameMode previousGamemode;
private final Location previousLocation;
private final HashMap<Integer, ItemStack> previousInventory;
private final File file;
Expand All @@ -69,18 +68,21 @@ public class ParkourPlayer {
* If you are using the API, please use {@link WITPAPI#registerPlayer(Player)} instead
*/
public ParkourPlayer(@NotNull Player player, int highScore, String time, String style, int blockLead, boolean useParticles,
boolean useDifficulty, boolean useStructure, boolean showScoreboard, boolean showDeathMsg) {
boolean useDifficulty, boolean useStructure, boolean useSpecial, boolean showDeathMsg, boolean showScoreboard) {
this.previousLocation = player.getLocation().clone();
this.previousGamemode = player.getGameMode();
this.previousInventory = new HashMap<>();
int index = 0;
Inventory inventory = player.getInventory();
for (ItemStack item : inventory.getContents()) {
if (item != null) {
previousInventory.put(index, item);
if (ParkourGenerator.Configurable.INVENTORY_HANDLING) {
int index = 0;
Inventory inventory = player.getInventory();
for (ItemStack item : inventory.getContents()) {
if (item != null) {
previousInventory.put(index, item);
}
index++;
}
index++;
}
this.useSpecial = showScoreboard;
this.useSpecial = useSpecial;
this.showDeathMsg = showDeathMsg;
this.highScore = highScore;
this.blockLead = blockLead;
Expand All @@ -89,6 +91,7 @@ public ParkourPlayer(@NotNull Player player, int highScore, String time, String
this.time = time;
this.useDifficulty = useDifficulty;
this.useStructure = useStructure;
this.showScoreboard = showScoreboard;

this.file = new File(WITP.getInstance().getDataFolder() + "/players/" + player.getUniqueId().toString() + ".json");
this.player = player;
Expand All @@ -99,7 +102,7 @@ public ParkourPlayer(@NotNull Player player, int highScore, String time, String

player.setPlayerTime(getTime(time), false);
WITP.getDivider().generate(this);
if (showDeathMsg && ParkourGenerator.Configurable.SCOREBOARD) {
if (showScoreboard && ParkourGenerator.Configurable.SCOREBOARD) {
updateScoreboard();
}
if (player.isOp() && WITP.isOutdated) {
Expand All @@ -126,9 +129,9 @@ public ParkourPlayer(@NotNull Player player, int highScore, String time, String
* @param replaceable
* What can be replaced (for example: %s to yes)
*/
public void sendTranslated(String path, String... replaceable) {
path = "lang." + lang + "." + path;
String string = WITP.getConfiguration().getString("lang", path);
public void sendTranslated(String path, String... replaceable) { // todo add lang.yml
path = "messages." + path;
String string = WITP.getConfiguration().getString("config", path);
if (string == null) {
Verbose.error("Unknown path: " + path);
return;
Expand Down Expand Up @@ -287,7 +290,7 @@ public void menu() {
Material particles = useParticles ? Material.GREEN_WOOL : Material.RED_WOOL;
String particlesString = Boolean.toString(useParticles);
String particlesValue = Util.normalizeBoolean(Util.colorBoolean(particlesString));
builder.setItem(14, new ItemBuilder(particles, "&a&lUse particles and sounds")
builder.setItem(13, new ItemBuilder(particles, "&a&lUse particles and sounds")
.setLore("&7If enabled every generated block", "&7will show particles and play a sound.", "",
"&7Currently: " + particlesValue).build(), (t2, e2) -> {
useParticles = !useParticles;
Expand All @@ -296,20 +299,32 @@ public void menu() {
saveStats();
player.closeInventory();
});
Material deathMsg = showDeathMsg ? Material.GREEN_WOOL : Material.RED_WOOL;
String deathString = Boolean.toString(showDeathMsg);
String deathValue = Util.normalizeBoolean(Util.colorBoolean(deathString));
builder.setItem(15, new ItemBuilder(deathMsg, "&a&lShow fall message & scoreboard")
.setLore("&7If enabled shows a message when you fall", "&7with extra info and the scoreboard", "",
"&7Currently: " + deathValue).build(), (t2, e2) -> {
showDeathMsg = !showDeathMsg;
if (showDeathMsg) {
Material scoreboard = showScoreboard ? Material.GREEN_WOOL : Material.RED_WOOL;
String scoreboardString = Boolean.toString(showScoreboard);
String scoreboardValue = Util.normalizeBoolean(Util.colorBoolean(scoreboardString));
builder.setItem(14, new ItemBuilder(scoreboard, "&a&lShow scoreboard")
.setLore("&7If enabled shows the scoreboard", "",
"&7Currently: " + scoreboardValue).build(), (t2, e2) -> {
showScoreboard = !showScoreboard;
if (showScoreboard) {
board = new FastBoard(player);
updateScoreboard();
} else {
board.delete();
}
send("&7You changed your showing of the fall message and scoreboard to " +
send("&7You changed your usage of the scoreboard to " +
Util.normalizeBoolean(Util.colorBoolean(Util.reverseBoolean(scoreboardString))));
saveStats();
player.closeInventory();
});
Material deathMsg = showDeathMsg ? Material.GREEN_WOOL : Material.RED_WOOL;
String deathString = Boolean.toString(showDeathMsg);
String deathValue = Util.normalizeBoolean(Util.colorBoolean(deathString));
builder.setItem(15, new ItemBuilder(deathMsg, "&a&lShow fall message")
.setLore("&7If enabled shows a message when you fall", "&7with extra info", "",
"&7Currently: " + deathValue).build(), (t2, e2) -> {
showDeathMsg = !showDeathMsg;
send("&7You changed your showing of the fall message to " +
Util.normalizeBoolean(Util.colorBoolean(Util.reverseBoolean(deathString))));
saveStats();
player.closeInventory();
Expand Down Expand Up @@ -416,7 +431,7 @@ public void save() throws IOException {
* @param messages
* The message
*/
public void send(@NotNull String... messages) {
public void send(String... messages) {
for (String msg : messages) {
player.sendMessage(Util.color(msg));
}
Expand Down Expand Up @@ -477,7 +492,7 @@ public void scoreboard(int page) {
.create();

player.spigot().sendMessage(previous);
send("&7----------------------------------------");
send(WITP.getConfiguration().getString("config", "messages.divider"));
}

/**
Expand Down Expand Up @@ -537,16 +552,20 @@ private int getRank(UUID player) {
if (from.useStructure == null) {
from.useStructure = true;
}
if (from.showScoreboard == null) {
from.showScoreboard = true;
}
ParkourPlayer pp = new ParkourPlayer(player, from.highScore, from.time, from.style, from.blockLead,
from.useParticles, from.useDifficulty, from.useStructure, from.useSpecial, from.showDeathMsg);
from.useParticles, from.useDifficulty, from.useStructure, from.useSpecial, from.showDeathMsg, from.showScoreboard);
pp.save();
players.put(player, pp);
reader.close();
return pp;
} else {
ParkourPlayer pp = new ParkourPlayer(player, 0, "Day",
WITP.getConfiguration().getString("config", "styles.default"),
4, true, true, true, true, true);
4, true, true, true, true,
true, true);
players.put(player, pp);
pp.save();
return pp;
Expand Down Expand Up @@ -639,10 +658,14 @@ public static void unregister(@NotNull ParkourPlayer player, boolean sendBack) t
Util.sendPlayer(player.getPlayer(), WITP.getConfiguration().getString("config", "bungeecord.return_server"));
} else {
Player pl = player.getPlayer();
pl.getInventory().clear();
pl.teleport(player.getPreviousLocation());
for (int slot : player.getPreviousInventory().keySet()) {
pl.getInventory().setItem(slot, player.getPreviousInventory().get(slot));
WITP.getVersionManager().setWorldBorder(player.player, new Vector().zero(), 29999984);
pl.setGameMode(player.previousGamemode);
pl.teleport(player.previousLocation);
if (ParkourGenerator.Configurable.INVENTORY_HANDLING) {
pl.getInventory().clear();
for (int slot : player.previousInventory.keySet()) {
pl.getInventory().setItem(slot, player.previousInventory.get(slot));
}
}
pl.resetPlayerTime();
}
Expand All @@ -666,12 +689,4 @@ public ParkourGenerator getGenerator() {
public @NotNull Player getPlayer() {
return player;
}

public HashMap<Integer, ItemStack> getPreviousInventory() {
return previousInventory;
}

public Location getPreviousLocation() {
return previousLocation;
}
}
22 changes: 20 additions & 2 deletions src/main/java/dev/efnilite/witp/WITP.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.efnilite.witp.util.Configuration;
import dev.efnilite.witp.util.Util;
import dev.efnilite.witp.util.Verbose;
import dev.efnilite.witp.util.VoidGenerator;
import dev.efnilite.witp.util.task.Tasks;
import dev.efnilite.witp.util.web.Metrics;
import dev.efnilite.witp.util.web.UpdateChecker;
Expand All @@ -30,9 +31,12 @@
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;

Expand Down Expand Up @@ -98,13 +102,27 @@ private void addCommand(String name, BukkitCommand wrapper) {
command.setTabCompleter(wrapper);
}

@Nullable
@Override
public ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, @Nullable String id) {
String config = WITP.getConfiguration().getString("config", "world.name");
if (config == null) {
Verbose.error("World name is null");
config = "witp";
}
if (worldName.equalsIgnoreCase(config)) {
return new VoidGenerator();
}
return super.getDefaultWorldGenerator(worldName, id);
}

@EventHandler
public void join(PlayerJoinEvent event) {
Player player = event.getPlayer();
World world = WITP.getDivider().getWorld();
if (configuration.getFile("config").getBoolean("bungeecord.enabled")) {
if (configuration.getFile("config").getBoolean("messages.join-leave-enabled")) {
event.setJoinMessage(configuration.getString("config", "messages.join").replaceAll("%p",
event.setJoinMessage(configuration.getString("config", "messages.join").replaceAll("%[a-z]",
player.getName()));
}
try {
Expand All @@ -114,7 +132,7 @@ public void join(PlayerJoinEvent event) {
Verbose.error("Something went wrong while trying to fetch a player's (" + player.getName() + ") data");
}
} else if (player.getWorld() == WITP.getDivider().getWorld()) {
World fallback = Bukkit.getWorld(configuration.getString("config", "world.fall_back"));
World fallback = Bukkit.getWorld(configuration.getString("config", "world.fall-back"));
if (fallback != null) {
player.teleport(fallback.getSpawnLocation());
} else {
Expand Down
50 changes: 39 additions & 11 deletions src/main/java/dev/efnilite/witp/command/MainCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import dev.efnilite.witp.util.Verbose;
import dev.efnilite.witp.util.wrapper.BukkitCommand;
import dev.efnilite.witp.version.VersionManager_v1_16_R3;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;

import java.io.File;
Expand All @@ -16,15 +19,23 @@
public class MainCommand extends BukkitCommand {

@Override
public boolean execute(Player player, String[] args) {
public boolean execute(CommandSender sender, String[] args) {
Player player = null;
if (sender instanceof Player) {
player = (Player) sender;
}
if (args.length == 0) {
player.sendMessage(Util.color("&7--------------- &aWITP &7---------------"));
player.sendMessage(Util.color("&a/witp &f- &7Main command"));
player.sendMessage(Util.color("&a/witp join &f- &7Join the game on this server"));
player.sendMessage(Util.color("&a/witp leave &f- &7Leave the game on this server"));
player.sendMessage(Util.color("&a/witp customize &f- &7Open the customization menu"));
sender.sendMessage(Util.color("&7--------------- &aWITP &7---------------"));
sender.sendMessage(Util.color("&a/witp &f- &7Main command"));
sender.sendMessage(Util.color("&a/witp join [player] &f- &7Join the game on this server or make another player join"));
sender.sendMessage(Util.color("&a/witp leave &f- &7Leave the game on this server"));
sender.sendMessage(Util.color("&a/witp menu &f- &7Open the customization menu"));
sender.sendMessage(Util.color("&a/witp leaderboard &f- &7Open the leaderboard"));
return true;
} else if (args.length == 1) {
if (player == null) {
return true;
}
if (args[0].equalsIgnoreCase("join")) {
try {
ParkourPlayer.register(player);
Expand All @@ -33,34 +44,51 @@ public boolean execute(Player player, String[] args) {
pp.send("&aYou joined the parkour");
}
} catch (IOException ex) {
Verbose.error("Error while joining");
ex.printStackTrace();
Verbose.error("Error while joining");
}
return true;
} else if (args[0].equalsIgnoreCase("leave")) {
ParkourPlayer pp = ParkourPlayer.getPlayer(player);
if (pp != null) {
try {
pp.send("&cYou left the parkour");
ParkourPlayer.unregister(pp, true);
} catch (IOException ex) {
Verbose.error("Error while leaving");
ex.printStackTrace();
Verbose.error("Error while leaving");
}
}
} else if (args[0].equalsIgnoreCase("customize")) {
} else if (args[0].equalsIgnoreCase("menu")) {
ParkourPlayer pp = ParkourPlayer.getPlayer(player);
if (pp != null) {
pp.menu();
}
}
} else if (args.length == 2) {
if (args[0].equalsIgnoreCase("leaderboard") && args[1] != null) {
if (args[0].equalsIgnoreCase("leaderboard") && args[1] != null && player != null) {
int page = Integer.parseInt(args[1]);
ParkourPlayer pp = ParkourPlayer.getPlayer(player);
if (pp != null) {
pp.scoreboard(page);
}
} else if (args[0].equalsIgnoreCase("join") && args[1] != null) {
if (sender.isOp()) {
Player join = Bukkit.getPlayer(args[1]);
if (join == null) {
Verbose.error("Player " + args[1] + " doesn't exist!");
return true;
}
try {
ParkourPlayer.register(join);
ParkourPlayer pp = ParkourPlayer.getPlayer(join);
if (pp != null) {
pp.send("&aYou joined the parkour");
}
} catch (IOException ex) {
ex.printStackTrace();
Verbose.error("Error while joining");
}
}
}
}
return true;
Expand Down
Loading

0 comments on commit 4b92313

Please sign in to comment.