mirror of
https://github.com/hnhx/xenon.git
synced 2025-01-09 11:07:18 -03:00
Merge pull request #2 from hnhx/revert-1-main
Revert "Improve code style and add a Config system"
This commit is contained in:
commit
590ce0a470
18 changed files with 111 additions and 222 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,2 @@
|
|||
dist
|
||||
api
|
||||
.idea
|
||||
api
|
|
@ -1,4 +1,4 @@
|
|||
main: xenon.Main
|
||||
main: xenon.main
|
||||
name: xenon
|
||||
version: 1.0
|
||||
api-version: 1.16
|
||||
|
|
|
@ -1,103 +0,0 @@
|
|||
package xenon;
|
||||
|
||||
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import xenon.commands.DiscordCommandExecutor;
|
||||
import xenon.commands.HelpCommandExecutor;
|
||||
import xenon.commands.StatsCommandExecutor;
|
||||
import xenon.commands.JoindateCommandExecutor;
|
||||
import xenon.commands.KillCommandExecutor;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import xenon.events.AntiIllegals;
|
||||
import xenon.events.AntiNetherRoof;
|
||||
import xenon.events.AntiSpam;
|
||||
import xenon.events.BoatflyPatch;
|
||||
import xenon.events.CustomChat;
|
||||
import xenon.events.CustomMessages;
|
||||
import xenon.events.CustomTab;
|
||||
import xenon.events.ElytraflyPatch;
|
||||
import xenon.events.LimitArmorStands;
|
||||
import xenon.events.RandomRespawn;
|
||||
import xenon.misc.Config;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hanna
|
||||
*/
|
||||
|
||||
public class Main extends JavaPlugin implements Listener {
|
||||
|
||||
private Config config;
|
||||
private static Main instance;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
this.config = new Config();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Get an instance of the main class
|
||||
instance = this;
|
||||
|
||||
// Initialize default config values if not set
|
||||
initConfig();
|
||||
|
||||
// Register commands and listeners
|
||||
registerListener();
|
||||
commandRegistration();
|
||||
|
||||
LimitArmorStands.limit();
|
||||
CustomTab.tab();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Save Config to file
|
||||
this.config.save();
|
||||
}
|
||||
|
||||
private void registerListener() {
|
||||
// Registering Bukkit Listeners
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
|
||||
pluginManager.registerEvents(new AntiIllegals(), this);
|
||||
pluginManager.registerEvents(new AntiNetherRoof(), this);
|
||||
pluginManager.registerEvents(new AntiSpam(), this);
|
||||
pluginManager.registerEvents(new BoatflyPatch(), this);
|
||||
pluginManager.registerEvents(new CustomChat(), this);
|
||||
pluginManager.registerEvents(new CustomMessages(), this);
|
||||
pluginManager.registerEvents(new ElytraflyPatch(), this);
|
||||
pluginManager.registerEvents(new RandomRespawn(), this);
|
||||
}
|
||||
|
||||
private void commandRegistration() {
|
||||
// Registering Bukkit commands
|
||||
this.getCommand("kill").setExecutor(new KillCommandExecutor());
|
||||
this.getCommand("help").setExecutor(new HelpCommandExecutor());
|
||||
this.getCommand("discord").setExecutor(new DiscordCommandExecutor());
|
||||
this.getCommand("stats").setExecutor(new StatsCommandExecutor());
|
||||
this.getCommand("joindate").setExecutor(new JoindateCommandExecutor());
|
||||
}
|
||||
|
||||
private void initConfig() {
|
||||
// Set default values
|
||||
if (this.config.getConfig().get("Discord") != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.config.getConfig().set("Discord", "https://discord.gg/gHn8aqTR5j");
|
||||
this.config.save();
|
||||
}
|
||||
|
||||
public Config getConfiguration() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public static Main getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
22
src/xenon/commands/Discord.java
Normal file
22
src/xenon/commands/Discord.java
Normal file
|
@ -0,0 +1,22 @@
|
|||
package xenon.commands;
|
||||
|
||||
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hanna
|
||||
*/
|
||||
public class Discord implements Listener, CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String labe, String[] args) {
|
||||
Player p = (Player) sender;
|
||||
p.sendMessage("§bClick on the link to join: §dhttps://discord.gg/gHn8aqTR5j");
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package xenon.commands;
|
||||
|
||||
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import xenon.Main;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hanna
|
||||
*/
|
||||
public class DiscordCommandExecutor implements Listener, CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String labe, String[] args) {
|
||||
Player p = (Player) sender;
|
||||
String discordLink;
|
||||
|
||||
if (Main.getInstance().getConfiguration().getConfig().get("Discord") == null) {
|
||||
discordLink = "https://discord.gg/gHn8aqTR5j";
|
||||
|
||||
Main.getInstance().getConfiguration().getConfig().set("Discord", "https://discord.gg/gHn8aqTR5j");
|
||||
Main.getInstance().getConfiguration().save();
|
||||
} else {
|
||||
discordLink = Main.getInstance().getConfiguration().getConfig().getString("Discord");
|
||||
}
|
||||
|
||||
p.sendMessage("§bClick on the link to join: §d" + discordLink);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -10,7 +10,7 @@ import org.bukkit.event.Listener;
|
|||
*
|
||||
* @author hanna
|
||||
*/
|
||||
public class HelpCommandExecutor implements Listener, CommandExecutor {
|
||||
public class Help implements Listener, CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String labe, String[] args) {
|
|
@ -15,7 +15,7 @@ import org.bukkit.event.Listener;
|
|||
*
|
||||
* @author hanna
|
||||
*/
|
||||
public class JoindateCommandExecutor implements Listener, CommandExecutor {
|
||||
public class Joindate implements Listener, CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String labe, String[] args) {
|
|
@ -10,7 +10,7 @@ import org.bukkit.event.Listener;
|
|||
*
|
||||
* @author hanna
|
||||
*/
|
||||
public class KillCommandExecutor implements Listener, CommandExecutor {
|
||||
public class Kill implements Listener, CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String labe, String[] args) {
|
|
@ -9,6 +9,7 @@ import java.nio.file.attribute.FileTime;
|
|||
import java.text.CharacterIterator;
|
||||
import java.text.StringCharacterIterator;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -20,7 +21,7 @@ import org.bukkit.event.Listener;
|
|||
*
|
||||
* @author hanna
|
||||
*/
|
||||
public class StatsCommandExecutor implements Listener, CommandExecutor {
|
||||
public class Stats implements Listener, CommandExecutor {
|
||||
|
||||
|
||||
@Override
|
|
@ -16,7 +16,7 @@ import org.bukkit.event.inventory.InventoryOpenEvent;
|
|||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import xenon.Main;
|
||||
import xenon.misc.Common;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -34,7 +34,7 @@ public class AntiIllegals implements Listener {
|
|||
Inventory inv = p.getInventory();
|
||||
revert(inv);
|
||||
}
|
||||
}.runTaskLater(Main.getInstance(), 1);
|
||||
}.runTaskLater(Common.getPlugin(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.bukkit.event.EventHandler;
|
|||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import xenon.Main;
|
||||
import xenon.misc.Common;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -47,6 +47,6 @@ public class AntiNetherRoof implements Listener {
|
|||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(Main.getInstance(), 0, 20);
|
||||
}.runTaskTimer(Common.getPlugin(), 0, 20);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package xenon.events;
|
|||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
|||
*/
|
||||
public class CustomMessages implements Listener {
|
||||
@EventHandler
|
||||
public void PlayerDeathEvent(PlayerDeathEvent event) {
|
||||
public void PlayerDeathEvent(PlayerDeathEvent event) {
|
||||
String pName = event.getEntity().getName();
|
||||
String dMessage = event.getDeathMessage().replace(pName + " ", "");
|
||||
event.setDeathMessage(String.format("§d%s §b%s",pName, dMessage));
|
||||
|
|
|
@ -6,15 +6,14 @@
|
|||
package xenon.events;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import net.minecraft.server.v1_16_R1.ChatComponentText;
|
||||
import net.minecraft.server.v1_16_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_16_R1.PacketPlayOutPlayerListHeaderFooter;
|
||||
import net.minecraft.server.v1_16_R3.ChatComponentText;
|
||||
import net.minecraft.server.v1_16_R3.MinecraftServer;
|
||||
import net.minecraft.server.v1_16_R3.PacketPlayOutPlayerListHeaderFooter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import xenon.Main;
|
||||
import xenon.misc.Common;
|
||||
import xenon.misc.GetElapsedTime;
|
||||
|
||||
/**
|
||||
|
@ -74,6 +73,6 @@ public class CustomTab {
|
|||
|
||||
}
|
||||
|
||||
}.runTaskTimer(Main.getInstance(), 0, 20);
|
||||
}.runTaskTimer(Common.getPlugin(), 0, 20);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.bukkit.event.EventHandler;
|
|||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import xenon.Main;
|
||||
import xenon.misc.Common;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -40,7 +40,7 @@ public class ElytraflyPatch implements Listener {
|
|||
Location curLocation = p.getLocation();
|
||||
double curDistanceFlown = curLocation.distanceSquared(prevLocation);
|
||||
|
||||
if (p.isGliding() && !p.getLocation().getBlock().isLiquid()) {
|
||||
if (p.isGliding() && !p.isInWater()) {
|
||||
if (glideStarted == null) glideStarted = curLocation;
|
||||
|
||||
if (distancesFlown.size() == 10) {
|
||||
|
@ -69,7 +69,7 @@ public class ElytraflyPatch implements Listener {
|
|||
prevLocation = curLocation;
|
||||
|
||||
}
|
||||
}.runTaskTimer(Main.getInstance(), 0, 3);
|
||||
}.runTaskTimer(Common.getPlugin(), 0, 3);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.bukkit.World;
|
|||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import xenon.Main;
|
||||
import xenon.misc.Common;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -32,6 +32,6 @@ public class LimitArmorStands {
|
|||
}
|
||||
}
|
||||
|
||||
}}.runTaskTimer(Main.getInstance(), 0, 20);
|
||||
}}.runTaskTimer(Common.getPlugin(), 0, 20);
|
||||
}
|
||||
}
|
||||
|
|
51
src/xenon/main.java
Normal file
51
src/xenon/main.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
package xenon;
|
||||
|
||||
|
||||
|
||||
import xenon.commands.Discord;
|
||||
import xenon.commands.Help;
|
||||
import xenon.commands.Stats;
|
||||
import xenon.commands.Joindate;
|
||||
import xenon.commands.Kill;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import xenon.events.AntiIllegals;
|
||||
import xenon.events.AntiNetherRoof;
|
||||
import xenon.events.AntiSpam;
|
||||
import xenon.events.BoatflyPatch;
|
||||
import xenon.events.CustomChat;
|
||||
import xenon.events.CustomMessages;
|
||||
import xenon.events.CustomTab;
|
||||
import xenon.events.ElytraflyPatch;
|
||||
import xenon.events.LimitArmorStands;
|
||||
import xenon.events.RandomRespawn;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hanna
|
||||
*/
|
||||
|
||||
public class main extends JavaPlugin implements Listener {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getServer().getPluginManager().registerEvents(new AntiIllegals(), this);
|
||||
getServer().getPluginManager().registerEvents(new AntiNetherRoof(), this);
|
||||
getServer().getPluginManager().registerEvents(new AntiSpam(), this);
|
||||
getServer().getPluginManager().registerEvents(new BoatflyPatch(), this);
|
||||
getServer().getPluginManager().registerEvents(new CustomChat(), this);
|
||||
getServer().getPluginManager().registerEvents(new CustomMessages(), this);
|
||||
getServer().getPluginManager().registerEvents(new ElytraflyPatch(), this);
|
||||
getServer().getPluginManager().registerEvents(new RandomRespawn(), this);
|
||||
|
||||
LimitArmorStands.limit();
|
||||
CustomTab.tab();
|
||||
|
||||
this.getCommand("kill").setExecutor(new Kill());
|
||||
this.getCommand("help").setExecutor(new Help());
|
||||
this.getCommand("discord").setExecutor(new Discord());
|
||||
this.getCommand("stats").setExecutor(new Stats());
|
||||
this.getCommand("joindate").setExecutor(new Joindate());
|
||||
|
||||
}
|
||||
}
|
14
src/xenon/misc/Common.java
Normal file
14
src/xenon/misc/Common.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
package xenon.misc;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hanna
|
||||
*/
|
||||
public class Common {
|
||||
public static Plugin getPlugin() {
|
||||
return Bukkit.getServer().getPluginManager().getPlugin("xenon");
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package xenon.misc;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Config {
|
||||
|
||||
private final File file;
|
||||
private final YamlConfiguration config;
|
||||
|
||||
public Config() {
|
||||
File dir = new File("./plugins/Xenon");
|
||||
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
this.file = new File(dir, "config.yml");
|
||||
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
this.config = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public YamlConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void reload(){
|
||||
try {
|
||||
config.load(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue