initial
This commit is contained in:
7
.classpath
Normal file
7
.classpath
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Schulä/Desktop/Dropbox/Server/craftbukkit.jar"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
72
.gitignore
vendored
Normal file
72
.gitignore
vendored
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
|
||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/eclipse
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=eclipse
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.metadata
|
||||||
|
bin/
|
||||||
|
tmp/
|
||||||
|
*.tmp
|
||||||
|
*.bak
|
||||||
|
*.swp
|
||||||
|
*~.nib
|
||||||
|
local.properties
|
||||||
|
.settings/
|
||||||
|
.loadpath
|
||||||
|
.recommenders
|
||||||
|
|
||||||
|
# External tool builders
|
||||||
|
.externalToolBuilders/
|
||||||
|
|
||||||
|
# Locally stored "Eclipse launch configurations"
|
||||||
|
*.launch
|
||||||
|
|
||||||
|
# PyDev specific (Python IDE for Eclipse)
|
||||||
|
*.pydevproject
|
||||||
|
|
||||||
|
# CDT-specific (C/C++ Development Tooling)
|
||||||
|
.cproject
|
||||||
|
|
||||||
|
# CDT- autotools
|
||||||
|
.autotools
|
||||||
|
|
||||||
|
# Java annotation processor (APT)
|
||||||
|
.factorypath
|
||||||
|
|
||||||
|
# PDT-specific (PHP Development Tools)
|
||||||
|
.buildpath
|
||||||
|
|
||||||
|
# sbteclipse plugin
|
||||||
|
.target
|
||||||
|
|
||||||
|
# Tern plugin
|
||||||
|
.tern-project
|
||||||
|
|
||||||
|
# TeXlipse plugin
|
||||||
|
.texlipse
|
||||||
|
|
||||||
|
# STS (Spring Tool Suite)
|
||||||
|
.springBeans
|
||||||
|
|
||||||
|
# Code Recommenders
|
||||||
|
.recommenders/
|
||||||
|
|
||||||
|
# Annotation Processing
|
||||||
|
.apt_generated/
|
||||||
|
.apt_generated_test/
|
||||||
|
|
||||||
|
# Scala IDE specific (Scala & Java development for Eclipse)
|
||||||
|
.cache-main
|
||||||
|
.scala_dependencies
|
||||||
|
.worksheet
|
||||||
|
|
||||||
|
# Uncomment this line if you wish to ignore the project description file.
|
||||||
|
# Typically, this file would be tracked if it contains build/dependency configurations:
|
||||||
|
#.project
|
||||||
|
|
||||||
|
### Eclipse Patch ###
|
||||||
|
# Spring Boot Tooling
|
||||||
|
.sts4-cache/
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/eclipse
|
||||||
|
|
||||||
17
.project
Normal file
17
.project
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>GuestSpawn</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
11
.settings/org.eclipse.jdt.core.prefs
Normal file
11
.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.source=1.6
|
||||||
50
src/me/Caesar2011/GuestSpawn/Commands/Cmd_Help.java
Normal file
50
src/me/Caesar2011/GuestSpawn/Commands/Cmd_Help.java
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package me.Caesar2011.GuestSpawn.Commands;
|
||||||
|
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.EnumCmdExe;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.Messenger;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class Cmd_Help {
|
||||||
|
CommandSender sender;
|
||||||
|
private String[] args;
|
||||||
|
|
||||||
|
public Cmd_Help(CommandSender sender, String[] args){
|
||||||
|
this.sender = sender;
|
||||||
|
this.args = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnumCmdExe execute(){
|
||||||
|
if (args.length == 0){
|
||||||
|
args = new String[]{"1"};
|
||||||
|
return execute();
|
||||||
|
} else if (args[0].equalsIgnoreCase("1")){
|
||||||
|
Messenger.sendPlyHeader(sender,"Help - Shortcuts - Page 1");
|
||||||
|
Messenger.sendPlyHelp(sender,"Show help","/ghelp [Page]");
|
||||||
|
Messenger.sendPlyHelp(sender,"Set new guest spawn","/gsetspawn");
|
||||||
|
Messenger.sendPlyHelp(sender,"Teleport to guest spawn","/gspawn");
|
||||||
|
Messenger.sendPlyHelp(sender,"Remove guest spawn","/greset");
|
||||||
|
Messenger.sendPlyHelp(sender,"Reload config","/greload");
|
||||||
|
return EnumCmdExe.SUCCESS;
|
||||||
|
} else if (args[0].equalsIgnoreCase("2")){
|
||||||
|
Messenger.sendPlyHeader(sender,"Help - Longcuts - Page 2");
|
||||||
|
Messenger.sendPlyHelp(sender,"Show help","/guesthelp [Page]");
|
||||||
|
Messenger.sendPlyHelp(sender,"Set new guest spawn","/guestsetspawn");
|
||||||
|
Messenger.sendPlyHelp(sender,"Teleport to guest spawn","/guestspawn");
|
||||||
|
Messenger.sendPlyHelp(sender,"Remove guest spawn","/guestreset");
|
||||||
|
Messenger.sendPlyHelp(sender,"Reload config","/guestreload");
|
||||||
|
return EnumCmdExe.SUCCESS;
|
||||||
|
} else if (args[0].equalsIgnoreCase("3")){
|
||||||
|
Messenger.sendPlyHeader(sender,"Help - Longcuts - Page 3");
|
||||||
|
Messenger.sendPlyHelp(sender,"Show help","/guestspawnhelp [Page]");
|
||||||
|
Messenger.sendPlyHelp(sender,"Set new guest spawn","/guestspawnsetspawn");
|
||||||
|
Messenger.sendPlyHelp(sender,"Teleport to guest spawn","/guestspawnspawn");
|
||||||
|
Messenger.sendPlyHelp(sender,"Remove guest spawn","/guestspawnreset");
|
||||||
|
Messenger.sendPlyHelp(sender,"Reload config","/guestspawnreload");
|
||||||
|
return EnumCmdExe.SUCCESS;
|
||||||
|
} else {
|
||||||
|
args = new String[]{};
|
||||||
|
return execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/me/Caesar2011/GuestSpawn/Commands/Cmd_Reload.java
Normal file
29
src/me/Caesar2011/GuestSpawn/Commands/Cmd_Reload.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package me.Caesar2011.GuestSpawn.Commands;
|
||||||
|
|
||||||
|
import me.Caesar2011.GuestSpawn.GuestSpawn;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.EnumCmdExe;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.EnumPerm;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.Messenger;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class Cmd_Reload {
|
||||||
|
GuestSpawn plugin;
|
||||||
|
CommandSender sender;
|
||||||
|
|
||||||
|
public Cmd_Reload(CommandSender sender, GuestSpawn plugin){
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.sender = sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnumCmdExe execute(){
|
||||||
|
//Permissioncheck
|
||||||
|
if (EnumPerm.RELOAD.noPermission(sender)){
|
||||||
|
return EnumCmdExe.NOPERM;
|
||||||
|
}
|
||||||
|
ConfigManager.onReload();
|
||||||
|
Messenger.onEnable();
|
||||||
|
return EnumCmdExe.RELOAD;
|
||||||
|
}
|
||||||
|
}
|
||||||
26
src/me/Caesar2011/GuestSpawn/Commands/Cmd_Reset.java
Normal file
26
src/me/Caesar2011/GuestSpawn/Commands/Cmd_Reset.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package me.Caesar2011.GuestSpawn.Commands;
|
||||||
|
|
||||||
|
import me.Caesar2011.GuestSpawn.GuestSpawn;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.EnumCmdExe;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.EnumPerm;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class Cmd_Reset {
|
||||||
|
CommandSender sender;
|
||||||
|
GuestSpawn plugin;
|
||||||
|
|
||||||
|
public Cmd_Reset(CommandSender sender){
|
||||||
|
this.sender = sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnumCmdExe execute(){
|
||||||
|
//Permissioncheck
|
||||||
|
if (EnumPerm.RESET.noPermission(sender)){
|
||||||
|
return EnumCmdExe.NOPERM;
|
||||||
|
}
|
||||||
|
ConfigManager.setGuestSpawnLoc(null);
|
||||||
|
return EnumCmdExe.RESET;
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/me/Caesar2011/GuestSpawn/Commands/Cmd_Setspawn.java
Normal file
31
src/me/Caesar2011/GuestSpawn/Commands/Cmd_Setspawn.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package me.Caesar2011.GuestSpawn.Commands;
|
||||||
|
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.EnumCmdExe;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.EnumPerm;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Cmd_Setspawn {
|
||||||
|
CommandSender sender;
|
||||||
|
|
||||||
|
public Cmd_Setspawn(CommandSender sender){
|
||||||
|
this.sender = sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnumCmdExe execute(){
|
||||||
|
//Permissioncheck
|
||||||
|
Player p;
|
||||||
|
if (!(sender instanceof Player)){
|
||||||
|
return EnumCmdExe.NOCONSOLE;
|
||||||
|
} else {
|
||||||
|
p = (Player) sender;
|
||||||
|
}
|
||||||
|
if (EnumPerm.SETSPAWN.noPermission(p)){
|
||||||
|
return EnumCmdExe.NOPERM;
|
||||||
|
}
|
||||||
|
ConfigManager.setGuestSpawnLoc(p.getLocation());
|
||||||
|
return EnumCmdExe.SET;
|
||||||
|
}
|
||||||
|
}
|
||||||
41
src/me/Caesar2011/GuestSpawn/Commands/Cmd_Spawn.java
Normal file
41
src/me/Caesar2011/GuestSpawn/Commands/Cmd_Spawn.java
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package me.Caesar2011.GuestSpawn.Commands;
|
||||||
|
|
||||||
|
import me.Caesar2011.GuestSpawn.GuestSpawn;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.EnumCmdExe;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.EnumPerm;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
|
|
||||||
|
public class Cmd_Spawn {
|
||||||
|
CommandSender sender;
|
||||||
|
GuestSpawn plugin;
|
||||||
|
|
||||||
|
public Cmd_Spawn(CommandSender sender, GuestSpawn plugin){
|
||||||
|
this.sender = sender;
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnumCmdExe execute(){
|
||||||
|
Player p;
|
||||||
|
if (!(sender instanceof Player)){
|
||||||
|
return EnumCmdExe.NOCONSOLE;
|
||||||
|
} else {
|
||||||
|
p = (Player) sender;
|
||||||
|
}
|
||||||
|
//Permissioncheck
|
||||||
|
if (EnumPerm.SPAWN.noPermission(p)){
|
||||||
|
return EnumCmdExe.NOPERM;
|
||||||
|
}
|
||||||
|
Location loc = ConfigManager.getGuestSpawnLoc(plugin);
|
||||||
|
if (loc != null) {
|
||||||
|
p.teleport(loc, TeleportCause.PLUGIN);
|
||||||
|
return EnumCmdExe.TELEPORT;
|
||||||
|
} else {
|
||||||
|
return EnumCmdExe.NOSET;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
69
src/me/Caesar2011/GuestSpawn/GuestSpawn.java
Normal file
69
src/me/Caesar2011/GuestSpawn/GuestSpawn.java
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
package me.Caesar2011.GuestSpawn;
|
||||||
|
|
||||||
|
import me.Caesar2011.GuestSpawn.Commands.Cmd_Help;
|
||||||
|
import me.Caesar2011.GuestSpawn.Commands.Cmd_Reload;
|
||||||
|
import me.Caesar2011.GuestSpawn.Commands.Cmd_Reset;
|
||||||
|
import me.Caesar2011.GuestSpawn.Commands.Cmd_Setspawn;
|
||||||
|
import me.Caesar2011.GuestSpawn.Commands.Cmd_Spawn;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.EnumCmdExe;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.Messenger;
|
||||||
|
import me.Caesar2011.GuestSpawn.Listener.Listener_PlayerJoin;
|
||||||
|
import me.Caesar2011.GuestSpawn.Listener.Listener_PlayerRespawn;
|
||||||
|
import me.Caesar2011.GuestSpawn.Listener.Listener_PlayerTeleport;
|
||||||
|
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public class GuestSpawn extends JavaPlugin {
|
||||||
|
public OfflinePlayer[] players;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
//Enable-Stuff
|
||||||
|
|
||||||
|
ConfigManager.onEnable();
|
||||||
|
Messenger.onEnable();
|
||||||
|
|
||||||
|
new Listener_PlayerJoin(this);
|
||||||
|
new Listener_PlayerTeleport(this);
|
||||||
|
new Listener_PlayerRespawn(this);
|
||||||
|
|
||||||
|
players = this.getServer().getOfflinePlayers();
|
||||||
|
System.out.println("[" + this.getName() + "] Plugin activated successfully.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
//Disable-Stuff
|
||||||
|
|
||||||
|
System.out.println("[" + this.getName() + "] Plugin deactivated successfully.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args){
|
||||||
|
EnumCmdExe result = EnumCmdExe.UNKNOWN;
|
||||||
|
if(cmd.getName().equalsIgnoreCase("ghelp")){
|
||||||
|
result = new Cmd_Help(sender, args).execute();
|
||||||
|
} else if (cmd.getName().equalsIgnoreCase("gsetspawn")) {
|
||||||
|
result = new Cmd_Setspawn(sender).execute();
|
||||||
|
} else if (cmd.getName().equalsIgnoreCase("gspawn")) {
|
||||||
|
result = new Cmd_Spawn(sender, this).execute();
|
||||||
|
} else if (cmd.getName().equalsIgnoreCase("greset")) {
|
||||||
|
result = new Cmd_Reset(sender).execute();
|
||||||
|
} else if (cmd.getName().equalsIgnoreCase("greload")) {
|
||||||
|
result = new Cmd_Reload(sender, this).execute();
|
||||||
|
} else {
|
||||||
|
result = EnumCmdExe.UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.isError()){
|
||||||
|
Messenger.sendErrorMsg(sender, result.getMsg(), result.getArgs());
|
||||||
|
} else if (result != EnumCmdExe.SUCCESS) {
|
||||||
|
Messenger.sendOtherMsg(sender, result.getMsg(), result.getArgs());
|
||||||
|
}
|
||||||
|
return result.getReturn();
|
||||||
|
}
|
||||||
|
}
|
||||||
38
src/me/Caesar2011/GuestSpawn/Library/ColorOperations.java
Normal file
38
src/me/Caesar2011/GuestSpawn/Library/ColorOperations.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package me.Caesar2011.GuestSpawn.Library;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
public class ColorOperations {
|
||||||
|
private static String seperator = "&";
|
||||||
|
private static String strings = "0123456789abcdef";
|
||||||
|
private static ChatColor[] colors = {
|
||||||
|
ChatColor.BLACK,
|
||||||
|
ChatColor.DARK_BLUE,
|
||||||
|
ChatColor.DARK_GREEN,
|
||||||
|
ChatColor.DARK_AQUA,
|
||||||
|
ChatColor.DARK_RED,
|
||||||
|
ChatColor.DARK_PURPLE,
|
||||||
|
ChatColor.GOLD,
|
||||||
|
ChatColor.GRAY,
|
||||||
|
ChatColor.DARK_GRAY,
|
||||||
|
ChatColor.DARK_BLUE,
|
||||||
|
ChatColor.GREEN,
|
||||||
|
ChatColor.AQUA,
|
||||||
|
ChatColor.RED,
|
||||||
|
ChatColor.LIGHT_PURPLE,
|
||||||
|
ChatColor.YELLOW,
|
||||||
|
ChatColor.WHITE
|
||||||
|
};
|
||||||
|
|
||||||
|
public static ChatColor getChatColor(String str){
|
||||||
|
if (str.length() == 2 && str.substring(0, 1).equals(seperator)){
|
||||||
|
char c = str.charAt(1);
|
||||||
|
for (int i = 0; i < strings.length(); i++) {
|
||||||
|
if (c == strings.charAt(i)){
|
||||||
|
return colors[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
236
src/me/Caesar2011/GuestSpawn/Library/ConfigManager.java
Normal file
236
src/me/Caesar2011/GuestSpawn/Library/ConfigManager.java
Normal file
@@ -0,0 +1,236 @@
|
|||||||
|
package me.Caesar2011.GuestSpawn.Library;
|
||||||
|
|
||||||
|
import me.Caesar2011.GuestSpawn.GuestSpawn;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
|
|
||||||
|
public class ConfigManager {
|
||||||
|
|
||||||
|
interface CfgStr {
|
||||||
|
String getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CfgBool {
|
||||||
|
boolean getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CfgCol {
|
||||||
|
ChatColor getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum CfgError implements CfgStr{
|
||||||
|
NOTSET("NotSet", "Guest spawn is not set."),
|
||||||
|
TPCANCEL("TeleportCancelled", "You are not allowed to (be) teleport."),
|
||||||
|
NOPERM("NoPermission", "You have not enough permissions."),
|
||||||
|
NOCONS("NoConsole", "Not from console until now."),
|
||||||
|
UNKNOWN("UnknownError", "There was an unknown error.");
|
||||||
|
private String path;
|
||||||
|
private String def;
|
||||||
|
CfgError(String path, String def){this.path = path;this.def = def;}
|
||||||
|
public String getValue(){return getStr(getPath());}
|
||||||
|
private String getPath(){return ErrorPath + "." + path;}
|
||||||
|
private String getDefault(){return def;}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum CfgOther implements CfgStr{
|
||||||
|
RELOAD("ReloadConfig", "Config was reloaded."),
|
||||||
|
SPAWN("Teleport", "You was teleport to guest spawn."),
|
||||||
|
SETSPAWN("Set", "New guest spawn was set."),
|
||||||
|
RESET("Reset", "Guest spawn loation was removed."),
|
||||||
|
FIRSTJOIN("FirstJoin", "%player% joined first time. Welcome!");
|
||||||
|
private String path;
|
||||||
|
private String def;
|
||||||
|
CfgOther(String path, String def){this.path = path;this.def = def;}
|
||||||
|
public String getValue(){return getStr(getPath());}
|
||||||
|
private String getPath(){return OtherPath + "." + path;}
|
||||||
|
private String getDefault(){return def;}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum CfgEvent implements CfgBool{
|
||||||
|
FIRSTJOIN("FirstJoin", true),
|
||||||
|
JOIN("Join", true),
|
||||||
|
RESPAWN("Respawn", true),
|
||||||
|
TELEPORT("Teleport", true);
|
||||||
|
private String path;
|
||||||
|
private boolean def;
|
||||||
|
CfgEvent(String path, boolean def){this.path = path;this.def = def;}
|
||||||
|
public boolean getValue(){return getBool(getPath());}
|
||||||
|
private String getPath(){return EventPath + "." + path;}
|
||||||
|
private boolean getDefault(){return def;}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum CfgFormat implements CfgBool{
|
||||||
|
ERR_UNDER("ErrorUnderlined", true),
|
||||||
|
ERR_BOLD("ErrorBolded", false),
|
||||||
|
HEAD_UNDER("HeaderUnderlined", true),
|
||||||
|
HEAD_BOLD("HeaderBolded", false);
|
||||||
|
private String path;
|
||||||
|
private boolean def;
|
||||||
|
CfgFormat(String path, boolean def){this.path = path;this.def = def;}
|
||||||
|
public boolean getValue(){return getBool(getPath());}
|
||||||
|
private String getPath(){return PropertyPath + "." + path;}
|
||||||
|
private boolean getDefault(){return def;}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum CfgColor implements CfgCol{
|
||||||
|
MSG_FST("FirstMsgColor", "&2"),
|
||||||
|
MSG_SEC("SecoundMsgColor", "&a"),
|
||||||
|
ERR_FST("FirstErrColor", "&4"),
|
||||||
|
ERR_SEC("SecoundErrColor", "&c"),
|
||||||
|
PREFIX("PrefixColor", "&3");
|
||||||
|
private String path;
|
||||||
|
private String def;
|
||||||
|
CfgColor(String path, String def){this.path = path;this.def = def;}
|
||||||
|
public ChatColor getValue(){return ColorOperations.getChatColor(getStr(getPath()));}
|
||||||
|
private String getPath(){return PropertyPath + "." + path;}
|
||||||
|
private String getDefault(){return def;}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum CfgPropStr implements CfgStr{
|
||||||
|
PRESTRING("PrefixName", "GuestSpawn");
|
||||||
|
private String path;
|
||||||
|
private String def;
|
||||||
|
CfgPropStr(String path, String def){this.path = path;this.def = def;}
|
||||||
|
public String getValue(){return getStr(getPath());}
|
||||||
|
private String getPath(){return PropertyPath + "." + path;}
|
||||||
|
private String getDefault(){return def;}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String ConfigPath = "GuestSpawn.Config";
|
||||||
|
private static String MessagePath = ConfigPath + ".Messages";
|
||||||
|
//private static String EntryPath = MessagePath + ".Entry";
|
||||||
|
private static String ErrorPath = MessagePath + ".Error";
|
||||||
|
private static String OtherPath = MessagePath + ".Other";
|
||||||
|
private static String PropertyPath = ConfigPath + ".Proerties";
|
||||||
|
private static String EventPath = PropertyPath + ".Events";
|
||||||
|
|
||||||
|
|
||||||
|
public static final String className = "ConfigManager";
|
||||||
|
private static final String fileName = "config.yml";
|
||||||
|
private static FileManager file = new FileManager(className, fileName);
|
||||||
|
|
||||||
|
|
||||||
|
public static void onEnable(){
|
||||||
|
file.onEnable();
|
||||||
|
for (CfgError e: CfgError.values()){
|
||||||
|
onGet().addDefault(e.getPath(), e.getDefault());
|
||||||
|
}
|
||||||
|
for (CfgOther e: CfgOther.values()){
|
||||||
|
onGet().addDefault(e.getPath(), e.getDefault());
|
||||||
|
}
|
||||||
|
for (CfgEvent e: CfgEvent.values()){
|
||||||
|
onGet().addDefault(e.getPath(), e.getDefault());
|
||||||
|
}
|
||||||
|
for (CfgFormat e: CfgFormat.values()){
|
||||||
|
onGet().addDefault(e.getPath(), e.getDefault());
|
||||||
|
}
|
||||||
|
for (CfgPropStr e: CfgPropStr.values()){
|
||||||
|
onGet().addDefault(e.getPath(), e.getDefault());
|
||||||
|
}
|
||||||
|
for (CfgColor e: CfgColor.values()){
|
||||||
|
onGet().addDefault(e.getPath(), e.getDefault());
|
||||||
|
}
|
||||||
|
onGet().options().copyDefaults(true);
|
||||||
|
onSave();
|
||||||
|
|
||||||
|
onRepair();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onDisable(){
|
||||||
|
file.onDisable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static FileConfiguration onGet(){
|
||||||
|
return file.onGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onSave(){
|
||||||
|
file.onSave();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getStr(String path){
|
||||||
|
if (onGet().contains(path) && onGet().isString(path)){
|
||||||
|
return onGet().getString(path);
|
||||||
|
} else {
|
||||||
|
throw (RuntimeException) null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*private static Integer getInt(String path){
|
||||||
|
if (onGet().contains(path) && onGet().isInt(path)){
|
||||||
|
return onGet().getInt(path);
|
||||||
|
} else {
|
||||||
|
throw (RuntimeException) null;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
private static Boolean getBool(String path){
|
||||||
|
if (onGet().contains(path) && onGet().isBoolean(path)){
|
||||||
|
return onGet().getBoolean(path);
|
||||||
|
} else {
|
||||||
|
throw (RuntimeException) null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setGuestSpawnLoc(Location loc){
|
||||||
|
onEnable();
|
||||||
|
if (loc == null){
|
||||||
|
onGet().set(PropertyPath + ".GuestSpawn", null);
|
||||||
|
} else {
|
||||||
|
onGet().set(PropertyPath + ".GuestSpawn.X", loc.getX());
|
||||||
|
onGet().set(PropertyPath + ".GuestSpawn.Y", loc.getY());
|
||||||
|
onGet().set(PropertyPath + ".GuestSpawn.Z", loc.getZ());
|
||||||
|
onGet().set(PropertyPath + ".GuestSpawn.Yaw", (double) loc.getYaw());
|
||||||
|
onGet().set(PropertyPath + ".GuestSpawn.Pitch", (double) loc.getPitch());
|
||||||
|
onGet().set(PropertyPath + ".GuestSpawn.World", loc.getWorld().getName());
|
||||||
|
}
|
||||||
|
onSave();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Location getGuestSpawnLoc(GuestSpawn plugin){
|
||||||
|
Location loc = new Location(null, 0, 0, 0, 0, 0);
|
||||||
|
boolean isSet = true;
|
||||||
|
if (onGet().contains(PropertyPath + ".GuestSpawn.X") && onGet().isDouble(PropertyPath + ".GuestSpawn.X")){
|
||||||
|
loc.setX(onGet().getDouble(PropertyPath + ".GuestSpawn.X"));
|
||||||
|
} else isSet = false;
|
||||||
|
if (onGet().contains(PropertyPath + ".GuestSpawn.Y") && onGet().isDouble(PropertyPath + ".GuestSpawn.Y")){
|
||||||
|
loc.setY(onGet().getDouble(PropertyPath + ".GuestSpawn.Y"));
|
||||||
|
} else isSet = false;
|
||||||
|
if (onGet().contains(PropertyPath + ".GuestSpawn.Z") && onGet().isDouble(PropertyPath + ".GuestSpawn.Z")){
|
||||||
|
loc.setZ(onGet().getDouble(PropertyPath + ".GuestSpawn.Z"));
|
||||||
|
} else isSet = false;
|
||||||
|
if (onGet().contains(PropertyPath + ".GuestSpawn.Yaw") && onGet().isDouble(PropertyPath + ".GuestSpawn.Yaw")){
|
||||||
|
loc.setYaw((float) onGet().getDouble(PropertyPath + ".GuestSpawn.Yaw"));
|
||||||
|
} else isSet = false;
|
||||||
|
if (onGet().contains(PropertyPath + ".GuestSpawn.Pitch") && onGet().isDouble(PropertyPath + ".GuestSpawn.Pitch")){
|
||||||
|
loc.setPitch((float) onGet().getDouble(PropertyPath + ".GuestSpawn.Pitch"));
|
||||||
|
} else isSet = false;
|
||||||
|
if (onGet().contains(PropertyPath + ".GuestSpawn.World") && onGet().isString(PropertyPath + ".GuestSpawn.World")){
|
||||||
|
loc.setWorld(plugin.getServer().getWorld(onGet().getString(PropertyPath + ".GuestSpawn.World")));
|
||||||
|
} else isSet = false;
|
||||||
|
|
||||||
|
if (isSet) return loc; else return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onReload(){
|
||||||
|
onEnable();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onRepair(){
|
||||||
|
boolean changed = false;
|
||||||
|
|
||||||
|
if (onGet().contains(PropertyPath + ".ErrColor")){
|
||||||
|
String x = onGet().getString(PropertyPath + ".ErrColor");
|
||||||
|
onGet().set(PropertyPath + ".FirstErrColor", x);
|
||||||
|
onGet().set(PropertyPath + ".ErrColor", null);
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
onSave();
|
||||||
|
if (changed) System.out.println("[" + Messenger.getPreStr() + "] Config updated to latest version.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
135
src/me/Caesar2011/GuestSpawn/Library/DateOperations.java
Normal file
135
src/me/Caesar2011/GuestSpawn/Library/DateOperations.java
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
package me.Caesar2011.GuestSpawn.Library;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class DateOperations {
|
||||||
|
|
||||||
|
Date d;
|
||||||
|
|
||||||
|
public DateOperations(Date d){
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(d);
|
||||||
|
cal.set(Calendar.MILLISECOND, 0);
|
||||||
|
cal.set(Calendar.MINUTE, 0);
|
||||||
|
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
|
this.d = cal.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DateOperations(String s){
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
|
||||||
|
try{
|
||||||
|
this.d = format.parse(s);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
this.d = new Date();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSecounds(int amount){
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(d);
|
||||||
|
cal.add(Calendar.SECOND, amount);
|
||||||
|
d = cal.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMinutes(int amount){
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(d);
|
||||||
|
cal.add(Calendar.MINUTE, amount);
|
||||||
|
d = cal.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addHours(int amount){
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(d);
|
||||||
|
cal.add(Calendar.HOUR, amount);
|
||||||
|
d = cal.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDays(int amount){
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(d);
|
||||||
|
cal.add(Calendar.DAY_OF_MONTH, amount);
|
||||||
|
d = cal.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMonth(int amount){
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(d);
|
||||||
|
cal.add(Calendar.MONTH, amount);
|
||||||
|
d = cal.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addYears(int amount){
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(d);
|
||||||
|
cal.add(Calendar.YEAR, amount);
|
||||||
|
d = cal.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date toDate(){
|
||||||
|
return this.d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString(){
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(d);
|
||||||
|
String buffDay = new Integer(cal.get(Calendar.DAY_OF_MONTH)).toString();
|
||||||
|
if (buffDay.length() == 1){
|
||||||
|
buffDay = "0" + buffDay;
|
||||||
|
}
|
||||||
|
String buffMonth = new Integer(cal.get(Calendar.MONTH) + 1).toString();
|
||||||
|
if (buffMonth.length() == 1){
|
||||||
|
buffMonth = "0" + buffMonth;
|
||||||
|
}
|
||||||
|
String buffYear = new Integer(cal.get(Calendar.YEAR)).toString();
|
||||||
|
return buffDay + "." + buffMonth + "." + buffYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBefore(Date date){
|
||||||
|
DateOperations DateToComp = new DateOperations(date);
|
||||||
|
if(d.compareTo(DateToComp.toDate()) < 0){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBefore(String string){
|
||||||
|
DateOperations DateToComp = new DateOperations(string);
|
||||||
|
if(d.compareTo(DateToComp.toDate()) < 0){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAfter(Date date){
|
||||||
|
DateOperations DateToComp = new DateOperations(date);
|
||||||
|
if(d.compareTo(DateToComp.toDate()) > 0){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAfter(String string) {
|
||||||
|
DateOperations DateToComp = new DateOperations(string);
|
||||||
|
if(d.compareTo(DateToComp.toDate()) > 0){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAfter(DateOperations endDate) {
|
||||||
|
DateOperations DateToComp = endDate;
|
||||||
|
if(d.compareTo(DateToComp.toDate()) > 0){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
51
src/me/Caesar2011/GuestSpawn/Library/EnumCmdExe.java
Normal file
51
src/me/Caesar2011/GuestSpawn/Library/EnumCmdExe.java
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package me.Caesar2011.GuestSpawn.Library;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager.CfgError;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager.CfgOther;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager.CfgStr;
|
||||||
|
|
||||||
|
|
||||||
|
public enum EnumCmdExe {
|
||||||
|
SUCCESS (true, true, null),
|
||||||
|
RELOAD (true, true, CfgOther.RELOAD),
|
||||||
|
SET (true, true, CfgOther.SETSPAWN),
|
||||||
|
RESET (true, true, CfgOther.RESET),
|
||||||
|
TELEPORT (true, true, CfgOther.SPAWN),
|
||||||
|
NOSET (false, true, CfgError.NOTSET),
|
||||||
|
NOPERM (false, true, CfgError.NOPERM),
|
||||||
|
NOCONSOLE(false, true, CfgError.NOCONS),
|
||||||
|
UNKNOWN (false, false, CfgError.UNKNOWN);
|
||||||
|
|
||||||
|
private boolean noerror;
|
||||||
|
private boolean ret;
|
||||||
|
private CfgStr msg;
|
||||||
|
private ArrayList<String[]> args = new ArrayList<String[]>();
|
||||||
|
|
||||||
|
EnumCmdExe(boolean noerror, boolean ret, CfgStr msg){
|
||||||
|
this.noerror = noerror;
|
||||||
|
this.ret = ret;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isError(){
|
||||||
|
return !noerror;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getReturn(){
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CfgStr getMsg(){
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addArg(String match, String replace){
|
||||||
|
args.add(new String[]{match, replace});
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[][] getArgs(){
|
||||||
|
return args.toArray(new String[args.size()][2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
src/me/Caesar2011/GuestSpawn/Library/EnumPerm.java
Normal file
34
src/me/Caesar2011/GuestSpawn/Library/EnumPerm.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package me.Caesar2011.GuestSpawn.Library;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public enum EnumPerm {
|
||||||
|
SPAWN("spawn"),
|
||||||
|
NOEVENT("noevent"),
|
||||||
|
SETSPAWN("setspawn"),
|
||||||
|
RELOAD("reload"),
|
||||||
|
RESET("reset");
|
||||||
|
|
||||||
|
private String perm;
|
||||||
|
private final String main = "guestspawn.";
|
||||||
|
|
||||||
|
EnumPerm(String perm)
|
||||||
|
{
|
||||||
|
this.perm = perm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPermission(CommandSender sender)
|
||||||
|
{
|
||||||
|
if(!(sender instanceof Player)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (((Player)sender).hasPermission(main + perm)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean noPermission(CommandSender sender)
|
||||||
|
{
|
||||||
|
return !hasPermission(sender);
|
||||||
|
}
|
||||||
|
}
|
||||||
69
src/me/Caesar2011/GuestSpawn/Library/FileManager.java
Normal file
69
src/me/Caesar2011/GuestSpawn/Library/FileManager.java
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
package me.Caesar2011.GuestSpawn.Library;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
public class FileManager {
|
||||||
|
protected boolean isLoaded = false;
|
||||||
|
protected String className;
|
||||||
|
protected String fileName;
|
||||||
|
protected String filePath;
|
||||||
|
protected FileConfiguration yaml = null;
|
||||||
|
protected File file;
|
||||||
|
|
||||||
|
protected FileManager(String className, String fileName){
|
||||||
|
this.className = className;
|
||||||
|
this.fileName = fileName;
|
||||||
|
this.filePath = "plugins" + File.separator + "GuestSpawn" + File.separator + fileName;
|
||||||
|
this.file = new File(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onEnable(){
|
||||||
|
if (!file.exists()) {
|
||||||
|
try {
|
||||||
|
file.createNewFile();
|
||||||
|
} catch (Exception e) {
|
||||||
|
try {
|
||||||
|
new File(file.getAbsoluteFile().getParentFile().toString()).mkdir();
|
||||||
|
file.createNewFile();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
System.err.println("[" + Messenger.getPreStr() + "] " + className + ": Could not create new file. (IOException)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("[" + Messenger.getPreStr() + "] " + className + ": \"" + fileName + "\" did not exist. Created new!");
|
||||||
|
}
|
||||||
|
yaml = YamlConfiguration.loadConfiguration(file);
|
||||||
|
isLoaded = true;
|
||||||
|
System.out.println("[" + Messenger.getPreStr() + "] " + className + ": Loaded.");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onDisable(){
|
||||||
|
if (isLoaded) {
|
||||||
|
onSave();
|
||||||
|
}
|
||||||
|
file = null;
|
||||||
|
System.out.println("[" + Messenger.getPreStr() + "] " + className + ": Saved.");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected FileConfiguration onGet(){
|
||||||
|
if (!isLoaded){
|
||||||
|
onEnable();
|
||||||
|
}
|
||||||
|
return yaml;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onSave(){
|
||||||
|
try {
|
||||||
|
onGet().save(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println(ChatColor.DARK_RED + "[" + Messenger.getPreStr() + "] " + className + ": Could not save file. (IOException)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
109
src/me/Caesar2011/GuestSpawn/Library/Messenger.java
Normal file
109
src/me/Caesar2011/GuestSpawn/Library/Messenger.java
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
package me.Caesar2011.GuestSpawn.Library;
|
||||||
|
|
||||||
|
import me.Caesar2011.GuestSpawn.GuestSpawn;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager.CfgColor;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager.CfgFormat;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager.CfgOther;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager.CfgPropStr;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager.CfgStr;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class Messenger {
|
||||||
|
private static ChatColor preColor = ChatColor.DARK_BLUE;
|
||||||
|
private static String preString = "GuestSpawn";
|
||||||
|
private static ChatColor msgColor1 = ChatColor.DARK_GREEN;
|
||||||
|
private static ChatColor msgColor2 = ChatColor.GREEN;
|
||||||
|
private static ChatColor errColor1 = ChatColor.DARK_RED;
|
||||||
|
private static ChatColor errColor2 = ChatColor.RED;
|
||||||
|
private static boolean errUnderlined = true;
|
||||||
|
private static boolean errBolded = true;
|
||||||
|
private static boolean headUnderlined = true;
|
||||||
|
private static boolean headBolded = true;
|
||||||
|
|
||||||
|
public static void onEnable() {
|
||||||
|
preColor = CfgColor.PREFIX.getValue();
|
||||||
|
preString = CfgPropStr.PRESTRING.getValue();
|
||||||
|
msgColor1 = CfgColor.MSG_FST.getValue();
|
||||||
|
msgColor2 = CfgColor.MSG_SEC.getValue();
|
||||||
|
errColor1 = CfgColor.ERR_FST.getValue();
|
||||||
|
errColor2 = CfgColor.ERR_SEC.getValue();
|
||||||
|
errUnderlined = CfgFormat.ERR_UNDER.getValue();
|
||||||
|
errBolded = CfgFormat.ERR_BOLD.getValue();
|
||||||
|
headUnderlined = CfgFormat.HEAD_UNDER.getValue();
|
||||||
|
headBolded = CfgFormat.HEAD_BOLD.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static String getPreStr(){
|
||||||
|
return preString;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void send(CommandSender sender, String arg) {
|
||||||
|
arg = preColor + "[" + preString + "] " + arg;
|
||||||
|
sender.sendMessage(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendOtherMsg(CommandSender sender, CfgStr msg){
|
||||||
|
sendOtherMsg(sender, msg, new String[0][0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendOtherMsg(CommandSender sender, CfgStr msg, String[]... value){
|
||||||
|
String arg = msgColor1 + msg.getValue();
|
||||||
|
for (String[] v: value){
|
||||||
|
arg = arg.replaceAll(v[0], msgColor2 + v[1] + msgColor1);
|
||||||
|
}
|
||||||
|
send(sender, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendErrorMsg(CommandSender sender, CfgStr msg){
|
||||||
|
sendErrorMsg(sender, msg, new String[0][0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendErrorMsg(CommandSender sender, CfgStr msg, String[]... value){
|
||||||
|
String arg = errColor1 + msg.getValue();
|
||||||
|
if (errUnderlined){
|
||||||
|
arg = ChatColor.UNDERLINE + arg;
|
||||||
|
}
|
||||||
|
if (errBolded){
|
||||||
|
arg = ChatColor.BOLD + arg;
|
||||||
|
}
|
||||||
|
for (String[] v: value){
|
||||||
|
arg = arg.replaceAll(v[0], errColor2 + v[1] + errColor1);
|
||||||
|
}
|
||||||
|
send(sender, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void sendPlyHelp(CommandSender sender, String desc, String command){
|
||||||
|
String arg = msgColor1 + desc + preColor + " - " + msgColor2 + command;
|
||||||
|
send(sender, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendPlyHeader(CommandSender sender, String header){
|
||||||
|
if (headUnderlined){
|
||||||
|
header = ChatColor.UNDERLINE + header;
|
||||||
|
}
|
||||||
|
if (headBolded){
|
||||||
|
header = ChatColor.BOLD + header;
|
||||||
|
}
|
||||||
|
header = msgColor1 + header;
|
||||||
|
send(sender, header);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
public static void broadMsg(GuestSpawn plugin, CfgOther msg){
|
||||||
|
broadMsg(plugin, msg, new String[]{});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void broadMsg(GuestSpawn plugin, CfgOther msg, String[]... value){
|
||||||
|
String arg = msgColor1 + msg.getValue();
|
||||||
|
for (String[] v: value){
|
||||||
|
arg = arg.replaceAll(v[0], msgColor2 + v[1] + msgColor1);
|
||||||
|
}
|
||||||
|
plugin.getServer().broadcastMessage(preColor + "[" + preString + "] " + msgColor1 + arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package me.Caesar2011.GuestSpawn.Listener;
|
||||||
|
|
||||||
|
import me.Caesar2011.GuestSpawn.GuestSpawn;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager.CfgError;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager.CfgEvent;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager.CfgOther;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.Messenger;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.EnumPerm;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
|
|
||||||
|
public class Listener_PlayerJoin implements Listener {
|
||||||
|
private GuestSpawn plugin;
|
||||||
|
|
||||||
|
public Listener_PlayerJoin(GuestSpawn plugin){
|
||||||
|
this.plugin = plugin;
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event){
|
||||||
|
execute(event.getPlayer(), plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void execute(final Player p, final GuestSpawn plugin){
|
||||||
|
boolean teleport = true;
|
||||||
|
boolean firstjoin = firstJoin(p, plugin);
|
||||||
|
if (firstjoin) {
|
||||||
|
Messenger.broadMsg(plugin, CfgOther.FIRSTJOIN, new String[]{"%player%", p.getName()});
|
||||||
|
}
|
||||||
|
if (EnumPerm.NOEVENT.noPermission(p) && (CfgEvent.JOIN.getValue() || CfgEvent.FIRSTJOIN.getValue())) {
|
||||||
|
if (!CfgEvent.JOIN.getValue()) {
|
||||||
|
teleport = firstjoin;
|
||||||
|
}
|
||||||
|
if (teleport){
|
||||||
|
Location loc = ConfigManager.getGuestSpawnLoc(plugin);
|
||||||
|
if (loc != null) {
|
||||||
|
Listener_PlayerTeleport.addName(p.getName());
|
||||||
|
p.teleport(loc, TeleportCause.PLUGIN);
|
||||||
|
Messenger.sendOtherMsg(p, CfgOther.SPAWN);
|
||||||
|
} else {
|
||||||
|
Messenger.sendErrorMsg(p, CfgError.NOTSET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean firstJoin(final Player p, final GuestSpawn plugin) {
|
||||||
|
for (OfflinePlayer op: plugin.players){
|
||||||
|
if (p.getName().equals(op.getName())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
plugin.players = plugin.getServer().getOfflinePlayers();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package me.Caesar2011.GuestSpawn.Listener;
|
||||||
|
|
||||||
|
import me.Caesar2011.GuestSpawn.GuestSpawn;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager.CfgError;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager.CfgEvent;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager.CfgOther;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.EnumPerm;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.Messenger;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
|
|
||||||
|
public class Listener_PlayerRespawn implements Listener {
|
||||||
|
private GuestSpawn plugin;
|
||||||
|
|
||||||
|
public Listener_PlayerRespawn(GuestSpawn plugin){
|
||||||
|
this.plugin = plugin;
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onPlayerRespawn(PlayerRespawnEvent event){
|
||||||
|
execute(event.getPlayer(), plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void execute(final Player p, final GuestSpawn plugin){
|
||||||
|
if (EnumPerm.NOEVENT.noPermission(p) && CfgEvent.RESPAWN.getValue()){
|
||||||
|
Location loc = ConfigManager.getGuestSpawnLoc(plugin);
|
||||||
|
if (loc != null) {
|
||||||
|
p.teleport(loc, TeleportCause.PLUGIN);
|
||||||
|
Messenger.sendOtherMsg(p, CfgOther.SPAWN);
|
||||||
|
} else {
|
||||||
|
Messenger.sendErrorMsg(p, CfgError.NOTSET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package me.Caesar2011.GuestSpawn.Listener;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import me.Caesar2011.GuestSpawn.GuestSpawn;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager.CfgError;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.Messenger;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.EnumPerm;
|
||||||
|
import me.Caesar2011.GuestSpawn.Library.ConfigManager.CfgEvent;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
|
||||||
|
public class Listener_PlayerTeleport implements Listener {
|
||||||
|
private GuestSpawn plugin;
|
||||||
|
private static ArrayList<String> blockedPlayers;
|
||||||
|
|
||||||
|
public Listener_PlayerTeleport(GuestSpawn plugin){
|
||||||
|
this.plugin = plugin;
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
|
blockedPlayers = new ArrayList<String>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onPlayerTeleport(PlayerTeleportEvent event){
|
||||||
|
if (execute(event.getPlayer(), event.getTo(), plugin)){
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean execute(final Player p, Location getTo, final GuestSpawn plugin){
|
||||||
|
Location loc = ConfigManager.getGuestSpawnLoc(plugin);
|
||||||
|
|
||||||
|
for (int i = 0; i < blockedPlayers.size(); i++){
|
||||||
|
if (blockedPlayers.get(i) == p.getName()){
|
||||||
|
blockedPlayers.remove(i);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EnumPerm.NOEVENT.noPermission(p) && loc != null && loc.distance(getTo) > 3 && CfgEvent.TELEPORT.getValue()) {
|
||||||
|
Messenger.sendErrorMsg(p, CfgError.TPCANCEL);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addName(String name){
|
||||||
|
blockedPlayers.add(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
49
src/plugin.yml
Normal file
49
src/plugin.yml
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
name: GuestSpawn
|
||||||
|
version: 1.1.1
|
||||||
|
main: me.Caesar2011.GuestSpawn.GuestSpawn
|
||||||
|
authors: [Pcit, Caesar2011]
|
||||||
|
|
||||||
|
commands:
|
||||||
|
ghelp:
|
||||||
|
description: Show help
|
||||||
|
usage: /ghelp
|
||||||
|
aliases: [guesthelp, guestspawnhelp]
|
||||||
|
gsetspawn:
|
||||||
|
description: Set new guest spawn
|
||||||
|
usage: /gsetspawn
|
||||||
|
aliases: [guestsetspawn, guestspawnsetspawn]
|
||||||
|
gspawn:
|
||||||
|
description: Teleport to guest spawn
|
||||||
|
usage: /gspawn
|
||||||
|
aliases: [guestspawn, guestspawnspawn]
|
||||||
|
greload:
|
||||||
|
description: Reload config
|
||||||
|
usage: /greload
|
||||||
|
aliases: [guestreload, guestspawnreload]
|
||||||
|
greset:
|
||||||
|
description: Remove guest spawn
|
||||||
|
usage: /greset
|
||||||
|
aliases: [guestreset, guestspawnreset]
|
||||||
|
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
guestspawn.*:
|
||||||
|
description: 'Access to all commands and no auto-teleport to guest spawn.'
|
||||||
|
children:
|
||||||
|
guestspawn.spawn: true
|
||||||
|
guestspawn.noevent: true
|
||||||
|
guestspawn.setspawn: true
|
||||||
|
guestspawn.reload: true
|
||||||
|
guestspawn.reset: true
|
||||||
|
default: op
|
||||||
|
|
||||||
|
guestspawn.spawn:
|
||||||
|
description: 'Access to teleport command.'
|
||||||
|
guestspawn.noevent:
|
||||||
|
description: 'Player will not be auto-teleport to guest spawn.'
|
||||||
|
guestspawn.setspawn:
|
||||||
|
description: 'Access to set command (set guest spawn).'
|
||||||
|
guestspawn.reload:
|
||||||
|
description: 'Access to reload command (reload config).'
|
||||||
|
guestspawn.reset:
|
||||||
|
description: 'Access to reset command (remove guest spawn).'
|
||||||
Reference in New Issue
Block a user