Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ repositories {
}

dependencies {
compileOnly 'io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT'
compileOnly 'io.papermc.paper:paper-api:1.19-R0.1-SNAPSHOT'

implementation 'com.github.CyberedCake:CyberAPI:v2.1.11'
implementation 'me.lucko:commodore:1.13'
implementation 'com.github.CyberedCake:CyberAPI:v3.0.3-spigot'
implementation 'me.lucko:commodore:2.0'
}

shadowJar {
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/net/cybercake/fallback/Commodore.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

import com.mojang.brigadier.tree.LiteralCommandNode;
import me.lucko.commodore.CommodoreProvider;
import me.lucko.commodore.file.CommodoreFileFormat;
import me.lucko.commodore.file.CommodoreFileReader;
import net.cybercake.cyberapi.chat.Log;
import org.bukkit.command.PluginCommand;

import java.io.IOException;

public class Commodore {

public static void register(PluginCommand pluginCommand, String fileName) throws IOException {
LiteralCommandNode<?> timeCommand = CommodoreFileFormat.parse(Main.getPlugin().getResource("commodore/" + fileName + ".commodore"));
CommodoreProvider.getCommodore(Main.getPlugin()).register(pluginCommand, timeCommand);
try {
LiteralCommandNode<?> commandProvided = CommodoreFileReader.INSTANCE.parse(Main.getInstance().getResource("commodore/" + fileName + ".commodore"));
CommodoreProvider.getCommodore(Main.getInstance()).register(pluginCommand, commandProvided);
}catch (Exception ignored) {
Log.error("Commodore file for command \"" + fileName + "\" not found");
}
}

}
}
10 changes: 5 additions & 5 deletions src/main/java/net/cybercake/fallback/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.cybercake.fallback;

import net.cybercake.cyberapi.Log;
import net.cybercake.cyberapi.chat.Log;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
Expand All @@ -19,10 +19,10 @@ public class Configuration {
private boolean playerVisibility;

public void reload() {
Main.getPlugin().saveDefaultConfig();
Main.getPlugin().reloadConfig();
Main.getInstance().saveDefaultConfig();
Main.getInstance().reloadConfig();

FileConfiguration config = Main.getMainConfig();
FileConfiguration config = Main.getInstance().getMainConfig().values();

this.connectTo = config.getString("connectTo");
this.connectionInterval = config.getInt("connectionInterval");
Expand All @@ -32,7 +32,7 @@ public void reload() {
this.spawn = new Location(world, config.getDouble("spawnAt.x"), config.getDouble("spawnAt.y"), config.getDouble("spawnAt.z"), config.getInt("spawnAt.yaw"), config.getInt("spawnAt.pitch"));
}else{
Log.warn("You have put an invalid world in your configuration file! Set to default values for now...");
this.spawn = new Location(Main.getPlugin().getServer().getWorlds().get(0), 0.0, 100.0, 0.0, 0, 0);
this.spawn = new Location(Main.getInstance().getServer().getWorlds().get(0), 0.0, 100.0, 0.0, 0, 0);
}

this.joinLeaveEvents = config.getBoolean("disable.joinLeaveMessages");
Expand Down
29 changes: 19 additions & 10 deletions src/main/java/net/cybercake/fallback/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import me.lucko.commodore.CommodoreProvider;
import net.cybercake.cyberapi.CyberAPI;
import net.cybercake.cyberapi.Log;
import net.cybercake.cyberapi.basic.BetterStackTraces;
import net.cybercake.cyberapi.basic.StringUtils;
import net.cybercake.cyberapi.chat.Log;
import net.cybercake.cyberapi.chat.UChat;
import net.cybercake.cyberapi.exceptions.BetterStackTraces;
import net.cybercake.cyberapi.instances.Spigot;
import net.cybercake.cyberapi.settings.Settings;
import net.cybercake.fallback.commands.AttemptConnect;
import net.cybercake.fallback.commands.FallbackReload;
import net.cybercake.fallback.listeners.ChatEvent;
Expand All @@ -17,12 +18,13 @@
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;

public final class Main extends Spigot {
public final class Main extends CyberAPI {

private static Main instance;

Expand All @@ -32,8 +34,15 @@ public final class Main extends Spigot {
public void onEnable() {
long mss = System.currentTimeMillis();
instance = this;
CyberAPI.silenceLogs(true);
CyberAPI.initSpigot(this, true);

startCyberAPI(new Settings()
.name("Fallback")
.prefix("Fallback")
.checkForUpdates(false)
.silenced(true)
.showPrefixInLogs(true)
.build()
);

configuration = new Configuration();
Log.info("Loaded the configuration!");
Expand Down Expand Up @@ -77,16 +86,17 @@ public void onDisable() {
public @NotNull Configuration getConfiguration() { return configuration; }

public void send(Player player, String server) {
player.sendMessage(UChat.getClearedChat());
if(server.equalsIgnoreCase("$$configuration")) server = getConfiguration().getConnectTo();
player.sendMessage(UChat.component("&6Sending you to &a" + server + "&6!"));
player.sendMessage(UChat.component("&7Sending you to &b" + server + ""));
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteArrayOutputStream);

out.writeUTF("Connect");
out.writeUTF(server);

player.sendPluginMessage(Main.getPlugin(), "BungeeCord", byteArrayOutputStream.toByteArray());
player.sendPluginMessage(Main.getInstance(), "BungeeCord", byteArrayOutputStream.toByteArray());

byteArrayOutputStream.close();
out.close();
Expand All @@ -98,8 +108,7 @@ public void send(Player player, String server) {

public static void registerCommandAndTab(String name, Object commandExecutor, boolean withCommodore) {
try {
registerCommand(name, (CommandExecutor)commandExecutor);
registerTabCompleter(name, (TabCompleter)commandExecutor);
Main.getInstance().registerCommand(name, (CommandExecutor) commandExecutor);
if(withCommodore) {
if(CommodoreProvider.isSupported()) {
Commodore.register(Bukkit.getPluginCommand(name), name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}

if(args.length < 1) {
player.sendMessage(UChat.component("&6Attempting to connect you to default server &2(&a" + Main.getInstance().getConfiguration().getConnectTo() + "&2)&6..."));
player.sendMessage(UChat.component("&7Attempting to connect you to default server &8(&b" + Main.getInstance().getConfiguration().getConnectTo() + "&8)&7..."));
Main.getInstance().send(player, "$$configuration");
}else{
player.sendMessage(UChat.component("&6Attempting to connect you to &a" + args[0] + "&6..."));
player.sendMessage(UChat.component("&7Attempting to connect you to &b" + args[0] + "&7..."));
Main.getInstance().send(player, args[0]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package net.cybercake.fallback.commands;

import net.cybercake.cyberapi.basic.BetterStackTraces;
import net.cybercake.cyberapi.chat.UChat;
import net.cybercake.cyberapi.chat.UTabComp;
import net.cybercake.cyberapi.exceptions.BetterStackTraces;
import net.cybercake.cyberapi.instances.Spigot;
import net.cybercake.fallback.Main;
import org.bukkit.Sound;
import org.bukkit.command.Command;
Expand All @@ -24,8 +23,8 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command

Main.getInstance().getConfiguration().reload();

sender.sendMessage(UChat.component("&6Successfully reloaded the fallback configuration in &a" + (System.currentTimeMillis()-mss) + "&ams&6!"));
Spigot.playSound(sender, Sound.ENTITY_PLAYER_LEVELUP, 1F, 1F);
sender.sendMessage(UChat.component("&aSuccessfully &7reloaded the fallback configuration in &b" + (System.currentTimeMillis()-mss) + "&bms&7!"));
Main.getInstance().playSound(sender, Sound.ENTITY_PLAYER_LEVELUP, 1F, 1F);
} catch (Exception exception) {
sender.sendMessage(UChat.component("&cAn error occurred whilst reloading the fallback configuration! &4" + exception));
BetterStackTraces.print(exception);
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/net/cybercake/fallback/listeners/DamageEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.cybercake.fallback.listeners;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.PlayerDeathEvent;

public class DamageEvent implements Listener {

@EventHandler
public void onDamage(EntityDamageEvent event) {
if (!(event.getEntity() instanceof Player player)) { return; }

event.setCancelled(true);
}

@EventHandler
public void onDeath(PlayerDeathEvent event) {
event.setCancelled(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void onJoin(PlayerJoinEvent event) {
Configuration configuration = Main.getInstance().getConfiguration();

Player player = event.getPlayer();
if(configuration.disableVisibility()) Bukkit.getOnlinePlayers().forEach(player1 -> player.hidePlayer(Main.getPlugin(), player1));
if(configuration.disableVisibility()) Bukkit.getOnlinePlayers().forEach(player1 -> player.hidePlayer(Main.getInstance(), player1));

if(!configuration.disableJoinLeaveEvents()) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class AttemptToSend implements Runnable {
public void run() {
boolean disableVisibility = Main.getInstance().getConfiguration().disableVisibility();
Bukkit.getOnlinePlayers().forEach(player -> {
if(disableVisibility) Bukkit.getOnlinePlayers().forEach(player1 -> player.hidePlayer(Main.getPlugin(), player1));
if(disableVisibility) Bukkit.getOnlinePlayers().forEach(player1 -> player.hidePlayer(Main.getInstance(), player1));

Main.getInstance().send(player, "$$configuration");
});
Expand Down