AnuraCore rewrite for freebuild server
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
/build/
|
||||
/dist/
|
||||
/build/
|
||||
/dist/
|
||||
/nbproject/private/
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
X-COMMENT: Main-Class will be added automatically by build
|
||||
|
||||
Manifest-Version: 1.0
|
||||
X-COMMENT: Main-Class will be added automatically by build
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,8 @@
|
||||
build.xml.data.CRC32=495367dd
|
||||
build.xml.script.CRC32=47737c7c
|
||||
build.xml.stylesheet.CRC32=8064a381@1.68.1.46
|
||||
build.xml.stylesheet.CRC32=f85dc8f2@1.92.0.48
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=495367dd
|
||||
nbproject/build-impl.xml.script.CRC32=d7be14a7
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.74.2.48
|
||||
nbproject/build-impl.xml.script.CRC32=694a0416
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=3a2fa800@1.92.0.48
|
||||
|
||||
@@ -5,6 +5,16 @@ annotation.processing.run.all.processors=true
|
||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||
application.title=AnuraCore
|
||||
application.vendor=Nico
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs=true
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width=4
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab=4
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.tab-size=8
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width=80
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-line-wrap=none
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.usedProfile=project
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.allowConvertToStarImport=true
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.countForUsingStarImport=8
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.importGroupsOrder=*
|
||||
auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml
|
||||
build.classes.dir=${build.dir}/classes
|
||||
build.classes.excludes=**/*.java,**/*.form
|
||||
@@ -20,8 +30,12 @@ build.test.results.dir=${build.dir}/test/results
|
||||
#debug.transport=dt_socket
|
||||
debug.classpath=\
|
||||
${run.classpath}
|
||||
debug.modulepath=\
|
||||
${run.modulepath}
|
||||
debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
debug.test.modulepath=\
|
||||
${run.test.modulepath}
|
||||
# Files in build.classes.dir which should be excluded from distribution jar
|
||||
dist.archive.excludes=
|
||||
# This directory is removed when the project is cleaned:
|
||||
@@ -30,23 +44,27 @@ dist.jar=${dist.dir}/AnuraCore.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
endorsed.classpath=
|
||||
excludes=
|
||||
file.reference.spigot-api-1.8-R0.1-SNAPSHOT.jar=D:\\Downloads\\Spigot\\Spigot-API\\target\\spigot-api-1.8-R0.1-SNAPSHOT.jar
|
||||
includes=**
|
||||
jar.archive.disabled=${jnlp.enabled}
|
||||
jar.compress=false
|
||||
jar.index=${jnlp.enabled}
|
||||
javac.classpath=\
|
||||
${file.reference.spigot-api-1.8-R0.1-SNAPSHOT.jar}
|
||||
${libs.Spigot-Server.classpath}
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
javac.external.vm=false
|
||||
javac.modulepath=
|
||||
javac.processormodulepath=
|
||||
javac.processorpath=\
|
||||
${javac.classpath}
|
||||
javac.source=1.7
|
||||
javac.target=1.7
|
||||
javac.source=1.8
|
||||
javac.target=1.8
|
||||
javac.test.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
javac.test.modulepath=\
|
||||
${javac.modulepath}
|
||||
javac.test.processorpath=\
|
||||
${javac.test.classpath}
|
||||
javadoc.additionalparam=
|
||||
@@ -85,9 +103,13 @@ run.classpath=\
|
||||
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
|
||||
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||
run.jvmargs=
|
||||
run.modulepath=\
|
||||
${javac.modulepath}
|
||||
run.test.classpath=\
|
||||
${javac.test.classpath}:\
|
||||
${build.test.classes.dir}
|
||||
run.test.modulepath=\
|
||||
${javac.test.modulepath}
|
||||
source.encoding=UTF-8
|
||||
src.dir=src
|
||||
test.src.dir=test
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>AnuraCore</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>AnuraCore</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
||||
|
||||
@@ -1,318 +0,0 @@
|
||||
package de.anura.core.API;
|
||||
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.util.Data;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.material.Stairs;
|
||||
|
||||
public class Core {
|
||||
|
||||
/**
|
||||
* Use this if you want to change the language
|
||||
*/
|
||||
public final static HashMap<Player, String> cachedPlayerLanguage = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Gets the current MySQL Object
|
||||
*
|
||||
* @return The working MySQL Object
|
||||
*/
|
||||
public static MySQL getMySql() {
|
||||
if (AnuraCore.getSql() == null) {
|
||||
return null;
|
||||
}
|
||||
if (!AnuraCore.getSql().hasConnection()) {
|
||||
return null;
|
||||
}
|
||||
return AnuraCore.getSql();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a language value for the given id and language
|
||||
*
|
||||
* @param id The language id as used in the translation center
|
||||
* @param lang The short value of a language e.g. de, en
|
||||
* @return Returns the text for this id
|
||||
*/
|
||||
public static String getl(String id, String lang) {
|
||||
String val = AnuraCore.lang.get(id, lang);
|
||||
if (val == null || val.isEmpty()) {
|
||||
val = AnuraCore.lang.get(id, "en");
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a language value for the given id for a CommandSender
|
||||
*
|
||||
* @param id The language id as used in the translation center
|
||||
* @param cs A command sender to automatically detect the language
|
||||
* @return Returns the text for this id
|
||||
*/
|
||||
public static String getl(String id, CommandSender cs) {
|
||||
if (cs instanceof Player) {
|
||||
return Core.getl(id, (Player) cs);
|
||||
} else {
|
||||
return Core.getl(id, "en");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a language value for the given id for a Player
|
||||
*
|
||||
* @param id The language id as used in the translation center
|
||||
* @param P A player to use his language setting
|
||||
* @return Returns the text for this id
|
||||
*/
|
||||
public static String getl(String id, Player P) {
|
||||
return Core.getl(id, Core.getPlayerLang(P));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a translated and colored message to the given CommandSender
|
||||
*
|
||||
* @param P The CommandSender, whose language is being determined and the
|
||||
* language is sended to
|
||||
* @param id The language id as used in the translation center
|
||||
* @param status The type of the message(true for green, false for red)
|
||||
*/
|
||||
public static void statusMsg(CommandSender P, String id, Boolean status) {
|
||||
ChatColor chatColor;
|
||||
if (status) {
|
||||
chatColor = ChatColor.GREEN;
|
||||
} else {
|
||||
chatColor = ChatColor.RED;
|
||||
}
|
||||
statusMsg(P, id, chatColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a translated and colored message to the given CommandSender
|
||||
*
|
||||
* @param P The CommandSender, whose language is being determined and the
|
||||
* language is sended to
|
||||
* @param id The language id as used in the translation center
|
||||
* @param color The color of the message
|
||||
*/
|
||||
public static void statusMsg(CommandSender P, String id, ChatColor color) {
|
||||
P.sendMessage(ChatColor.GRAY + "[Anura] " + color + Core.getl(id, Core.getPlayerLang(P)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the language of the given CommandSender
|
||||
*
|
||||
* @param P The CommandSender, whose language is being determined
|
||||
* @return Returns the short language name of the player (like de or en)
|
||||
*/
|
||||
public static String getPlayerLang(CommandSender P) {
|
||||
try {
|
||||
if (!(P instanceof Player)) {
|
||||
return "en";
|
||||
}
|
||||
Player p = (Player) P;
|
||||
if (!Core.cachedPlayerLanguage.containsKey(p)) {
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT lang FROM players WHERE uuid = '" + p.getUniqueId().toString() + "'");
|
||||
if (rs == null || !rs.next()) {
|
||||
//This is a weird bug
|
||||
Core.cachedPlayerLanguage.put(p, "de");
|
||||
return "de";
|
||||
}
|
||||
Core.cachedPlayerLanguage.put(p, rs.getString("lang"));
|
||||
return rs.getString("lang");
|
||||
|
||||
} else {
|
||||
return Core.cachedPlayerLanguage.get(p);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
return "en";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the available Languages
|
||||
*
|
||||
* @return Returns an iterable set of strings like de or en
|
||||
*/
|
||||
public static Set<String> getAvailLangs() {
|
||||
return AnuraCore.lang.languages.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Key by a given value from a given HashMap
|
||||
*
|
||||
* @param <T> The type of the key in the map
|
||||
* @param <E> The type of the value in the map
|
||||
* @param map The HashMap to get the key from
|
||||
* @param value The value to use to get a key
|
||||
* @return Returns the found key
|
||||
*/
|
||||
public static <T, E> T getKeyByValue(Map<T, E> map, E value) {
|
||||
for (Map.Entry<T, E> entry : map.entrySet()) {
|
||||
if (value.equals(entry.getValue())) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates all lobby features for all players from the database
|
||||
*/
|
||||
public static void updateFeatures() {
|
||||
AnuraCore.getInstance().getFeatures().updateFeaturesAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates all lobby features for the given player from the database
|
||||
*
|
||||
* @param P The player to update the features
|
||||
*/
|
||||
public static void updateFeatures(Player P) {
|
||||
AnuraCore.getInstance().getFeatures().updateFeatures(P);
|
||||
}
|
||||
|
||||
public static AnuraCore getMainClass() {
|
||||
return AnuraCore.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a player stand up
|
||||
* @param P The player to end the sitting of
|
||||
* @param noRemove If the player should stay in the sittingPlayer HashMap, used to prevent a Concurrent Modif Exc
|
||||
*/
|
||||
public static void endSitting(Player P, boolean noRemove) {
|
||||
try {
|
||||
if (Data.sittingPlayer.containsKey(P)) {
|
||||
MaterialData md = Data.sittingBlocks.get(P).getState().getData();
|
||||
if (md instanceof Stairs) {
|
||||
Stairs s = (Stairs) md;
|
||||
Location loc = Data.sittingBlocks.get(P).getRelative(s.getFacing()).getLocation();
|
||||
Entity a = Data.sittingPlayer.get(P);
|
||||
P.teleport(loc);
|
||||
a.remove();
|
||||
if (!noRemove) {
|
||||
Data.sittingPlayer.remove(P);
|
||||
}
|
||||
Data.sittingBlocks.remove(P);
|
||||
} else {
|
||||
Location loc = Data.sittingPlayer.get(P).getLocation();
|
||||
P.teleport(loc);
|
||||
Data.sittingPlayer.get(P).remove();
|
||||
if (!noRemove) {
|
||||
Data.sittingPlayer.remove(P);
|
||||
}
|
||||
Data.sittingBlocks.remove(P);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a player stand up
|
||||
* @param P The player to end the sitting of
|
||||
*/
|
||||
public static void endSitting(Player P) {
|
||||
endSitting(P, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check if a given string can be converted into an integer
|
||||
* @param s The string to check
|
||||
* @return If the given string is an integer
|
||||
*/
|
||||
public static boolean isInteger(String s) {
|
||||
return isInteger(s, 10);
|
||||
}
|
||||
|
||||
private static boolean isInteger(String s, int radix) {
|
||||
if (s.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
if (i == 0 && s.charAt(i) == '-') {
|
||||
if (s.length() == 1) {
|
||||
return false;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (Character.digit(s.charAt(i), radix) < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the level class object
|
||||
* @return The level class object
|
||||
*/
|
||||
public static Level getLevel() {
|
||||
return AnuraCore.level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a given player to the hub
|
||||
* @param P The player to move to the hub
|
||||
*/
|
||||
public static void kickToLobby(Player P) {
|
||||
try {
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(b);
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF("lobby");
|
||||
P.sendPluginMessage(getMainClass(), "BungeeCord", b.toByteArray());
|
||||
} catch (Throwable ex) {
|
||||
Errors.reportException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current set spawn
|
||||
* @return The spawn for this server
|
||||
*/
|
||||
public static Location getServerSpawn() {
|
||||
FileConfiguration c = getMainClass().getConfig();
|
||||
Location loc = null;
|
||||
World w = Bukkit.getWorld(c.getString("spawn.world"));
|
||||
if (w != null) {
|
||||
loc = new Location(Bukkit.getWorld(c.getString("spawn.world")), c.getDouble("spawn.X"), c.getDouble("spawn.Y"), c.getDouble("spawn.Z"), (float) c.getDouble("spawn.yaw"), (float) c.getDouble("spawn.pitch"));
|
||||
}
|
||||
if (loc == null) {
|
||||
loc = Bukkit.getWorlds().get(0).getSpawnLocation();
|
||||
}
|
||||
return loc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports a player to the current set serverspawn
|
||||
* Get serverspawn with {@link getServerSpawn()}
|
||||
* @param P The player to move to the spawn
|
||||
*/
|
||||
public static void toSpawn(Player P) {
|
||||
P.teleport(getServerSpawn());
|
||||
}
|
||||
|
||||
public static void sendActionBar(Player P, String msg) {
|
||||
P.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(msg));
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
package de.anura.core.API;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Errors {
|
||||
|
||||
/**
|
||||
* Reports an exception to the database
|
||||
*
|
||||
* @param exc A Throwable to get the error data from
|
||||
* @param info Some additional info
|
||||
*/
|
||||
public static void reportException(Throwable exc, String info) {
|
||||
if (Core.getMySql() == null) {
|
||||
System.err.println("FATAL ERROR: Error handler fired before init of mysql connection!!");
|
||||
exc.printStackTrace();
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Core.getMainClass(), () -> {
|
||||
try {
|
||||
String message = exc.getLocalizedMessage();
|
||||
String name = exc.getClass().toString();
|
||||
String server = Core.getMainClass() == null ? "~not available~" : Core.getMainClass().getConfig().getString("server-name");
|
||||
String errorSql = "INSERT INTO coreErrors (server, exception, msg, info, timestamp) VALUES('" + server + "', '" + name + "', '" + Core.getMySql().escapeString(message) + "', '" + info + "', '" + System.currentTimeMillis() / 1000 + "')";
|
||||
Core.getMySql().queryUpdate(errorSql);
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT id FROM coreErrors ORDER BY id DESC LIMIT 1");
|
||||
rs.first();
|
||||
int id = rs.getInt("id");
|
||||
String elemSql = "INSERT INTO coreErrorStack(errorId, className, fileName, methodName, lineNumber, nativeMethod) VALUES";
|
||||
boolean first = true;
|
||||
for (StackTraceElement elem : exc.getStackTrace()) {
|
||||
if (!first) {
|
||||
elemSql += ",";
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
elemSql += "('" + id + "', '" + elem.getClassName() + "', '" + elem.getFileName() + "', '" + elem.getMethodName() + "', '" + elem.getLineNumber() + "', " + elem.isNativeMethod() + ")";
|
||||
}
|
||||
Core.getMySql().queryUpdate(elemSql);
|
||||
} catch (Throwable ex) {
|
||||
System.err.println("FATAL ERROR: Error handler generated an exception!! (" + ex.getLocalizedMessage() + ")");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports an exception to the database
|
||||
*
|
||||
* @param exc A Throwable to get the error from
|
||||
*/
|
||||
public static void reportException(Throwable exc) {
|
||||
reportException(exc, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to report a bug
|
||||
*
|
||||
* @param P The reporter
|
||||
* @param msg A message from the reporter
|
||||
* @param data An array of error entries generated by
|
||||
* {@link make(String, Object)}
|
||||
*/
|
||||
public static void bugReport(Player P, String msg, Entry<String, Object>... data) {
|
||||
UUID uuid = P.getUniqueId();
|
||||
String dataText = "";
|
||||
for (Entry<String, Object> date : data) {
|
||||
dataText += date.getKey() + ":" + date.getValue().toString() + ";";
|
||||
}
|
||||
Core.getMySql().queryUpdate("INSERT INTO serverBugs(player, msg, data, timestamp) VALUES ((SELECT id FROM players WHERE uuid = '" + uuid.toString() + "'), '" + Core.getMySql().escapeString(msg) + "', '" + dataText + "', '" + System.currentTimeMillis() / 1000 + "')");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an error entry
|
||||
*
|
||||
* @param key The key for this object
|
||||
* @param value Any object to use as value
|
||||
* @return The error entry to give to
|
||||
*/
|
||||
public static Entry<String, Object> make(String key, Object value) {
|
||||
return new AbstractMap.SimpleEntry<>(key, value);
|
||||
}
|
||||
}
|
||||
@@ -1,298 +0,0 @@
|
||||
package de.anura.core.API;
|
||||
|
||||
import de.anura.core.AnuraCore;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class Inventories implements Listener {
|
||||
|
||||
public Inventories(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
public enum Action {
|
||||
|
||||
OPEN_INV,
|
||||
TELEPORT,
|
||||
MESSAGE,
|
||||
SERVER,
|
||||
COMMAND,
|
||||
LANGUAGE
|
||||
}
|
||||
|
||||
private static final HashMap<String, HashMap<String, Inventory>> invs = new HashMap<>();
|
||||
private static final HashMap<String, Boolean> invType = new HashMap<>();
|
||||
private static final HashMap<String, String> invLang = new HashMap<>();
|
||||
private static final HashMap<String, HashMap<Integer, Entry<Action, Object>>> invActions = new HashMap<>();
|
||||
private static final HashMap<String, String> invNames = new HashMap<>();
|
||||
private static final HashMap<String, HashMap<String, ItemStack>> items = new HashMap<>();
|
||||
private static final HashMap<String, String> itemNames = new HashMap<>();
|
||||
private static final HashMap<String, Entry<Action, Object>> itemActions = new HashMap<>();
|
||||
private static final HashMap<String, Integer> itemPositions = new HashMap<>();
|
||||
public static final HashMap<Player, Boolean> checkInteracts = new HashMap<>();
|
||||
|
||||
public static void registerInventory(String type, String name, ChatColor nameColor) {
|
||||
HashMap<String, Inventory> langInvs = new HashMap<>();
|
||||
for (String lang : Core.getAvailLangs()) {
|
||||
Inventory inv = Bukkit.createInventory(null, 9, nameColor + Core.getl(name, lang));
|
||||
langInvs.put(lang, inv);
|
||||
invNames.put(nameColor + Core.getl(name, lang), type);
|
||||
}
|
||||
invs.put(type, langInvs);
|
||||
invType.put(type, true);
|
||||
invActions.put(type, new HashMap<>());
|
||||
}
|
||||
|
||||
public static void registerInventory(String type, String name, ChatColor nameColor, boolean multilang, String lang) {
|
||||
if (multilang) {
|
||||
registerInventory(type, name, nameColor);
|
||||
return;
|
||||
}
|
||||
invType.put(type, false);
|
||||
HashMap<String, Inventory> langInvs = new HashMap<>();
|
||||
Inventory inv = Bukkit.createInventory(null, 9, nameColor + Core.getl(name, lang));
|
||||
langInvs.put("global", inv);
|
||||
invNames.put(nameColor + Core.getl(name, lang), type);
|
||||
invs.put(type, langInvs);
|
||||
invLang.put(type, lang);
|
||||
invActions.put(type, new HashMap<>());
|
||||
}
|
||||
|
||||
public static void buildInvItem(String type, Material m, String name, ChatColor nameColor, ChatColor loreColor, String... lores) { //INV!!
|
||||
HashMap<String, ItemStack> stacks = new HashMap<>();
|
||||
for (String lang : Core.getAvailLangs()) {
|
||||
ItemStack stack = new ItemStack(m);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
String display = nameColor + Core.getl(name, lang);
|
||||
meta.setDisplayName(display);
|
||||
if (loreColor != null) {
|
||||
for (int i = 0; i < lores.length; i++) {
|
||||
lores[i] = loreColor + Core.getl(lores[i], lang);
|
||||
}
|
||||
meta.setLore(Arrays.asList(lores));
|
||||
}
|
||||
itemNames.put(display, type);
|
||||
stack.setItemMeta(meta);
|
||||
stacks.put(lang, stack);
|
||||
}
|
||||
items.put(type, stacks);
|
||||
}
|
||||
|
||||
public static void buildInvItem(String type, Material m, String name, ChatColor nameColor) {
|
||||
buildInvItem(type, m, name, nameColor, null, "none");
|
||||
}
|
||||
|
||||
public static HashMap<String, ItemStack> buildItems(Material m, String name, ChatColor nameColor, ChatColor loreColor, String... lores) {
|
||||
HashMap<String, ItemStack> stacks = new HashMap<>();
|
||||
for (String lang : Core.getAvailLangs()) {
|
||||
ItemStack stack = new ItemStack(m);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
meta.setDisplayName(nameColor + Core.getl(name, lang));
|
||||
if (loreColor != null) {
|
||||
for (int i = 0; i < lores.length; i++) {
|
||||
lores[i] = loreColor + Core.getl(lores[i], lang);
|
||||
}
|
||||
meta.setLore(Arrays.asList(lores));
|
||||
}
|
||||
stack.setItemMeta(meta);
|
||||
stacks.put(lang, stack);
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
|
||||
public static HashMap<String, ItemStack> buildItems(Material m, String name, ChatColor nameColor, String lang, ChatColor loreColor, String... lores) {
|
||||
HashMap<String, ItemStack> stacks = new HashMap<>();
|
||||
ItemStack stack = new ItemStack(m);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
meta.setDisplayName(nameColor + Core.getl(name, lang));
|
||||
if (loreColor != null) {
|
||||
for (int i = 0; i < lores.length; i++) {
|
||||
lores[i] = loreColor + Core.getl(lores[i], lang);
|
||||
}
|
||||
meta.setLore(Arrays.asList(lores));
|
||||
}
|
||||
stack.setItemMeta(meta);
|
||||
stacks.put("global", stack);
|
||||
return stacks;
|
||||
}
|
||||
|
||||
public static HashMap<String, ItemStack> buildItems(Material m, String name, ChatColor nameColor, String lang) {
|
||||
return buildItems(m, name, nameColor, lang, null, "none");
|
||||
}
|
||||
|
||||
public static HashMap<String, ItemStack> buildItems(Material m, String name, ChatColor nameColor) {
|
||||
return buildItems(m, name, nameColor, null, "none");
|
||||
}
|
||||
|
||||
public static void putIntoInventory(String type, int position, HashMap<String, ItemStack> items) {
|
||||
for (Entry<String, ItemStack> item : items.entrySet()) {
|
||||
invs.get(type).get(item.getKey()).setItem(position, item.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerAction(String type, int slot, Action action, Object data) {
|
||||
if (action == Action.MESSAGE && !(data instanceof String)) {
|
||||
return;
|
||||
}
|
||||
if (action == Action.OPEN_INV && !(data instanceof String)) {
|
||||
return;
|
||||
}
|
||||
if (action == Action.SERVER && !(data instanceof String)) {
|
||||
return;
|
||||
}
|
||||
if (action == Action.COMMAND && !(data instanceof String)) {
|
||||
return;
|
||||
}
|
||||
if (action == Action.TELEPORT && !(data instanceof Location)) {
|
||||
return;
|
||||
}
|
||||
invActions.get(type).put(slot, new AbstractMap.SimpleEntry<>(action, data));
|
||||
}
|
||||
|
||||
public static Inventory getInventory(String type, Player P) {
|
||||
if (invType.get(type)) {
|
||||
return invs.get(type).get(Core.getPlayerLang(P));
|
||||
} else {
|
||||
return invs.get(type).get("global");
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack getItem(String type, Player P) {
|
||||
return items.get(type).get(Core.getPlayerLang(P));
|
||||
}
|
||||
|
||||
public static void setItemInPlayerInv(String type, Integer position) {
|
||||
itemPositions.put(type, position);
|
||||
}
|
||||
|
||||
public static void registerItemAction(String type, Action action, Object data) {
|
||||
if ((action == Action.TELEPORT && !(data instanceof Location)) || (action != Action.TELEPORT && !(data instanceof String))) {
|
||||
return;
|
||||
}
|
||||
itemActions.put(type, new AbstractMap.SimpleEntry<>(action, data));
|
||||
}
|
||||
|
||||
public static void executeAction(Player P, Action action, Object data) {
|
||||
try {
|
||||
if (action == Action.SERVER) {
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(b);
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF((String) data);
|
||||
P.sendPluginMessage(AnuraCore.getInstance(), "BungeeCord", b.toByteArray());
|
||||
} else if (action == Action.MESSAGE) {
|
||||
Core.statusMsg(P, (String) data, true);
|
||||
} else if (action == Action.OPEN_INV) {
|
||||
P.openInventory(getInventory((String) data, P));
|
||||
} else if (action == Action.TELEPORT) {
|
||||
P.teleport((Location) data);
|
||||
} else if (action == Action.COMMAND) {
|
||||
Bukkit.getServer().dispatchCommand(P, (String) data);
|
||||
} else if (action == Action.LANGUAGE) {
|
||||
String lang = (String) data;
|
||||
Core.cachedPlayerLanguage.put(P, lang);
|
||||
Core.getMySql().queryUpdate("UPDATE players SET lang = '" + lang + "' WHERE uuid = '" + P.getUniqueId().toString() + "'");
|
||||
PlayerInventory pi = P.getInventory();
|
||||
for (Entry<String, Integer> item : itemPositions.entrySet()) {
|
||||
pi.setItem(item.getValue(), getItem(item.getKey(), P));
|
||||
}
|
||||
Core.statusMsg(P, "lang_changed", true);
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addInvItems(Player P) {
|
||||
if (!itemPositions.isEmpty()) {
|
||||
P.getInventory().clear();
|
||||
}
|
||||
for (Entry<String, Integer> item : itemPositions.entrySet()) {
|
||||
P.getInventory().setItem(item.getValue(), getItem(item.getKey(), P));
|
||||
}
|
||||
}
|
||||
|
||||
public static void openInventory(String inv, Player P) {
|
||||
P.openInventory(invs.get(inv).get(invType.get(inv) ? Core.getPlayerLang(P) : "global"));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInvClick(InventoryClickEvent event) {
|
||||
try {
|
||||
if (checkInteracts.containsKey((Player) event.getWhoClicked()) && !checkInteracts.get((Player) event.getWhoClicked())) {
|
||||
return;
|
||||
}
|
||||
final Player player = (Player) event.getWhoClicked();
|
||||
Inventory inventory = event.getClickedInventory();
|
||||
if (inventory == null) return;
|
||||
String invName = inventory.getName();
|
||||
if (invNames.containsKey(invName)) {
|
||||
event.setCancelled(true);
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
player.updateInventory();
|
||||
if (invActions.get(invNames.get(invName)).containsKey(event.getSlot())) {
|
||||
player.closeInventory();
|
||||
Entry<Action, Object> action = invActions.get(invNames.get(invName)).get(event.getSlot());
|
||||
executeAction(player, action.getKey(), action.getValue());
|
||||
} else {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(AnuraCore.getInstance(), () -> {
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
player.updateInventory();
|
||||
}, 1);
|
||||
}
|
||||
} else if (invNames.containsKey(event.getInventory().getName())) {
|
||||
event.setCancelled(true);
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
player.updateInventory();
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
try {
|
||||
if (checkInteracts.containsKey(event.getPlayer()) && !checkInteracts.get(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
if (event.hasItem()) {
|
||||
if (event.getAction().equals(org.bukkit.event.block.Action.RIGHT_CLICK_AIR) || event.getAction().equals(org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK)) {
|
||||
final Player P = event.getPlayer();
|
||||
String type = itemNames.get(P.getItemInHand().getItemMeta().getDisplayName());
|
||||
if (itemActions.containsKey(type)) {
|
||||
event.setCancelled(true);
|
||||
executeAction(P, itemActions.get(type).getKey(), itemActions.get(type).getValue());
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(AnuraCore.getInstance(), P::updateInventory, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.LOW)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
addInvItems(event.getPlayer());
|
||||
}
|
||||
}
|
||||
@@ -1,356 +0,0 @@
|
||||
package de.anura.core.API;
|
||||
|
||||
import de.anura.core.AnuraCore;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class Inventories_NEW implements Listener {
|
||||
|
||||
private final boolean multilang;
|
||||
private final HashMap<String, Inventory> invs = new HashMap<>();
|
||||
private final HashMap<Integer, InvItem> items = new HashMap<>();
|
||||
private final HashSet<String> invNames = new HashSet<>();
|
||||
|
||||
private String title;
|
||||
private ChatColor color;
|
||||
private int size;
|
||||
private String lang = null;
|
||||
|
||||
public Inventories_NEW(boolean multilang, String title, ChatColor color, int size) {
|
||||
assert(size % 9 == 0);
|
||||
this.multilang = multilang;
|
||||
this.title = title;
|
||||
this.color = color;
|
||||
this.size = size;
|
||||
inventories.add(this);
|
||||
}
|
||||
|
||||
public Inventories_NEW(String lang, String title, ChatColor color, int size) {
|
||||
this(true, title, color, size);
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
public Inventories_NEW(boolean multilang, String title, ChatColor color) {
|
||||
this(true, title, color, 9);
|
||||
}
|
||||
|
||||
public Inventories_NEW(String lang, String title, ChatColor color) {
|
||||
this(lang, title, color, 9);
|
||||
}
|
||||
|
||||
public Inventories_NEW settings(String name, ChatColor color, int size) {
|
||||
title = name;
|
||||
this.color = color;
|
||||
this.size = size;
|
||||
for (String inv : invs.keySet()) {
|
||||
createInventory(inv);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Inventories_NEW putItem(int slot, InvItem item) {
|
||||
items.put(slot, item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Inventories_NEW open(Player P) {
|
||||
if (multilang) P.openInventory(invs.get("global"));
|
||||
else P.openInventory(invs.get(Core.getPlayerLang(P)));
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean checkInvClick(String invName, int slot, Player P) {
|
||||
if (!invNames.contains(invName)) return false;
|
||||
if (!items.containsKey(slot)) return true;
|
||||
items.get(slot).click(P);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void createInventory(String inv) {
|
||||
String l = inv;
|
||||
if (l.equals("global")) {
|
||||
l = lang;
|
||||
}
|
||||
String name = color + Core.getl(title, l);
|
||||
Inventory i = Bukkit.createInventory(null, size, name);
|
||||
invNames.add(name);
|
||||
invs.put(inv, i);
|
||||
}
|
||||
|
||||
private void setupInvs() {
|
||||
if (multilang) createInventory("global");
|
||||
else {
|
||||
for (String l : Core.getAvailLangs()) {
|
||||
createInventory(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class InvItem {
|
||||
|
||||
private final ItemStack stack;
|
||||
private final String name;
|
||||
private final ChatColor color;
|
||||
private final ChatColor loreColor;
|
||||
private final String[] lores;
|
||||
private final HashSet<ActionData> actions = new HashSet<>();
|
||||
|
||||
public InvItem(ItemStack stack, String name, ChatColor nameColor, ChatColor loreColor, String... lores) {
|
||||
this.stack = stack;
|
||||
this.name = name;
|
||||
this.color = nameColor;
|
||||
this.loreColor = loreColor;
|
||||
this.lores = lores;
|
||||
}
|
||||
|
||||
public InvItem addAction(ActionData data) {
|
||||
actions.add(data);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack getItem(String lang) {
|
||||
ItemStack item = stack.clone();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(color + Core.getl(name, lang));
|
||||
if (lores.length != 0) {
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (String l : lores) {
|
||||
lore.add(loreColor + Core.getl(l, lang));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public void click(Player P) {
|
||||
for (ActionData action : actions) {
|
||||
Object data = action.getData();
|
||||
switch (action.getAction()) {
|
||||
case OPEN_INV:
|
||||
if (data instanceof Inventories_NEW) {
|
||||
((Inventories_NEW)data).open(P);
|
||||
}
|
||||
break;
|
||||
case TELEPORT:
|
||||
if (data instanceof Location) {
|
||||
P.teleport((Location) data);
|
||||
}
|
||||
break;
|
||||
case MESSAGE:
|
||||
if (data instanceof String) {
|
||||
P.sendMessage((String) data);
|
||||
}
|
||||
break;
|
||||
case SERVER:
|
||||
if (data instanceof String) {
|
||||
try {
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(b);
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF((String) data);
|
||||
P.sendPluginMessage(AnuraCore.getInstance(), "BungeeCord", b.toByteArray());
|
||||
} catch (IOException ex) {}
|
||||
}
|
||||
break;
|
||||
case COMMAND:
|
||||
if (data instanceof String) {
|
||||
Bukkit.getServer().dispatchCommand(P, (String) data);
|
||||
}
|
||||
break;
|
||||
case LANGUAGE:
|
||||
if (data instanceof String) {
|
||||
String lang = (String) data;
|
||||
Core.cachedPlayerLanguage.put(P, lang);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Core.getMainClass(), () -> {
|
||||
Core.getMySql().queryUpdate("UPDATE players SET lang = '" + lang + "' WHERE uuid = '" + P.getUniqueId().toString() + "'");
|
||||
});
|
||||
setInvItems(P);
|
||||
Core.statusMsg(P, "lang_changed", true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ActionData {
|
||||
|
||||
private final Action action;
|
||||
private final Object data;
|
||||
|
||||
public ActionData(Action a, Object d) {
|
||||
action = a;
|
||||
data = d;
|
||||
}
|
||||
|
||||
public Action getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Action {
|
||||
OPEN_INV,
|
||||
TELEPORT,
|
||||
MESSAGE,
|
||||
SERVER,
|
||||
COMMAND,
|
||||
LANGUAGE
|
||||
}
|
||||
|
||||
|
||||
private static final HashMap<String, HashMap<String, ItemStack>> oldItems = new HashMap<>();
|
||||
private static final HashMap<String, String> itemNames = new HashMap<>();
|
||||
private static final HashMap<String, Entry<Action, Object>> itemActions = new HashMap<>();
|
||||
private static final HashMap<String, Integer> itemPositions = new HashMap<>();
|
||||
|
||||
private static final HashSet<Inventories_NEW> inventories = new HashSet<>();
|
||||
public static final HashMap<Player, Boolean> checkInteracts = new HashMap<>();
|
||||
|
||||
|
||||
public static void buildInvItem(String type, Material m, String name, ChatColor nameColor, ChatColor loreColor, String... lores) { //INV!!
|
||||
HashMap<String, ItemStack> stacks = new HashMap<>();
|
||||
for (String lang : Core.getAvailLangs()) {
|
||||
ItemStack stack = new ItemStack(m);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
String display = nameColor + Core.getl(name, lang);
|
||||
meta.setDisplayName(display);
|
||||
if (loreColor != null) {
|
||||
for (int i = 0; i < lores.length; i++) {
|
||||
lores[i] = loreColor + Core.getl(lores[i], lang);
|
||||
}
|
||||
meta.setLore(Arrays.asList(lores));
|
||||
}
|
||||
itemNames.put(display, type);
|
||||
stack.setItemMeta(meta);
|
||||
stacks.put(lang, stack);
|
||||
}
|
||||
oldItems.put(type, stacks);
|
||||
}
|
||||
|
||||
public static void buildInvItem(String type, Material m, String name, ChatColor nameColor) {
|
||||
buildInvItem(type, m, name, nameColor, null, "none");
|
||||
}
|
||||
|
||||
public static HashMap<String, ItemStack> buildItems(Material m, String name, ChatColor nameColor, ChatColor loreColor, String... lores) {
|
||||
HashMap<String, ItemStack> stacks = new HashMap<>();
|
||||
for (String lang : Core.getAvailLangs()) {
|
||||
ItemStack stack = new ItemStack(m);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
meta.setDisplayName(nameColor + Core.getl(name, lang));
|
||||
if (loreColor != null) {
|
||||
for (int i = 0; i < lores.length; i++) {
|
||||
lores[i] = loreColor + Core.getl(lores[i], lang);
|
||||
}
|
||||
meta.setLore(Arrays.asList(lores));
|
||||
}
|
||||
stack.setItemMeta(meta);
|
||||
stacks.put(lang, stack);
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
|
||||
public static ItemStack getItem(String type, Player P) {
|
||||
return oldItems.get(type).get(Core.getPlayerLang(P));
|
||||
}
|
||||
|
||||
public static void setItemInPlayerInv(String type, Integer position) {
|
||||
itemPositions.put(type, position);
|
||||
}
|
||||
|
||||
public static void registerItemAction(String type, Action action, Object data) {
|
||||
if ((action == Action.TELEPORT && !(data instanceof Location)) || (action != Action.TELEPORT && !(data instanceof String))) {
|
||||
return;
|
||||
}
|
||||
itemActions.put(type, new AbstractMap.SimpleEntry<>(action, data));
|
||||
}
|
||||
|
||||
public static void setInvItems(Player P) {
|
||||
if (!itemPositions.isEmpty()) {
|
||||
P.getInventory().clear();
|
||||
}
|
||||
for (Entry<String, Integer> item : itemPositions.entrySet()) {
|
||||
P.getInventory().setItem(item.getValue(), getItem(item.getKey(), P));
|
||||
}
|
||||
}
|
||||
|
||||
public static class InvEvents implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInvClick(InventoryClickEvent event) {
|
||||
try {
|
||||
final Player P = (Player) event.getWhoClicked();
|
||||
if (checkInteracts.containsKey(P) && !checkInteracts.get(P)) {
|
||||
return;
|
||||
}
|
||||
Inventory inventory = event.getClickedInventory();
|
||||
if (inventory == null) return;
|
||||
for (Inventories_NEW i : inventories) {
|
||||
if (i.checkInvClick(inventory.getName(), event.getSlot(), P)) {
|
||||
event.setCancelled(true);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(AnuraCore.getInstance(), () -> {
|
||||
P.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
P.updateInventory();
|
||||
}, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
try {
|
||||
if (checkInteracts.containsKey(event.getPlayer()) && !checkInteracts.get(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
if (event.hasItem()) {
|
||||
if (event.getAction().equals(org.bukkit.event.block.Action.RIGHT_CLICK_AIR) || event.getAction().equals(org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK)) {
|
||||
final Player P = event.getPlayer();
|
||||
String type = itemNames.get(P.getItemInHand().getItemMeta().getDisplayName());
|
||||
if (itemActions.containsKey(type)) {
|
||||
event.setCancelled(true);
|
||||
//executeAction(P, itemActions.get(type).getKey(), itemActions.get(type).getValue());
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(AnuraCore.getInstance(), P::updateInventory, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.LOW)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
setInvItems(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
package de.anura.core.API;
|
||||
|
||||
import de.anura.core.util.Data;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.HashMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public final class Level {
|
||||
|
||||
private static final HashMap<Player, Integer> anuraLevel = new HashMap<>();
|
||||
private static final HashMap<Player, Integer> smashLevel = new HashMap<>();
|
||||
private static final HashMap<Player, Integer> ffLevel = new HashMap<>();
|
||||
|
||||
public Level() {
|
||||
try {
|
||||
for (Player P : Bukkit.getOnlinePlayers()) {
|
||||
Data.joinTime.put(P, (int) (System.currentTimeMillis() / 1000));
|
||||
Data.aimTheWaterWins.put(P, 0);
|
||||
}
|
||||
loadLevelAll();
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.getMainClass(), this::update, 20 * 60, 20 * 60);
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveStuffAll() {
|
||||
for (Player P : Bukkit.getOnlinePlayers()) {
|
||||
saveStuff(P);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveStuff(Player P) {
|
||||
int walkedMeters = P.getStatistic(Statistic.WALK_ONE_CM) / 100;
|
||||
int playedTime = (int) ((System.currentTimeMillis() / 1000 - Data.joinTime.get(P)) / 60);
|
||||
Core.getMySql().queryUpdate("UPDATE coreStats "
|
||||
+ "SET onlineTime = onlineTime + " + playedTime + ""
|
||||
+ ", walkedMeters = walkedMeters + " + walkedMeters + ""
|
||||
+ ", aimTheWaterWins = aimTheWaterWins + " + Data.aimTheWaterWins.get(P) + " "
|
||||
+ "WHERE player = (SELECT id FROM players WHERE uuid = '" + P.getUniqueId().toString() + "')");
|
||||
Data.joinTime.put(P, (int) (System.currentTimeMillis() / 1000));
|
||||
P.setStatistic(Statistic.WALK_ONE_CM, 0);
|
||||
Data.aimTheWaterWins.put(P, 0);
|
||||
}
|
||||
|
||||
public void loadLevelAll() {
|
||||
for (Player P : Bukkit.getOnlinePlayers()) {
|
||||
loadLevel(P);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadLevel(Player P) {
|
||||
try {
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT level, smashLevel, ffLevel FROM coreStats WHERE player = (SELECT id FROM players WHERE uuid = '" + P.getUniqueId().toString() + "')");
|
||||
rs.first();
|
||||
anuraLevel.put(P, (int) rs.getDouble("level"));
|
||||
smashLevel.put(P, rs.getInt("smashLevel"));
|
||||
ffLevel.put(P, rs.getInt("ffLevel"));
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void update() {
|
||||
for (Player P : Bukkit.getOnlinePlayers()) {
|
||||
update(P);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(Player P) {
|
||||
try {
|
||||
if (!anuraLevel.containsKey(P)) {
|
||||
return;
|
||||
}
|
||||
saveStuff(P);
|
||||
String whereClause = " = (SELECT id FROM players WHERE uuid = '" + P.getUniqueId().toString() + "')";
|
||||
ResultSet stats = Core.getMySql().querySelect("SELECT * FROM coreStats WHERE player" + whereClause);
|
||||
ResultSet features = Core.getMySql().querySelect("SELECT count(*) as features FROM coreFeatures WHERE playerId" + whereClause);
|
||||
ResultSet pots = Core.getMySql().querySelect("SELECT count(*) as pots FROM coreFoundPots WHERE player" + whereClause);
|
||||
ResultSet stages = Core.getMySql().querySelect("SELECT count(*) as stages FROM jumpUsers WHERE playerId" + whereClause);
|
||||
ResultSet smashClasses = Core.getMySql().querySelect("SELECT count(*) as classes FROM smashClasses WHERE playerId" + whereClause);
|
||||
ResultSet ffStats = Core.getMySql().querySelect("SELECT SUM(totalKillsAlive) as killsAlive, SUM(totalKillsUndead) as killsUndead, SUM(totalDeaths) as totalDeaths, SUM(hasWon) as wins, COUNT(*) as games FROM ffStatsPlayers WHERE playerId" + whereClause);
|
||||
stats.first();
|
||||
features.first();
|
||||
pots.first();
|
||||
stages.first();
|
||||
smashClasses.first();
|
||||
ffStats.first();
|
||||
int time = stats.getInt("onlineTime");
|
||||
double walked = stats.getInt("walkedMeters");
|
||||
int wins = stats.getInt("aimTheWaterWins");
|
||||
double kills = stats.getInt("smashKills");
|
||||
double deaths = stats.getInt("smashDeaths");
|
||||
double killstreak = stats.getInt("smashKillstreak");
|
||||
double smashMoney = stats.getInt("smashMoney");
|
||||
int maxSmashLevel = stats.getInt("maxSmashLevel");
|
||||
int maxFFLevel = stats.getInt("maxFFLevel");
|
||||
int feature = features.getInt("features");
|
||||
int pot = pots.getInt("pots");
|
||||
int stage = stages.getInt("stages");
|
||||
int classes = smashClasses.getInt("classes");
|
||||
int ffKills = ffStats.getInt("killsAlive") + ffStats.getInt("killsUndead");
|
||||
int ffDeaths = ffStats.getInt("totalDeaths");
|
||||
int ffWins = ffStats.getInt("wins");
|
||||
int ffGames = ffStats.getInt("games");
|
||||
double fLevel = (ffKills/(ffDeaths + 1)) * 2 * (ffKills / 25) + ffWins / 5 + ffGames / 15;
|
||||
double level = (time * 0.0375 + walked / 300.0 + wins * 250 + feature * 1200 + pot * 200 + stage * 400) / 400.0;
|
||||
double sLevel = ((kills / (deaths + 1)) * kills / 90 + smashMoney / 90 + classes * 5 + (killstreak * killstreak) / 4) / 3 + 1;
|
||||
if (maxSmashLevel < sLevel) {
|
||||
maxSmashLevel = (int) sLevel;
|
||||
}
|
||||
if (maxFFLevel < fLevel) {
|
||||
maxFFLevel = (int) fLevel;
|
||||
}
|
||||
level += (double) (maxSmashLevel / 4);
|
||||
level += (double) maxFFLevel;
|
||||
anuraLevel.put(P, (int) level);
|
||||
smashLevel.put(P, (int) sLevel);
|
||||
ffLevel.put(P, (int) fLevel);
|
||||
Core.getMySql().queryUpdate("UPDATE coreStats SET level = '" + level + "', smashLevel = '" + sLevel + "', maxSmashLevel = '" + maxSmashLevel + "', ffLevel = '" + fLevel + "', maxFFLevel = '" + maxFFLevel + "' WHERE player" + whereClause);
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateLevel(Player P) {
|
||||
Core.getLevel().update(P);
|
||||
}
|
||||
|
||||
public static int getSmashLevel(Player P) {
|
||||
return smashLevel.get(P);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package de.anura.core.API;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.HashMap;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class Money {
|
||||
|
||||
private static final HashMap<OfflinePlayer, Integer> playerMoney = new HashMap<>();
|
||||
|
||||
public static void payMoney(OfflinePlayer P, int count) {
|
||||
if (!playerMoney.containsKey(P)) {
|
||||
if (!loadMoney(P)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
int money = playerMoney.get(P) + count;
|
||||
if (money < 0) money = 0;
|
||||
playerMoney.put(P, money);
|
||||
}
|
||||
|
||||
public static void saveMoney(OfflinePlayer P) {
|
||||
if (!playerMoney.containsKey(P)) {
|
||||
return;
|
||||
}
|
||||
Core.getMySql().queryUpdate("UPDATE coreStats SET money = '" + playerMoney.get(P) + "' WHERE player = (SELECT id FROM players WHERE uuid = '" + P.getUniqueId().toString() + "')");
|
||||
playerMoney.remove(P);
|
||||
}
|
||||
|
||||
public static boolean loadMoney(OfflinePlayer P) {
|
||||
try {
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT money FROM coreStats WHERE player = (SELECT id FROM players WHERE uuid = '" + P.getUniqueId().toString() + "')");
|
||||
rs.first();
|
||||
playerMoney.put(P, rs.getInt("money"));
|
||||
return true;
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getMoney(OfflinePlayer P) {
|
||||
if (!playerMoney.containsKey(P)) {
|
||||
if (!loadMoney(P)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return playerMoney.get(P);
|
||||
}
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
package de.anura.core.API;
|
||||
|
||||
import de.anura.core.AnuraCore;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class MySQL {
|
||||
|
||||
private Connection conn;
|
||||
private static final String dbLoc = "database.";
|
||||
public FileConfiguration config;
|
||||
private boolean reconnecting = false;
|
||||
|
||||
public MySQL() {
|
||||
File file = new File("plugins/Core/", "database.yml");
|
||||
FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
|
||||
cfg.addDefault(dbLoc + "host", "localhost");
|
||||
cfg.addDefault(dbLoc + "port", 3306);
|
||||
cfg.addDefault(dbLoc + "username", "username");
|
||||
cfg.addDefault(dbLoc + "pw", "pw");
|
||||
cfg.addDefault(dbLoc + "db", "db");
|
||||
cfg.options().copyDefaults(true);
|
||||
try {
|
||||
cfg.save(file);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
this.config = cfg;
|
||||
if (!this.openConnection()) {
|
||||
Bukkit.broadcastMessage(ChatColor.RED + "No database connection available, please contact a server administrator!");
|
||||
}
|
||||
}
|
||||
|
||||
public String escapeString(String text) {
|
||||
return text == null ? "" : text.replace("\\", "").replace("'", "\\'");
|
||||
}
|
||||
|
||||
private Boolean openConnection() {
|
||||
String host = config.getString(dbLoc + "host");
|
||||
int port = config.getInt(dbLoc + "port");
|
||||
String username = config.getString(dbLoc + "username");
|
||||
String pw = config.getString(dbLoc + "pw");
|
||||
String db = config.getString(dbLoc + "db");
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
Connection connLoc = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + db, username, pw);
|
||||
this.conn = connLoc;
|
||||
return true;
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasConnection() {
|
||||
try {
|
||||
Boolean validConn = true;
|
||||
if (this.conn == null) {
|
||||
validConn = false;
|
||||
} else if (!this.conn.isValid(1)) {
|
||||
validConn = false;
|
||||
}
|
||||
return validConn;
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private Boolean reconnect() {
|
||||
if (this.reconnecting) {
|
||||
return false;
|
||||
}
|
||||
this.reconnecting = true;
|
||||
System.out.println("Reconnecting...");
|
||||
this.closeConnection();
|
||||
if (!this.openConnection()) {
|
||||
Bukkit.broadcastMessage(ChatColor.RED + "Database reconnect failed! Please contact a server administrator!");
|
||||
} else {
|
||||
System.out.println("Database reconnect successful!");
|
||||
}
|
||||
this.reconnecting = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void queryRedo(final String query) {
|
||||
if (!this.reconnect()) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(AnuraCore.getInstance(), () -> {
|
||||
Core.getMySql().queryUpdate(query);
|
||||
}, 4);
|
||||
}
|
||||
}
|
||||
|
||||
public void queryUpdate(String query) {
|
||||
if (!this.hasConnection()) {
|
||||
queryRedo(query);
|
||||
}
|
||||
Connection connLoc = this.conn;
|
||||
PreparedStatement st = null;
|
||||
try {
|
||||
st = connLoc.prepareStatement(query);
|
||||
st.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Failed to send Update '" + query + "'! (" + e.getLocalizedMessage() + ")");
|
||||
}
|
||||
this.closeRessources(null, st);
|
||||
}
|
||||
|
||||
public ResultSet querySelect(final String query) {
|
||||
if (!this.hasConnection()) {
|
||||
reconnect();
|
||||
}
|
||||
try {
|
||||
PreparedStatement st = this.conn.prepareStatement(query);
|
||||
ResultSet returns = this.querySelect(st);
|
||||
return returns;
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Unknown error whilst trying to build Prepared Statement!");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ResultSet querySelect(PreparedStatement st) {
|
||||
if (!this.hasConnection()) {
|
||||
reconnect();
|
||||
}
|
||||
ResultSet rs;
|
||||
try {
|
||||
rs = st.executeQuery();
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Failed to send 'SELECT'-Query!(" + st.toString() + ")");
|
||||
System.err.println("Caused by: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
||||
private void closeRessources(ResultSet rs, PreparedStatement st) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
if (st != null) {
|
||||
try {
|
||||
st.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
public void closeConnection() {
|
||||
try {
|
||||
if (this.conn != null) {
|
||||
this.conn.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
} finally {
|
||||
this.conn = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package de.anura.core.API;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class Tools {
|
||||
|
||||
/**
|
||||
* Sends a given message to a given player with the given status
|
||||
*
|
||||
* @param p The player to send the message to
|
||||
* @param msg The message to send
|
||||
* @param positive If the message should be green(true) or red(false)
|
||||
*/
|
||||
public static void sendStatusMsg(CommandSender p, String msg, Boolean positive) {
|
||||
ChatColor chatColor;
|
||||
if (positive) {
|
||||
chatColor = ChatColor.GREEN;
|
||||
} else {
|
||||
chatColor = ChatColor.RED;
|
||||
}
|
||||
p.sendMessage(ChatColor.GRAY + "[Anura] " + chatColor + msg);
|
||||
}
|
||||
}
|
||||
@@ -1,106 +1,93 @@
|
||||
package de.anura.core;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.API.Level;
|
||||
import de.anura.core.API.Money;
|
||||
import de.anura.core.API.MySQL;
|
||||
import de.anura.core.API.Tools;
|
||||
import de.anura.core.util.Data;
|
||||
import java.io.File;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class AnuraCore extends JavaPlugin {
|
||||
|
||||
private static MySQL sql;
|
||||
private static AnuraCore instance;
|
||||
public static Features features;
|
||||
public static Permissions perms;
|
||||
public static Signs signs;
|
||||
public static Tools tools;
|
||||
public static Level level;
|
||||
public static LanguageSupport lang;
|
||||
public static FlowerPots pots;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
try {
|
||||
sql = new MySQL();
|
||||
instance = this;
|
||||
if (sql.hasConnection()) {
|
||||
if (AnuraCore.getInstance().getConfig().getBoolean("is-main-lobby")) {
|
||||
for (World w : Bukkit.getWorlds()) {
|
||||
for (Entity e : w.getEntities()) {
|
||||
if (e.getType().equals(EntityType.BOAT)) {
|
||||
e.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||
Setup.setupConfig();
|
||||
Setup.setupEvents();
|
||||
Setup.setupClasses();
|
||||
Setup.setupTasks();
|
||||
Setup.setupCommands();
|
||||
if (this.getConfig().getBoolean("is-main-lobby")) {
|
||||
Setup.setupXPBattle();
|
||||
}
|
||||
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", signs);
|
||||
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new Teleports());
|
||||
sql.queryUpdate("DELETE FROM coreServers WHERE name = '" + this.getConfig().getString("server-name") + "'");
|
||||
sql.queryUpdate("INSERT INTO coreServers (name, maxPlayers) VALUES ('" + this.getConfig().getString("server-name") + "','" + this.getServer().getMaxPlayers() + "')");
|
||||
for (World w : Bukkit.getWorlds()) {
|
||||
AnuraVillager.addVillagers(w.getEntities());
|
||||
}
|
||||
} else {
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
try {
|
||||
if (!sql.hasConnection()) {
|
||||
return;
|
||||
}
|
||||
for (Player P : getServer().getOnlinePlayers()) {
|
||||
Money.saveMoney(P);
|
||||
}
|
||||
File configFile = new File("plugins/Core/", "config.yml");
|
||||
File dbFile = new File("plugins/Core", "database.yml");
|
||||
AnuraCore.sql.config.save(dbFile);
|
||||
this.getConfig().save(configFile);
|
||||
sql.queryUpdate("DELETE FROM coreServers WHERE name = '" + this.getConfig().getString("server-name") + "'");
|
||||
features.reset();
|
||||
level.update();
|
||||
for (Player P : Data.sittingPlayer.keySet()) {
|
||||
Core.endSitting(P, true);
|
||||
}
|
||||
Data.sittingPlayer.clear();
|
||||
sql.closeConnection();
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static AnuraCore getInstance() {
|
||||
return AnuraCore.instance;
|
||||
}
|
||||
|
||||
public static MySQL getSql() {
|
||||
return AnuraCore.sql;
|
||||
}
|
||||
|
||||
public Features getFeatures() {
|
||||
return features;
|
||||
}
|
||||
}
|
||||
package de.anura.core;
|
||||
|
||||
import de.anura.core.commands.Answer;
|
||||
import de.anura.core.commands.GameMode;
|
||||
import de.anura.core.commands.MessageCmd;
|
||||
import de.anura.core.commands.MoneyCmd;
|
||||
import de.anura.core.commands.Spawn;
|
||||
import de.anura.core.database.DB;
|
||||
import de.anura.core.database.ErrorAppender;
|
||||
import de.anura.core.listeners.*;
|
||||
import de.anura.core.msg.Msg;
|
||||
import de.anura.core.msg.Msg.MsgType;
|
||||
import de.anura.core.msg.Msg.PluginType;
|
||||
import de.anura.core.tools.Villagers;
|
||||
import de.anura.core.tools.Potions;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.core.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class AnuraCore extends JavaPlugin {
|
||||
|
||||
private static AnuraCore instance;
|
||||
private static ErrorAppender errorAppender;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
|
||||
Msg.register(this, "SYSTEM", PluginType.SYSTEM);
|
||||
Logger logger = (Logger) LogManager.getRootLogger();
|
||||
errorAppender = new ErrorAppender();
|
||||
logger.addAppender(errorAppender);
|
||||
|
||||
registerEvents();
|
||||
registerCommands();
|
||||
|
||||
AnuraThread.init();
|
||||
Villagers.init();
|
||||
Potions.init();
|
||||
Money.init();
|
||||
|
||||
for (Player P : Bukkit.getOnlinePlayers()) {
|
||||
JoinEvent.addAttachment(P);
|
||||
Potions.join(P);
|
||||
}
|
||||
|
||||
Msg.send(this, MsgType.SUCCESS, "Server wurde erfolgreich neu geladen!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
Msg.send(this, MsgType.SPECIAL, "Server wird neu geladen!");
|
||||
|
||||
Money.save();
|
||||
|
||||
AnuraThread.shutdown();
|
||||
Potions.disable();
|
||||
Logger logger = (Logger) LogManager.getRootLogger();
|
||||
logger.removeAppender(errorAppender);
|
||||
DB.stop();
|
||||
}
|
||||
|
||||
public static AnuraCore getInstance() {
|
||||
return AnuraCore.instance;
|
||||
}
|
||||
|
||||
private void registerEvents() {
|
||||
PluginManager man = Bukkit.getPluginManager();
|
||||
man.registerEvents(new EntityDamage(), this);
|
||||
man.registerEvents(new EntityFish(), this);
|
||||
man.registerEvents(new InteractEntity(), this);
|
||||
man.registerEvents(new InventoryEvent(), this);
|
||||
man.registerEvents(new JoinEvent(), this);
|
||||
man.registerEvents(new LeaveEvent(), this);
|
||||
man.registerEvents(new PlayerChat(), this);
|
||||
man.registerEvents(new PotionEvents(), this);
|
||||
}
|
||||
|
||||
@SuppressWarnings("null")
|
||||
private void registerCommands() {
|
||||
getCommand("r").setExecutor(new Answer());
|
||||
getCommand("gm").setExecutor(new GameMode());
|
||||
getCommand("money").setExecutor(new MoneyCmd());
|
||||
getCommand("spawn").setExecutor(new Spawn());
|
||||
|
||||
MessageCmd msgCmd = new MessageCmd();
|
||||
getCommand("msg").setExecutor(msgCmd);
|
||||
getCommand("msg").setTabCompleter(msgCmd);
|
||||
}
|
||||
}
|
||||
|
||||
153
src/de/anura/core/AnuraThread.java
Normal file
153
src/de/anura/core/AnuraThread.java
Normal file
@@ -0,0 +1,153 @@
|
||||
package de.anura.core;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.scheduler.CraftTask;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public abstract class AnuraThread {
|
||||
|
||||
private static final Set<BukkitTask> tasks = Collections.synchronizedSet(new HashSet<>());
|
||||
private static Method taskClass = null;
|
||||
private static final Map<String, Integer> log = new ConcurrentHashMap<>();
|
||||
private static final Queue<Runnable> doSync = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public static void init() {
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(AnuraCore.getInstance(), AnuraThread::check, 20 * 30, 20 * 60 * 5);
|
||||
add(Bukkit.getScheduler().runTaskTimer(AnuraCore.getInstance(), () -> {
|
||||
long millis = System.currentTimeMillis();
|
||||
Runnable lastRun = null;
|
||||
for (int i = 0; i < 200; i++) {
|
||||
if (doSync.isEmpty()) return;
|
||||
try {
|
||||
lastRun = doSync.poll();
|
||||
lastRun.run();
|
||||
} catch (Throwable t) {
|
||||
Logger.getLogger(AnuraThread.class.getName()).log(Level.SEVERE, "Caught exception while running sync task", t);
|
||||
}
|
||||
if (System.currentTimeMillis() - millis > 25) { // 50% of tick time
|
||||
if (i > 0 && doSync.size() > 10) {
|
||||
Logger.getLogger(AnuraThread.class.getName()).log(Level.INFO, "{0} sync tasks queued for execution!", doSync.size());
|
||||
} else if (i == 0 && lastRun != null) {
|
||||
Logger.getLogger(AnuraThread.class.getName()).log(Level.INFO, "{0} took too long ({1}ms) to execute!", new Object[] { lastRun.getClass().getName(), System.currentTimeMillis() - millis });
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, 3, 3));
|
||||
}
|
||||
|
||||
public static void check() {
|
||||
BukkitScheduler s = Bukkit.getScheduler();
|
||||
synchronized (tasks) {
|
||||
int j = 0;
|
||||
Iterator<BukkitTask> taskIt = tasks.iterator();
|
||||
while (taskIt.hasNext()) {
|
||||
BukkitTask task = taskIt.next();
|
||||
if (!s.isCurrentlyRunning(task.getTaskId()) && !s.isQueued(task.getTaskId())) {
|
||||
taskIt.remove();
|
||||
j++;
|
||||
}
|
||||
}
|
||||
if (j > 10) Logger.getLogger(AnuraThread.class.getName()).log(Level.INFO, "Cleaned up {0} tasks!", j);
|
||||
}
|
||||
synchronized (log) {
|
||||
for (Entry<String, Integer> clazz : log.entrySet()) {
|
||||
if (clazz.getValue() > 200) {
|
||||
Logger.getLogger(AnuraThread.class.getName()).log(Level.WARNING, "{0} newly registered tasks for {1}", new Object[] {clazz.getValue(), clazz.getKey()});
|
||||
}
|
||||
}
|
||||
}
|
||||
log.clear();
|
||||
}
|
||||
|
||||
public static void queueSync(Runnable r) {
|
||||
doSync.add(r);
|
||||
}
|
||||
|
||||
public static void sync(Runnable r) {
|
||||
if (!AnuraCore.getInstance().isEnabled()) {
|
||||
Logger.getLogger(AnuraThread.class.getName()).log(Level.WARNING, "Ignore newly registered task for {0}: Server is shutting down", r.getClass());
|
||||
return;
|
||||
}
|
||||
add(Bukkit.getScheduler().runTask(AnuraCore.getInstance(), r));
|
||||
}
|
||||
|
||||
public static void async(Runnable r) {
|
||||
if (!AnuraCore.getInstance().isEnabled()) {
|
||||
Logger.getLogger(AnuraThread.class.getName()).log(Level.WARNING, "Ignore newly registered task for {0}: Server is shutting down", r.getClass());
|
||||
return;
|
||||
}
|
||||
add(Bukkit.getScheduler().runTaskAsynchronously(AnuraCore.getInstance(), r));
|
||||
}
|
||||
|
||||
public static <A> void syncCB(Consumer<A> cb, A value) {
|
||||
sync(() -> cb.accept(value));
|
||||
}
|
||||
|
||||
public static <A> void asyncCB(Consumer<A> cb, A value) {
|
||||
async(() -> cb.accept(value));
|
||||
}
|
||||
|
||||
public static void shutdown() {
|
||||
synchronized (tasks) {
|
||||
BukkitScheduler s = Bukkit.getScheduler();
|
||||
tasks.forEach((t) -> {
|
||||
if (!s.isCurrentlyRunning(t.getTaskId()) && !s.isQueued(t.getTaskId())) return;
|
||||
Logger.getLogger(AnuraThread.class.getName()).log(Level.INFO, "Shutting down {0} ({1})", new Object[] {t.getTaskId(), getName(t)});
|
||||
t.cancel();
|
||||
});
|
||||
tasks.clear();
|
||||
}
|
||||
if (doSync.size() > 0) {
|
||||
Logger.getLogger(AnuraThread.class.getName()).log(Level.INFO, "Running {0} queued sync tasks", doSync.size());
|
||||
synchronized (doSync) {
|
||||
doSync.forEach(Runnable::run);
|
||||
}
|
||||
doSync.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static void add(BukkitTask task) {
|
||||
tasks.add(task);
|
||||
String name = getName(task);
|
||||
log.put(name, log.containsKey(name) ? log.get(name) + 1 : 1);
|
||||
}
|
||||
|
||||
private static String getName(BukkitTask task) {
|
||||
reflect();
|
||||
String name = null;
|
||||
try {
|
||||
name = taskClass.invoke(task).toString().split("\\$")[0];
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
|
||||
Logger.getLogger(AnuraThread.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
if (name == null) name = "unknown";
|
||||
return name;
|
||||
}
|
||||
|
||||
private static void reflect() {
|
||||
if (taskClass == null) {
|
||||
try {
|
||||
taskClass = CraftTask.class.getDeclaredMethod("getTaskClass");
|
||||
taskClass.setAccessible(true);
|
||||
} catch (NoSuchMethodException | SecurityException ex) {
|
||||
Logger.getLogger(AnuraThread.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
package de.anura.core;
|
||||
|
||||
import de.anura.core.Features.Feature;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.entity.Villager.Profession;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public class AnuraVillager {
|
||||
|
||||
private final VillagerType type;
|
||||
private Villager villager;
|
||||
private Location loc;
|
||||
|
||||
public AnuraVillager(VillagerType type) {
|
||||
this.type = type;
|
||||
villagers.put(type, this);
|
||||
}
|
||||
|
||||
public AnuraVillager(VillagerType type, Villager villager) {
|
||||
this(type);
|
||||
setVillager(villager);
|
||||
loc = villager.getLocation();
|
||||
}
|
||||
|
||||
public void spawn(Location loc) {
|
||||
Villager v = buildVillager(loc, type.getName());
|
||||
setVillager(v);
|
||||
this.loc = loc;
|
||||
}
|
||||
|
||||
private void setVillager(Villager v) {
|
||||
villager = v;
|
||||
byEntity.put(v, this);
|
||||
}
|
||||
|
||||
private Villager buildVillager(Location loc, String name) {
|
||||
Villager vi = loc.getWorld().spawn(loc, Villager.class);
|
||||
vi.setProfession(Profession.PRIEST);
|
||||
vi.setBaby();
|
||||
vi.setAgeLock(true);
|
||||
vi.setBreed(false);
|
||||
vi.setCanPickupItems(false);
|
||||
vi.setCustomName(ChatColor.GOLD + name);
|
||||
vi.setCustomNameVisible(true);
|
||||
vi.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 999999999, 999));
|
||||
return vi;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
byEntity.remove(villager);
|
||||
villagers.remove(type);
|
||||
}
|
||||
|
||||
public VillagerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void tp() {
|
||||
villager.teleport(loc);
|
||||
}
|
||||
|
||||
public static void addVillagers(Entity[] entities) {
|
||||
addVillagers(Arrays.asList(entities));
|
||||
}
|
||||
|
||||
public static void addVillagers(List<Entity> entities) {
|
||||
for (Entity e : entities) {
|
||||
if (e.isValid() && e.getType().equals(EntityType.VILLAGER)) {
|
||||
Villager vi = (Villager) e;
|
||||
if (vi.getCustomName() != null && VillagerType.getByName(vi.getCustomName()) != null) {
|
||||
new AnuraVillager(VillagerType.getByName(vi.getCustomName()), vi);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeVillagers(Entity[] entities) {
|
||||
for (Entity e : entities) {
|
||||
if (e.isValid() && e.getType().equals(EntityType.VILLAGER)) {
|
||||
Villager vi = (Villager) e;
|
||||
if (vi.getCustomName() != null && VillagerType.getByName(vi.getCustomName()) != null) {
|
||||
AnuraVillager av = getByEntity(vi);
|
||||
if (av == null) continue;
|
||||
av.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static AnuraVillager getByEntity(Villager v) {
|
||||
return byEntity.get(v);
|
||||
}
|
||||
|
||||
public static AnuraVillager getByType(VillagerType type) {
|
||||
return villagers.get(type);
|
||||
}
|
||||
|
||||
private static final HashMap<Villager, AnuraVillager> byEntity = new HashMap<>();
|
||||
public static final HashMap<VillagerType, AnuraVillager> villagers = new HashMap<>();
|
||||
|
||||
|
||||
public enum VillagerType {
|
||||
DOUBLE_JUMP(Feature.DOUBLE_JUMP, "Double jump"),
|
||||
AUTO_BOAT(Feature.BOAT, "AutoBoat");
|
||||
|
||||
private VillagerType(Feature feature, String name) {
|
||||
this.feature = feature;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private final Feature feature;
|
||||
private final String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Feature getFeature() {
|
||||
return feature;
|
||||
}
|
||||
|
||||
private final static HashMap<Feature, VillagerType> BY_FEATURE = new HashMap<>();
|
||||
private final static HashMap<String, VillagerType> BY_NAME = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (VillagerType type : values()) {
|
||||
BY_FEATURE.put(type.getFeature(), type);
|
||||
BY_NAME.put(type.getName(), type);
|
||||
}
|
||||
}
|
||||
|
||||
public static VillagerType getByFeature(Feature feature) {
|
||||
return BY_FEATURE.get(feature);
|
||||
}
|
||||
|
||||
public static VillagerType getByName(String name) {
|
||||
return BY_NAME.containsKey(name) ? BY_NAME.get(name) : BY_NAME.get(name.substring(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,293 +0,0 @@
|
||||
package de.anura.core;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.API.Inventories;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
||||
import org.bukkit.event.vehicle.VehicleExitEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class Features implements Listener {
|
||||
|
||||
private final Location atwCenter;
|
||||
|
||||
public enum Feature {
|
||||
|
||||
DOUBLE_JUMP(1),
|
||||
BOAT(2);
|
||||
|
||||
private Feature(int id) {
|
||||
this.featureId = id;
|
||||
}
|
||||
public final int featureId;
|
||||
private static final HashMap<Integer, Feature> BY_ID = new HashMap<>();
|
||||
|
||||
public int getId() {
|
||||
return featureId;
|
||||
}
|
||||
|
||||
public static Feature getById(Integer id) {
|
||||
return BY_ID.get(id);
|
||||
}
|
||||
|
||||
static {
|
||||
for (Feature feature : values()) {
|
||||
BY_ID.put(feature.featureId, feature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Features() {
|
||||
Bukkit.getPluginManager().registerEvents(this, AnuraCore.getInstance());
|
||||
atwCenter = new Location(Bukkit.getWorld("lobby"), -297, 31, -1742);
|
||||
}
|
||||
|
||||
private final HashMap<Player, ArrayList<Feature>> playerFeatures = new HashMap<>();
|
||||
private final HashMap<Player, Boolean> canDoubleJump = new HashMap<>();
|
||||
public final HashMap<Player, HashMap<Feature, Boolean>> featureEnabled = new HashMap<>();
|
||||
public static ArrayList<UUID> wantFlight = new ArrayList<>();
|
||||
|
||||
public void updateFeatures(Player P) {
|
||||
try {
|
||||
if (!mainLobby()) {
|
||||
return;
|
||||
}
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT featureId FROM coreFeatures WHERE playerId = (SELECT id FROM players WHERE uuid = '" + P.getUniqueId().toString() + "')");
|
||||
resetPlayerFeatures(P);
|
||||
playerFeatures.put(P, new ArrayList<>());
|
||||
featureEnabled.put(P, new HashMap<>());
|
||||
boolean added = false;
|
||||
while (rs.next()) {
|
||||
if (!added) {
|
||||
P.getInventory().setItem(2, Inventories.getItem("CHARGE", P));
|
||||
added = true;
|
||||
}
|
||||
if (Feature.getById(rs.getInt("featureId")) != null) {
|
||||
this.addFeature(P, Feature.getById(rs.getInt("featureId")));
|
||||
featureEnabled.get(P).put(Feature.getById(rs.getInt("featureId")), true);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateFeaturesAll() {
|
||||
if (!mainLobby()) {
|
||||
return;
|
||||
}
|
||||
for (Player P : Bukkit.getOnlinePlayers()) {
|
||||
updateFeatures(P);
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
for (Player P : Bukkit.getOnlinePlayers()) {
|
||||
this.resetPlayerFeatures(P);
|
||||
}
|
||||
}
|
||||
|
||||
public void disableFeature(Player P, Feature f) {
|
||||
try {
|
||||
if (!mainLobby()) {
|
||||
return;
|
||||
}
|
||||
if (f == Feature.DOUBLE_JUMP) {
|
||||
if (!hasFeature(P, f)) {
|
||||
Core.statusMsg(P, "dont_have_dbl_jump", false);
|
||||
return;
|
||||
}
|
||||
featureEnabled.get(P).put(f, false);
|
||||
canDoubleJump.put(P, false);
|
||||
Core.statusMsg(P, "dbl_jump_off", true);
|
||||
P.setExp(0);
|
||||
if (P.getGameMode() != GameMode.CREATIVE) {
|
||||
P.setAllowFlight(false);
|
||||
}
|
||||
} else if (f == Feature.BOAT) {
|
||||
if (!hasFeature(P, f)) {
|
||||
Core.statusMsg(P, "dont_have_boats", false);
|
||||
}
|
||||
featureEnabled.get(P).put(f, false);
|
||||
Core.statusMsg(P, "boat_off", true);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void enableFeature(Player P, Feature f) {
|
||||
try {
|
||||
if (!mainLobby()) {
|
||||
return;
|
||||
}
|
||||
if (f == Feature.DOUBLE_JUMP) {
|
||||
if (!hasFeature(P, f)) {
|
||||
Core.statusMsg(P, "dont_have_dbl_jump", false);
|
||||
return;
|
||||
}
|
||||
featureEnabled.get(P).put(f, true);
|
||||
P.setAllowFlight(true);
|
||||
P.setExp(1);
|
||||
canDoubleJump.put(P, true);
|
||||
Core.statusMsg(P, "dbl_jump_on", true);
|
||||
} else if (f == Feature.BOAT) {
|
||||
if (!hasFeature(P, f)) {
|
||||
Core.statusMsg(P, "dont_have_boats", false);
|
||||
}
|
||||
featureEnabled.get(P).put(f, true);
|
||||
Core.statusMsg(P, "boat_on", true);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasFeature(Player P, Feature f) {
|
||||
if (!mainLobby()) {
|
||||
return false;
|
||||
}
|
||||
if (playerFeatures.containsKey(P)) {
|
||||
return playerFeatures.get(P).contains(f);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void resetPlayerFeatures(Player P) {
|
||||
if (!playerFeatures.containsKey(P)) {
|
||||
return;
|
||||
}
|
||||
for (Feature f : (Iterable<? extends Feature>) playerFeatures.get(P).clone()) {
|
||||
removeFeature(P, f);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFeature(Player P, Feature f) {
|
||||
if (!mainLobby()) {
|
||||
return;
|
||||
}
|
||||
if (playerFeatures.containsKey(P)) {
|
||||
playerFeatures.get(P).remove(f);
|
||||
}
|
||||
if (f.equals(Feature.DOUBLE_JUMP)) {
|
||||
if (!P.getGameMode().equals(GameMode.CREATIVE)) {
|
||||
P.setAllowFlight(false);
|
||||
P.setExp(0);
|
||||
}
|
||||
this.canDoubleJump.put(P, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void addFeature(Player P, Feature f) {
|
||||
if (!mainLobby()) {
|
||||
return;
|
||||
}
|
||||
if (playerFeatures.containsKey(P) && !hasFeature(P, f)) {
|
||||
playerFeatures.get(P).add(f);
|
||||
}
|
||||
if (f.equals(Feature.DOUBLE_JUMP)) {
|
||||
P.setAllowFlight(true);
|
||||
P.setExp(1);
|
||||
this.canDoubleJump.put(P, true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean mainLobby() {
|
||||
return AnuraCore.getInstance().getConfig().getBoolean("is-main-lobby");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
try {
|
||||
if (!mainLobby()) {
|
||||
return;
|
||||
}
|
||||
Player P = event.getPlayer();
|
||||
if (this.hasFeature(P, Feature.DOUBLE_JUMP)) {
|
||||
if (this.canDoubleJump.containsKey(P) && !this.canDoubleJump.get(P) && P.isOnGround() && this.featureEnabled.get(P).get(Feature.DOUBLE_JUMP)) {
|
||||
this.canDoubleJump.put(P, true);
|
||||
P.setExp(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.hasFeature(P, Feature.BOAT) && featureEnabled.get(P).get(Feature.BOAT)) {
|
||||
if (P.getLocation().getBlock().getType().equals(Material.STATIONARY_WATER) && P.getVehicle() == null) {
|
||||
if (P.getWorld().equals(atwCenter.getWorld()) && P.getLocation().distance(atwCenter) < 30) return;
|
||||
Boat b = (Boat) P.getWorld().spawnEntity(event.getTo(), EntityType.BOAT);
|
||||
b.setPassenger(P);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onToggleFlight(PlayerToggleFlightEvent event) {
|
||||
try {
|
||||
if (!mainLobby()) {
|
||||
return;
|
||||
}
|
||||
Player P = event.getPlayer();
|
||||
|
||||
if (this.hasFeature(P, Feature.DOUBLE_JUMP) && !P.getGameMode().equals(GameMode.CREATIVE)) {
|
||||
if (this.canDoubleJump.containsKey(P) && this.canDoubleJump.get(P)) {
|
||||
this.canDoubleJump.put(P, false);
|
||||
P.setExp(0);
|
||||
Vector v = P.getLocation().getDirection();
|
||||
P.setVelocity(v.multiply(new Vector(1, 2, 1)));
|
||||
P.setVelocity(P.getVelocity().setY(1));
|
||||
} else {
|
||||
Vector v = P.getVelocity();
|
||||
P.setVelocity(v.setY(-0.4));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBoatDestory(VehicleDestroyEvent event) {
|
||||
try {
|
||||
if (event.getVehicle().getType().equals(EntityType.BOAT) && AnuraCore.getInstance().getConfig().getBoolean("is-main-lobby")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onExit(VehicleExitEvent event) {
|
||||
try {
|
||||
if (event.getVehicle().getType().equals(EntityType.BOAT) && AnuraCore.getInstance().getConfig().getBoolean("is-main-lobby")) {
|
||||
event.getVehicle().remove();
|
||||
Player p = (Player) event.getExited();
|
||||
p.setVelocity(p.getVelocity().add(new Vector(0D, 1D, 0D)));
|
||||
if (p.getGameMode().equals(GameMode.CREATIVE) && wantFlight.contains(p.getUniqueId())) {
|
||||
p.setFlying(true);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
package de.anura.core;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.API.Money;
|
||||
import de.anura.core.util.Data;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class FlowerPots {
|
||||
|
||||
private final static HashMap<Player, HashMap<Integer, Boolean>> foundCache = new HashMap<>();
|
||||
private final static HashMap<Player, HashMap<Integer, Integer>> foundTimestamp = new HashMap<>();
|
||||
|
||||
public static boolean foundPot(Player P, Integer pot) {
|
||||
if (!foundCache.containsKey(P)) {
|
||||
refreshCache(P);
|
||||
}
|
||||
if (foundCache.get(P).containsKey(pot)) {
|
||||
if (foundCache.get(P).get(pot) && foundTimestamp.get(P).containsKey(pot)) {
|
||||
if ((System.currentTimeMillis() / 1000 - foundTimestamp.get(P).get(pot)) >= getPotWaitTime(pot)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int getPotWaitTime(Integer pot) {
|
||||
if (Data.flowerPots.containsKey(pot)) {
|
||||
if (Data.flowerPotsWait.containsKey(pot)) {
|
||||
return Data.flowerPotsWait.get(pot);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void refreshCache(Player P) {
|
||||
try {
|
||||
ResultSet rs = AnuraCore.getSql().querySelect("SELECT id, timestamp, type FROM coreFoundPots WHERE player = (SELECT id FROM players WHERE uuid = '" + P.getUniqueId().toString() + "')");
|
||||
HashMap<Integer, Boolean> list = new HashMap<>();
|
||||
HashMap<Integer, Integer> listTimes = new HashMap<>();
|
||||
while (rs.next()) {
|
||||
list.put(rs.getInt("id"), rs.getBoolean("type"));
|
||||
if (rs.getBoolean("type")) {
|
||||
listTimes.put(rs.getInt("id"), rs.getInt("timestamp"));
|
||||
}
|
||||
}
|
||||
foundCache.put(P, list);
|
||||
foundTimestamp.put(P, listTimes);
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void refreshPot(Integer pot) {
|
||||
Location l = Data.flowerPots.get(pot);
|
||||
for (Player P : l.getWorld().getPlayers()) {
|
||||
if (P.getLocation().distance(l) < 20) {
|
||||
refreshPlayerPot(P, pot, l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void refreshPlayerPot(Player p, Integer pot, Location l) {
|
||||
if (!foundPot(p, pot)) {
|
||||
p.sendBlockChange(l, Material.FLOWER_POT, (byte) 0);
|
||||
} else {
|
||||
p.sendBlockChange(l, Material.AIR, (byte) 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void refreshPlayer(Player p) {
|
||||
for (Map.Entry<Integer, Location> pots : Data.flowerPots.entrySet()) {
|
||||
if (pots.getValue().getWorld().equals(p.getLocation().getWorld()) && pots.getValue().distance(p.getLocation()) < 20) {
|
||||
refreshPlayerPot(p, pots.getKey(), pots.getValue());
|
||||
}
|
||||
}
|
||||
Data.lastLoc.put(p, p.getLocation());
|
||||
}
|
||||
|
||||
public static void playerFoundPot(Player P, Integer pot) {
|
||||
try {
|
||||
if (!foundPot(P, pot)) {
|
||||
Integer time = getPotWaitTime(pot);
|
||||
boolean alreadyFound = foundCache.get(P).containsKey(pot);
|
||||
int type = 0;
|
||||
if (time == -1) {
|
||||
foundCache.get(P).put(pot, false);
|
||||
} else {
|
||||
type = 1;
|
||||
foundCache.get(P).put(pot, true);
|
||||
foundTimestamp.get(P).put(pot, (int) (System.currentTimeMillis() / 1000));
|
||||
}
|
||||
String sql;
|
||||
if (alreadyFound) {
|
||||
sql = "UPDATE coreFoundPots SET timestamp = '" + (System.currentTimeMillis() / 1000) + "', type = 1 WHERE player = (SELECT id FROM players WHERE uuid = '" + P.getUniqueId().toString() + "') AND id = '" + pot + "'";
|
||||
} else {
|
||||
sql = "INSERT INTO coreFoundPots(id, player, timestamp, type) VALUES('" + pot + "', (SELECT id FROM players WHERE uuid = '" + P.getUniqueId().toString() + "'),'" + (int) (System.currentTimeMillis() / 1000) + "'," + type + ")";
|
||||
}
|
||||
AnuraCore.getSql().queryUpdate(sql);
|
||||
Location loc = Data.flowerPots.get(pot);
|
||||
for (int i = 0; i < 20; i++) {
|
||||
loc.getWorld().playEffect(loc, Effect.FIREWORKS_SPARK, 4);
|
||||
}
|
||||
P.playSound(loc, Sound.ENTITY_PLAYER_LEVELUP, 1, (float) 1.5);
|
||||
ResultSet rs = AnuraCore.getSql().querySelect("SELECT id, url, name, money FROM corePots WHERE id = '" + pot + "'");
|
||||
rs.first();
|
||||
Money.payMoney(P, rs.getInt("money"));
|
||||
P.sendMessage(ChatColor.RED + "---------- " + ChatColor.YELLOW + "Achievement" + ChatColor.RED + " ----------");
|
||||
P.sendMessage(ChatColor.BLUE + Core.getl(rs.getString("name"), Core.getPlayerLang(P)));
|
||||
P.sendMessage("" + ChatColor.GOLD + ChatColor.UNDERLINE + "http://mc-anura.de/index.php?location=achievement_" + rs.getString("id"));
|
||||
P.sendMessage("");
|
||||
P.sendMessage(ChatColor.RED + "---------- " + ChatColor.YELLOW + "Achievement" + ChatColor.RED + " ----------");
|
||||
} else if (getPotWaitTime(pot) != -1 && foundCache.containsKey(P) && foundCache.get(P).containsKey(pot) && foundTimestamp.containsKey(P) && foundTimestamp.get(P).containsKey(pot)) {
|
||||
int current = (int) (System.currentTimeMillis() / 1000);
|
||||
int found = foundTimestamp.get(P).get(pot);
|
||||
int waitTime = getPotWaitTime(pot);
|
||||
int toWait = (found + waitTime) - current;
|
||||
if (toWait <= 0) {
|
||||
return;
|
||||
}
|
||||
String text = ChatColor.RED + Core.getl("ach_wait_1", P);
|
||||
if (toWait < 60) {
|
||||
text += " " + ChatColor.GREEN + toWait + " " + ChatColor.RED + Core.getl("ach_wait_seconds", P);
|
||||
} else if (toWait < 60 * 60) {
|
||||
text += " " + ChatColor.GREEN + Math.round(toWait / 60) + " " + ChatColor.RED + Core.getl("ach_wait_minutes", P);
|
||||
} else if (toWait < 60 * 60 * 24) {
|
||||
text += " " + ChatColor.GREEN + Math.round(toWait / 60 / 60) + " " + ChatColor.RED + Core.getl("ach_wait_hours", P);
|
||||
} else {
|
||||
text += " " + ChatColor.GREEN + Math.round(toWait / 60 / 60 / 24) + " " + ChatColor.RED + Core.getl("ach_wait_days", P);
|
||||
}
|
||||
text += " " + Core.getl("ach_wait_2", P);
|
||||
|
||||
P.sendMessage(text);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package de.anura.core;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.HashMap;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class LanguageSupport {
|
||||
|
||||
public HashMap<String, String> languages = new HashMap<>();
|
||||
private HashMap<String, HashMap<String, String>> languageValues = new HashMap<>();
|
||||
|
||||
public LanguageSupport() {
|
||||
try {
|
||||
ResultSet al = Core.getMySql().querySelect("SELECT name, short_name FROM coreAvailableLanguages WHERE `show` = 1");
|
||||
if (!al.next()) {
|
||||
return;
|
||||
}
|
||||
al.beforeFirst();
|
||||
String languageString = "";
|
||||
while (al.next()) {
|
||||
languages.put(al.getString("short_name"), al.getString("name"));
|
||||
languageString += ", " + al.getString("short_name");
|
||||
languageValues.put(al.getString("short_name"), new HashMap<>());
|
||||
}
|
||||
ResultSet lv = Core.getMySql().querySelect("SELECT id" + languageString + " FROM coreLanguages");
|
||||
while (lv.next()) {
|
||||
for (String lang : languages.keySet()) {
|
||||
languageValues.get(lang).put(lv.getString("id"), lv.getString(lang));
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String get(String id, String lang) {
|
||||
String value;
|
||||
if (languageValues.get(lang).containsKey(id)) {
|
||||
value = languageValues.get(lang).get(id);
|
||||
} else {
|
||||
value = id;
|
||||
}
|
||||
return ChatColor.translateAlternateColorCodes('&', value);
|
||||
}
|
||||
}
|
||||
94
src/de/anura/core/Money.java
Normal file
94
src/de/anura/core/Money.java
Normal file
@@ -0,0 +1,94 @@
|
||||
package de.anura.core;
|
||||
|
||||
import de.anura.core.database.DB;
|
||||
import de.anura.core.database.MySQL.PreparedUpdate;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class Money {
|
||||
|
||||
public static final String CURRENCY = "Hundewelpen";
|
||||
public static final int INITIAL_MONEY = 20;
|
||||
|
||||
private static final Map<UUID, Integer> playerMoney = new ConcurrentHashMap<>();
|
||||
|
||||
private static final Set<UUID> toSave = Collections.newSetFromMap(new ConcurrentHashMap<UUID, Boolean>());
|
||||
|
||||
public static void init() {
|
||||
AnuraThread.add(Bukkit.getScheduler().runTaskTimerAsynchronously(AnuraCore.getInstance(), Money::save, 20 * 60, 20 * 60));
|
||||
}
|
||||
|
||||
public static void payMoney(UUID uuid, int count) {
|
||||
// TODO: Thread safety!
|
||||
Runnable exec = () -> {
|
||||
int money = playerMoney.get(uuid) + count;
|
||||
if (money < 0) money = 0;
|
||||
playerMoney.put(uuid, money);
|
||||
toSave.add(uuid);
|
||||
};
|
||||
|
||||
if (playerMoney.containsKey(uuid)) {
|
||||
exec.run();
|
||||
} else {
|
||||
AnuraThread.async(() -> {
|
||||
if (loadMoney(uuid)) {
|
||||
exec.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void save() {
|
||||
if (toSave.isEmpty())
|
||||
return;
|
||||
|
||||
PreparedUpdate prep = DB.queryPrepUpdate("UPDATE players SET money = ? WHERE uuid = ?");
|
||||
|
||||
if (prep == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (UUID uuid : toSave) {
|
||||
if (playerMoney.containsKey(uuid)) {
|
||||
prep.add(playerMoney.remove(uuid), uuid.toString());
|
||||
}
|
||||
}
|
||||
prep.done();
|
||||
|
||||
toSave.clear();
|
||||
}
|
||||
|
||||
public static boolean loadMoney(UUID uuid) {
|
||||
try {
|
||||
ResultSet rs = DB.querySelect("SELECT money FROM players WHERE uuid = ?", uuid.toString());
|
||||
rs.first();
|
||||
playerMoney.put(uuid, rs.getInt("money"));
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(Money.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void getMoney(UUID uuid, Consumer<Integer> moneyCB) {
|
||||
if (playerMoney.containsKey(uuid)) {
|
||||
moneyCB.accept(playerMoney.get(uuid));
|
||||
} else {
|
||||
AnuraThread.async(() -> {
|
||||
if (!loadMoney(uuid)) {
|
||||
moneyCB.accept(-1);
|
||||
}
|
||||
moneyCB.accept(playerMoney.get(uuid));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
package de.anura.core;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
|
||||
public final class Permissions implements Listener {
|
||||
|
||||
private final HashMap<Integer, String> groupNames = new HashMap<>();
|
||||
private final HashMap<Integer, ArrayList<String>> groupPerms = new HashMap<>();
|
||||
private final HashMap<UUID, ArrayList<Integer>> playerGroups = new HashMap<>();
|
||||
private final HashMap<Integer, Integer> groupParents = new HashMap<>();
|
||||
private final HashMap<Integer, String> groupPrefix = new HashMap<>();
|
||||
private final HashMap<Integer, String> groupSuffix = new HashMap<>();
|
||||
private final HashMap<Integer, String> groupListColor = new HashMap<>();
|
||||
private final HashMap<Player, PermissionAttachment> permAttachments = new HashMap<>();
|
||||
|
||||
private int groupAutoIncrement = 0;
|
||||
private final AnuraCore plugin;
|
||||
|
||||
public Permissions(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.reload();
|
||||
this.plugin = plugin;
|
||||
this.createPermAttachs();
|
||||
this.updateAllPlayers();
|
||||
}
|
||||
|
||||
//Event handlers
|
||||
@EventHandler
|
||||
public void playerJoin(PlayerJoinEvent event) {
|
||||
Player P = event.getPlayer();
|
||||
this.permAttachments.put(P, P.addAttachment(this.plugin));
|
||||
this.updatePlayer(P);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerKick(PlayerKickEvent event) {
|
||||
Player P = event.getPlayer();
|
||||
if (this.permAttachments.get(P) == null) {
|
||||
return;
|
||||
}
|
||||
P.removeAttachment(this.permAttachments.get(P));
|
||||
this.permAttachments.remove(P);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerQuit(PlayerQuitEvent event) {
|
||||
Player P = event.getPlayer();
|
||||
if (this.permAttachments.get(P) == null) {
|
||||
return;
|
||||
}
|
||||
P.removeAttachment(this.permAttachments.get(P));
|
||||
this.permAttachments.remove(P);
|
||||
}
|
||||
|
||||
//The permission stuff
|
||||
private void createPermAttachs() {
|
||||
for (Player P : Bukkit.getOnlinePlayers()) {
|
||||
this.permAttachments.put(P, P.addAttachment(this.plugin));
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAllPlayers() {
|
||||
for (Player P : Bukkit.getOnlinePlayers()) {
|
||||
this.updatePlayer(P);
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePlayer(Player P) {
|
||||
try {
|
||||
PermissionAttachment pa = this.permAttachments.get(P);
|
||||
for (String p : pa.getPermissions().keySet()) {
|
||||
pa.unsetPermission(p);
|
||||
}
|
||||
if (!this.playerGroups.containsKey(P.getUniqueId())) {
|
||||
this.playerGroups.put(P.getUniqueId(), new ArrayList<>());
|
||||
}
|
||||
ArrayList<Integer> groups = this.playerGroups.get(P.getUniqueId());
|
||||
ArrayList<Integer> assignedGroups = new ArrayList<>();
|
||||
String prefixes = "";
|
||||
String suffixes = "";
|
||||
String listColor = "";
|
||||
for (Integer g : groups) {
|
||||
if (assignedGroups.contains(g)) {
|
||||
continue;
|
||||
}
|
||||
assignedGroups.add(g);
|
||||
for (String perm : this.groupPerms.get(g)) {
|
||||
pa.setPermission(perm, true);
|
||||
}
|
||||
ArrayList<String> perms = this.getParentPerms(g, assignedGroups);
|
||||
for (String perm : perms) {
|
||||
pa.setPermission(perm, true);
|
||||
}
|
||||
if (this.groupPrefix.containsKey(g)) {
|
||||
prefixes += this.groupPrefix.get(g);
|
||||
}
|
||||
if (this.groupSuffix.containsKey(g)) {
|
||||
suffixes += this.groupSuffix.get(g);
|
||||
}
|
||||
if (this.groupListColor.containsKey(g)) {
|
||||
listColor = this.groupListColor.get(g);
|
||||
}
|
||||
}
|
||||
String name = prefixes + P.getName() + suffixes;
|
||||
P.setDisplayName(name);
|
||||
P.setPlayerListName(listColor + P.getName());
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<String> getParentPerms(Integer group, ArrayList<Integer> assigned) {
|
||||
ArrayList<String> toReturn = new ArrayList<>();
|
||||
if (this.groupParents.get(group) == -1) {
|
||||
return toReturn;
|
||||
}
|
||||
if (assigned.contains(this.groupParents.get(group))) {
|
||||
return toReturn;
|
||||
}
|
||||
for (String perm : this.groupPerms.get(this.groupParents.get(group))) {
|
||||
toReturn.add(perm);
|
||||
}
|
||||
for (String perm : this.getParentPerms(this.groupParents.get(group), assigned)) {
|
||||
toReturn.add(perm);
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public String reload() {
|
||||
try {
|
||||
ResultSet groupsRs = Core.getMySql().querySelect("SELECT prefix, suffix, parent, name, id, listColor FROM permGroups");
|
||||
ResultSet permsRs = Core.getMySql().querySelect("SELECT `group`, name FROM permPerms");
|
||||
ResultSet userRs = Core.getMySql().querySelect("SELECT playerUUID, `group` FROM permPlayerGroups");
|
||||
this.groupNames.clear();
|
||||
this.groupPerms.clear();
|
||||
this.playerGroups.clear();
|
||||
this.groupParents.clear();
|
||||
this.groupPrefix.clear();
|
||||
this.groupSuffix.clear();
|
||||
HashMap<Integer, Integer> groupIds = new HashMap<>();
|
||||
this.groupAutoIncrement = 0;
|
||||
groupsRs.last();
|
||||
if (groupsRs.getRow() != 0) {
|
||||
groupsRs.beforeFirst();
|
||||
while (groupsRs.next()) {
|
||||
int id = this.groupAutoIncrement;
|
||||
this.groupNames.put(id, groupsRs.getString("name"));
|
||||
this.groupPerms.put(id, new ArrayList<>());
|
||||
this.groupParents.put(id, groupsRs.getInt("parent"));
|
||||
if (groupsRs.getString("prefix") != null) {
|
||||
this.groupPrefix.put(id, groupsRs.getString("prefix"));
|
||||
}
|
||||
if (groupsRs.getString("suffix") != null) {
|
||||
this.groupSuffix.put(id, groupsRs.getString("suffix"));
|
||||
}
|
||||
if (groupsRs.getString("listColor") != null) {
|
||||
this.groupListColor.put(id, groupsRs.getString("listColor"));
|
||||
}
|
||||
groupIds.put(groupsRs.getInt("id"), id);
|
||||
this.groupAutoIncrement++;
|
||||
}
|
||||
}
|
||||
permsRs.last();
|
||||
if (permsRs.getRow() != 0) {
|
||||
permsRs.beforeFirst();
|
||||
while (permsRs.next()) {
|
||||
int groupId = groupIds.get(permsRs.getInt("group"));
|
||||
if (this.groupNames.containsKey(groupId)) {
|
||||
|
||||
this.groupPerms.get(groupId).add(permsRs.getString("name"));
|
||||
}
|
||||
}
|
||||
}
|
||||
userRs.last();
|
||||
if (userRs.getRow() != 0) {
|
||||
userRs.beforeFirst();
|
||||
while (userRs.next()) {
|
||||
int groupId = groupIds.get(userRs.getInt("group"));
|
||||
if (this.groupNames.containsKey(groupId)) {
|
||||
ArrayList<Integer> groupList = this.playerGroups.get(UUID.fromString(userRs.getString("playerUUID")));
|
||||
if (groupList == null) {
|
||||
groupList = new ArrayList<>();
|
||||
}
|
||||
groupList.add(groupId);
|
||||
this.playerGroups.put(UUID.fromString(userRs.getString("playerUUID")), groupList);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
return ChatColor.GREEN + "Permissions reloaded!";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,279 +0,0 @@
|
||||
package de.anura.core;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.API.Inventories;
|
||||
import de.anura.core.API.Level;
|
||||
import de.anura.core.API.Tools;
|
||||
import de.anura.core.commands.*;
|
||||
import de.anura.core.events.*;
|
||||
import de.anura.core.util.Data;
|
||||
import java.sql.ResultSet;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.material.Stairs;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class Setup {
|
||||
|
||||
public static void setupConfig() {
|
||||
FileConfiguration c = Core.getMainClass().getConfig();
|
||||
c.addDefault("no-damage", false);
|
||||
c.addDefault("no-void-death", false);
|
||||
c.addDefault("no-change-blocks", false);
|
||||
c.addDefault("is-main-lobby", false);
|
||||
c.addDefault("no-hunger", false);
|
||||
c.addDefault("no-rain", false);
|
||||
c.addDefault("enable-leaves-decay", true);
|
||||
c.addDefault("server-name", "none");
|
||||
c.addDefault("allow-stairs-sit", false);
|
||||
c.addDefault("disable-mushroom-spread", false);
|
||||
c.addDefault("on-join-to-spawn", false);
|
||||
c.addDefault("golf", false);
|
||||
c.addDefault("no-snow-melt", false);
|
||||
c.addDefault("no-bed-explode", false);
|
||||
c.addDefault("spawn.world", "none");
|
||||
c.addDefault("spawn.X", 0);
|
||||
c.addDefault("spawn.Y", 0);
|
||||
c.addDefault("spawn.Z", 0);
|
||||
c.addDefault("spawn.yaw", 0d);
|
||||
c.addDefault("spawn.pitch", 0d);
|
||||
c.options().copyDefaults(true);
|
||||
c.options().header("Config File of the Anura Core-Plugin:");
|
||||
}
|
||||
|
||||
public static void setupEvents() {
|
||||
new PlayerJoin(Core.getMainClass());
|
||||
new PlayerMove(Core.getMainClass());
|
||||
new PlayerInteract(Core.getMainClass());
|
||||
new BlockBreak(Core.getMainClass());
|
||||
new BlockPlace(Core.getMainClass());
|
||||
new PlayerQuit(Core.getMainClass());
|
||||
new PlayerKick(Core.getMainClass());
|
||||
new PlayerChat(Core.getMainClass());
|
||||
new EntityDamage(Core.getMainClass());
|
||||
new WeatherChange(Core.getMainClass());
|
||||
new CmdPreprocess(Core.getMainClass());
|
||||
new HangingEBreak(Core.getMainClass());
|
||||
new FoodChange(Core.getMainClass());
|
||||
new LeavesDecay(Core.getMainClass());
|
||||
new EntityDamageByE(Core.getMainClass());
|
||||
new PlayerInteractE(Core.getMainClass());
|
||||
new SignChange(Core.getMainClass());
|
||||
new PlayerTeleport(Core.getMainClass());
|
||||
new InvClick(Core.getMainClass());
|
||||
new BlockSpread(Core.getMainClass());
|
||||
new DropItem(Core.getMainClass());
|
||||
new EntityChangeBlock(Core.getMainClass());
|
||||
new BlockFade(Core.getMainClass());
|
||||
new VillagerEvents(Core.getMainClass());
|
||||
}
|
||||
|
||||
public static void setupClasses() {
|
||||
try {
|
||||
AnuraCore.lang = new LanguageSupport();
|
||||
new Inventories(Core.getMainClass());
|
||||
setupInventories();
|
||||
AnuraCore.perms = new Permissions(Core.getMainClass());
|
||||
AnuraCore.tools = new Tools();
|
||||
AnuraCore.pots = new FlowerPots();
|
||||
AnuraCore.signs = new Signs();
|
||||
AnuraCore.level = new Level();
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT id, X, Y, Z, world, type, waitTime FROM corePots");
|
||||
while (rs.next()) {
|
||||
World w = Bukkit.getWorld(rs.getString("world"));
|
||||
if (w == null) {
|
||||
continue;
|
||||
}
|
||||
Location l = new Location(w, rs.getInt("X"), rs.getInt("Y"), rs.getInt("Z"));
|
||||
Data.flowerPots.put(rs.getInt("id"), l);
|
||||
if (rs.getBoolean("type")) {
|
||||
Data.flowerPotsWait.put(rs.getInt("id"), rs.getInt("waitTime"));
|
||||
}
|
||||
l.getBlock().setType(Material.BROWN_MUSHROOM);
|
||||
}
|
||||
AnuraCore.features = new Features();
|
||||
AnuraCore.features.updateFeaturesAll();
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setupTasks() {
|
||||
try {
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT world, X, Y, Z FROM coreStairs WHERE server = '" + Core.getMainClass().getConfig().getString("server-name") + "'");
|
||||
while (rs.next()) {
|
||||
World w = Bukkit.getWorld(rs.getString("world"));
|
||||
if (w == null) {
|
||||
continue;
|
||||
}
|
||||
Location l = new Location(w, rs.getInt("X"), rs.getInt("Y"), rs.getInt("Z"));
|
||||
if (l.getBlock().getState().getData() instanceof Stairs) {
|
||||
Data.sittableBlocks.add(l.getBlock());
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.getMainClass(), () -> {
|
||||
for (Player p : Data.sittingPlayer.keySet()) {
|
||||
Location loc = Data.sittingPlayer.get(p).getLocation();
|
||||
Arrow a = loc.getWorld().spawnArrow(loc, new Vector(0, 0, 0), 0, 0);
|
||||
a.setPassenger(p);
|
||||
Data.sittingPlayer.get(p).remove();
|
||||
Data.sittingPlayer.put(p, a);
|
||||
}
|
||||
}, 600, 600);
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.getMainClass(), AnuraCore.signs::updateServerSigns, 20 * 5, 20 * 5);
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.getMainClass(), new VillagerTask(), 20, 20);
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setupCommands() {
|
||||
TeamCommands tc = new TeamCommands();
|
||||
AdminCommands ac = new AdminCommands();
|
||||
PlayerCommands pc = new PlayerCommands();
|
||||
OtherCommands oc = new OtherCommands();
|
||||
|
||||
Core.getMainClass().getCommand("setjumper").setExecutor(tc);
|
||||
Core.getMainClass().getCommand("setspawn").setExecutor(ac);
|
||||
Core.getMainClass().getCommand("spawn").setExecutor(pc);
|
||||
Core.getMainClass().getCommand("money").setExecutor(pc);
|
||||
Core.getMainClass().getCommand("gm").setExecutor(tc);
|
||||
Core.getMainClass().getCommand("sun").setExecutor(tc);
|
||||
Core.getMainClass().getCommand("core").setExecutor(ac);
|
||||
Core.getMainClass().getCommand("hilfe").setExecutor(pc);
|
||||
Core.getMainClass().getCommand("none").setExecutor(oc);
|
||||
Core.getMainClass().getCommand("flyspeed").setExecutor(tc);
|
||||
Core.getMainClass().getCommand("setwarp").setExecutor(tc);
|
||||
Core.getMainClass().getCommand("warp").setExecutor(pc);
|
||||
Core.getMainClass().getCommand("remwarp").setExecutor(tc);
|
||||
Core.getMainClass().getCommand("flowerpot").setExecutor(tc);
|
||||
Core.getMainClass().getCommand("addmap").setExecutor(tc);
|
||||
Core.getMainClass().getCommand("rendermap").setExecutor(tc);
|
||||
Core.getMainClass().getCommand("cleararrows").setExecutor(ac);
|
||||
Core.getMainClass().getCommand("stairmode").setExecutor(tc);
|
||||
Core.getMainClass().getCommand("addcmd").setExecutor(tc);
|
||||
Core.getMainClass().getCommand("setcmd").setExecutor(tc);
|
||||
Core.getMainClass().getCommand("togglecommands").setExecutor(oc);
|
||||
Core.getMainClass().getCommand("addmap").setExecutor(tc);
|
||||
Core.getMainClass().getCommand("toggledbljump").setExecutor(pc);
|
||||
Core.getMainClass().getCommand("joinminigame").setExecutor(pc);
|
||||
Core.getMainClass().getCommand("leaveminigame").setExecutor(pc);
|
||||
Core.getMainClass().getCommand("toggleminigame").setExecutor(pc);
|
||||
Core.getMainClass().getCommand("addAimTWWin").setExecutor(oc);
|
||||
Core.getMainClass().getCommand("toggleboat").setExecutor(pc);
|
||||
Core.getMainClass().getCommand("toggleboatflight").setExecutor(tc);
|
||||
Core.getMainClass().getCommand("bug").setExecutor(pc);
|
||||
Core.getMainClass().getCommand("warplist").setExecutor(tc);
|
||||
Core.getMainClass().getCommand("addInvItems").setExecutor(oc);
|
||||
Core.getMainClass().getCommand("villager").setExecutor(ac);
|
||||
Core.getMainClass().getCommand("i").setExecutor(tc);
|
||||
Core.getMainClass().getCommand("mute").setExecutor(tc);
|
||||
Core.getMainClass().getCommand("unmute").setExecutor(tc);
|
||||
}
|
||||
|
||||
private static void setupInventories() {
|
||||
try {
|
||||
Inventories.registerInventory("GAMEMODES", "select_gamemode_inv", ChatColor.DARK_BLUE);
|
||||
Inventories.putIntoInventory("GAMEMODES", 0, Inventories.buildItems(Material.RED_ROSE, "inv_lobby_tps", ChatColor.DARK_GREEN));
|
||||
Inventories.putIntoInventory("GAMEMODES", 2, Inventories.buildItems(Material.CARROT_STICK, "inv_lobby_minigames", ChatColor.BLUE));
|
||||
Inventories.putIntoInventory("GAMEMODES", 4, Inventories.buildItems(Material.IRON_PICKAXE, "inv_lobby_freebuild", ChatColor.GOLD));
|
||||
|
||||
Inventories.registerAction("GAMEMODES", 0, Inventories.Action.OPEN_INV, "LOBBY");
|
||||
Inventories.registerAction("GAMEMODES", 2, Inventories.Action.OPEN_INV, "MINIGAMES");
|
||||
Inventories.registerAction("GAMEMODES", 4, Inventories.Action.SERVER, "freebuild");
|
||||
|
||||
Inventories.registerInventory("MINIGAMES", "minigames_inv", ChatColor.DARK_BLUE);
|
||||
if (Core.getMainClass().getConfig().getString("server-name").equals("lobby")) {
|
||||
Inventories.putIntoInventory("MINIGAMES", 0, Inventories.buildItems(Material.BOW, "inv_lobby_smash", ChatColor.GREEN, ChatColor.BLUE, "smash_description_1", "smash_description_2", "smash_description_3", "smash_description_4", "smash_description_5", "smash_description_6"));
|
||||
Inventories.putIntoInventory("MINIGAMES", 1, Inventories.buildItems(Material.WHEAT, "inv_lobby_farmfight", ChatColor.YELLOW));
|
||||
Inventories.putIntoInventory("MINIGAMES", 2, Inventories.buildItems(Material.FIREWORK, "inv_lobby_rocketmatch", ChatColor.DARK_AQUA));
|
||||
Inventories.putIntoInventory("MINIGAMES", 4, Inventories.buildItems(Material.EXP_BOTTLE, "inv_lobby_xpbattle", ChatColor.GREEN));
|
||||
Inventories.putIntoInventory("MINIGAMES", 5, Inventories.buildItems(Material.POTION, "inv_lobby_pool", ChatColor.DARK_AQUA));
|
||||
} else {
|
||||
Inventories.putIntoInventory("MINIGAMES", 0, Inventories.buildItems(Material.BOW, "inv_lobby_smash", ChatColor.GREEN, ChatColor.BLUE, "smash_description_1", "smash_description_2", "smash_description_3", "smash_description_4", "smash_description_5", "smash_description_6"));
|
||||
Inventories.putIntoInventory("MINIGAMES", 3, Inventories.buildItems(Material.WHEAT, "inv_lobby_farmfight", ChatColor.YELLOW));
|
||||
Inventories.putIntoInventory("MINIGAMES", 6, Inventories.buildItems(Material.FIREWORK, "inv_lobby_rocketmatch", ChatColor.DARK_AQUA));
|
||||
}
|
||||
Inventories.putIntoInventory("MINIGAMES", 8, Inventories.buildItems(Material.ENDER_PEARL, "inv_lobby_back", ChatColor.YELLOW));
|
||||
|
||||
if (Core.getMainClass().getConfig().getString("server-name").equals("lobby")) {
|
||||
Inventories.registerAction("MINIGAMES", 0, Inventories.Action.SERVER, "smash");
|
||||
Inventories.registerAction("MINIGAMES", 1, Inventories.Action.SERVER, "farmfight");
|
||||
Inventories.registerAction("MINIGAMES", 2, Inventories.Action.SERVER, "rocketmatch");
|
||||
Inventories.registerAction("MINIGAMES", 4, Inventories.Action.COMMAND, "toggleminigame xpbattle");
|
||||
Inventories.registerAction("MINIGAMES", 5, Inventories.Action.COMMAND, "aimthewater");
|
||||
} else {
|
||||
Inventories.registerAction("MINIGAMES", 0, Inventories.Action.SERVER, "smash");
|
||||
Inventories.registerAction("MINIGAMES", 3, Inventories.Action.SERVER, "farmfight");
|
||||
Inventories.registerAction("MINIGAMES", 6, Inventories.Action.SERVER, "rocketmatch");
|
||||
}
|
||||
Inventories.registerAction("MINIGAMES", 8, Inventories.Action.OPEN_INV, "GAMEMODES");
|
||||
|
||||
Inventories.registerInventory("LOBBY", "lobby_inv", ChatColor.DARK_BLUE);
|
||||
Inventories.putIntoInventory("LOBBY", 0, Inventories.buildItems(Material.SLIME_BALL, "inv_lobby_jump", ChatColor.DARK_GREEN));
|
||||
Inventories.putIntoInventory("LOBBY", 1, Inventories.buildItems(Material.WATER_BUCKET, "inv_lobby_swim", ChatColor.DARK_AQUA));
|
||||
Inventories.putIntoInventory("LOBBY", 3, Inventories.buildItems(Material.BOW, "inv_lobby_smash", ChatColor.GREEN));
|
||||
Inventories.putIntoInventory("LOBBY", 4, Inventories.buildItems(Material.WHEAT, "inv_lobby_farmfight", ChatColor.YELLOW));
|
||||
Inventories.putIntoInventory("LOBBY", 6, Inventories.buildItems(Material.WOOD_DOOR, "tp_to_spawn", ChatColor.GOLD));
|
||||
Inventories.putIntoInventory("LOBBY", 8, Inventories.buildItems(Material.ENDER_PEARL, "inv_lobby_back", ChatColor.YELLOW));
|
||||
|
||||
Inventories.registerAction("LOBBY", 0, Inventories.Action.COMMAND, "jumpinv");
|
||||
Inventories.registerAction("LOBBY", 1, Inventories.Action.TELEPORT, new Location(Bukkit.getWorld("lobby"), -289, 31, -1715));
|
||||
Inventories.registerAction("LOBBY", 3, Inventories.Action.TELEPORT, new Location(Bukkit.getWorld("lobby"), 64, 34, -1490));
|
||||
Inventories.registerAction("LOBBY", 4, Inventories.Action.TELEPORT, new Location(Bukkit.getWorld("lobby"), -106, 22, -1806));
|
||||
Inventories.registerAction("LOBBY", 6, Inventories.Action.COMMAND, "spawn");
|
||||
Inventories.registerAction("LOBBY", 8, Inventories.Action.OPEN_INV, "GAMEMODES");
|
||||
|
||||
Inventories.registerInventory("FEATURES", "features_inv", ChatColor.DARK_BLUE);
|
||||
Inventories.putIntoInventory("FEATURES", 2, Inventories.buildItems(Material.LEATHER_BOOTS, "inv_lobby_double_jump", ChatColor.DARK_AQUA));
|
||||
Inventories.putIntoInventory("FEATURES", 4, Inventories.buildItems(Material.BOAT, "inv_lobby_boat", ChatColor.DARK_AQUA));
|
||||
Inventories.registerAction("FEATURES", 2, Inventories.Action.COMMAND, "toggledbljump");
|
||||
Inventories.registerAction("FEATURES", 4, Inventories.Action.COMMAND, "toggleboat");
|
||||
|
||||
Inventories.registerInventory("LANGUAGE", "Select language", ChatColor.DARK_BLUE);
|
||||
int i = 0;
|
||||
for (String langu : AnuraCore.lang.languages.keySet()) {
|
||||
Inventories.putIntoInventory("LANGUAGE", i, Inventories.buildItems(Material.BOOK_AND_QUILL, Core.getMainClass().lang.languages.get(langu), ChatColor.DARK_GREEN, ChatColor.GOLD, "set_lang_to", Core.getMainClass().lang.languages.get(langu)));
|
||||
Inventories.registerAction("LANGUAGE", i, Inventories.Action.LANGUAGE, langu);
|
||||
i++;
|
||||
}
|
||||
|
||||
Inventories.buildInvItem("COMPASS", Material.COMPASS, "select_game", ChatColor.DARK_AQUA);
|
||||
Inventories.buildInvItem("SIGN", Material.SIGN, "Change language", ChatColor.DARK_GREEN);
|
||||
Inventories.buildInvItem("CHARGE", Material.FIREBALL, "features_item", ChatColor.BLUE);
|
||||
Inventories.buildInvItem("DOOR", Material.WOOD_DOOR, "tp_to_spawn", ChatColor.YELLOW);
|
||||
Inventories.buildInvItem("EYE", Material.EYE_OF_ENDER, "inv_to_lobby", ChatColor.YELLOW);
|
||||
if (Core.getMainClass().getConfig().getString("server-name").equals("lobby")) {
|
||||
Inventories.setItemInPlayerInv("COMPASS", 0);
|
||||
Inventories.setItemInPlayerInv("SIGN", 1);
|
||||
Inventories.setItemInPlayerInv("DOOR", 8);
|
||||
}
|
||||
Inventories.registerItemAction("COMPASS", Inventories.Action.OPEN_INV, "GAMEMODES");
|
||||
Inventories.registerItemAction("SIGN", Inventories.Action.OPEN_INV, "LANGUAGE");
|
||||
Inventories.registerItemAction("CHARGE", Inventories.Action.OPEN_INV, "FEATURES");
|
||||
Inventories.registerItemAction("DOOR", Inventories.Action.COMMAND, "spawn");
|
||||
Inventories.registerItemAction("EYE", Inventories.Action.SERVER, "lobby");
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setupXPBattle() {
|
||||
Scoreboard s = Bukkit.getScoreboardManager().getMainScoreboard();
|
||||
if (s.getObjective("xpBattleStart") == null) {
|
||||
s.registerNewObjective("xpBattleStart", "dummy");
|
||||
s.registerNewObjective("xpBattleJoin", "dummy");
|
||||
s.registerNewObjective("xpBattleEnd", "dummy");
|
||||
s.registerNewObjective("xpBattleIngame", "dummy");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,169 +0,0 @@
|
||||
package de.anura.core;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.sql.ResultSet;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
public class Signs implements PluginMessageListener {
|
||||
|
||||
public void updateServerSigns() {
|
||||
try {
|
||||
if (Bukkit.getOnlinePlayers().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT DISTINCT value FROM coreWarpSigns WHERE type = 'server' AND server = '" + Core.getMainClass().getConfig().getString("server-name") + "'");
|
||||
if (rs == null || !rs.first()) {
|
||||
return;
|
||||
}
|
||||
rs.beforeFirst();
|
||||
while (rs.next()) {
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(b);
|
||||
out.writeUTF("PlayerCount");
|
||||
out.writeUTF(rs.getString("value"));
|
||||
Bukkit.getOnlinePlayers().iterator().next().sendPluginMessage(Core.getMainClass(), "BungeeCord", b.toByteArray());
|
||||
ResultSet rs2 = Core.getMySql().querySelect("SELECT maxPlayers FROM coreServers WHERE name = LOWER('" + rs.getString("value") + "')");
|
||||
rs2.last();
|
||||
boolean online = true;
|
||||
int maxPlayers = 0;
|
||||
if (rs2.getRow() == 0) {
|
||||
online = false;
|
||||
} else {
|
||||
rs2.first();
|
||||
maxPlayers = rs2.getInt("maxPlayers");
|
||||
}
|
||||
final boolean onlineF = online;
|
||||
final int maxPlayersF = maxPlayers;
|
||||
rs2 = Core.getMySql().querySelect("SELECT X,Y,Z,world,info FROM coreWarpSigns WHERE type = 'server' AND server = '" + Core.getMainClass().getConfig().getString("server-name") + "' AND value = '" + rs.getString("value") + "'");
|
||||
rs2.last();
|
||||
if (rs2.getRow() == 0) {
|
||||
continue;
|
||||
}
|
||||
rs2.beforeFirst();
|
||||
while (rs2.next()) {
|
||||
Boolean remove = false;
|
||||
World w = Bukkit.getWorld(rs2.getString("world"));
|
||||
BlockState bs = null;
|
||||
if (w == null) {
|
||||
remove = true;
|
||||
} else {
|
||||
Block bl = w.getBlockAt(rs2.getInt("X"), rs2.getInt("Y"), rs2.getInt("Z"));
|
||||
if (bl == null || !(bl.getState() instanceof Sign)) {
|
||||
remove = true;
|
||||
} else {
|
||||
bs = bl.getState();
|
||||
}
|
||||
}
|
||||
if (remove) {
|
||||
String anotherSQL = "DELETE FROM coreWarpSigns WHERE server = '" + Core.getMainClass().getConfig().getString("server-name") + "' AND type = 'server' AND value = '" + rs.getString("value") + "'";
|
||||
Core.getMySql().queryUpdate(anotherSQL);
|
||||
continue;
|
||||
}
|
||||
if (bs == null) {
|
||||
continue;
|
||||
}
|
||||
final Sign s = (Sign) bs;
|
||||
final String rest = s.getLine(1).substring(0, s.getLine(1).length() - 2);
|
||||
final String info = rs2.getString("info");
|
||||
Bukkit.getScheduler().runTask(AnuraCore.getInstance(), () -> {
|
||||
if (!onlineF) {
|
||||
s.setLine(1, ChatColor.RED + "--" + ChatColor.DARK_GRAY + "/" + ChatColor.RED + "--");
|
||||
s.setLine(3, ChatColor.RED + "Offline");
|
||||
s.update();
|
||||
return;
|
||||
}
|
||||
s.setLine(1, rest + maxPlayersF);
|
||||
s.setLine(3, info);
|
||||
s.update();
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||
try {
|
||||
if (!channel.equals("BungeeCord")) {
|
||||
return;
|
||||
}
|
||||
|
||||
DataInputStream in = new DataInputStream(new ByteArrayInputStream(message));
|
||||
String subchannel = in.readUTF();
|
||||
switch (subchannel) {
|
||||
case "PlayerCount":
|
||||
String server = in.readUTF();
|
||||
int playercount = in.readInt();
|
||||
String sqlQ = "SELECT X,Y,Z,world FROM coreWarpSigns WHERE server = '" + Core.getMainClass().getConfig().getString("server-name") + "' AND type = 'server' AND value = '" + server + "'";
|
||||
ResultSet rs = Core.getMySql().querySelect(sqlQ);
|
||||
rs.last();
|
||||
if (rs.getRow() == 0) {
|
||||
return;
|
||||
} rs.beforeFirst();
|
||||
while (rs.next()) {
|
||||
Boolean remove = false;
|
||||
World w = Bukkit.getWorld(rs.getString("world"));
|
||||
BlockState bs = null;
|
||||
if (w == null) {
|
||||
remove = true;
|
||||
} else {
|
||||
Block b = w.getBlockAt(rs.getInt("X"), rs.getInt("Y"), rs.getInt("Z"));
|
||||
if (b == null || !(b.getState() instanceof Sign)) {
|
||||
remove = true;
|
||||
} else {
|
||||
bs = b.getState();
|
||||
}
|
||||
}
|
||||
if (remove) {
|
||||
String anotherSQL = "DELETE FROM coreWarpSigns WHERE server = '" + Core.getMainClass().getConfig().getString("server-name") + "' AND type = 'server' AND value = '" + server + "'";
|
||||
Core.getMySql().queryUpdate(anotherSQL);
|
||||
continue;
|
||||
}
|
||||
if (bs == null) {
|
||||
continue;
|
||||
}
|
||||
if (bs instanceof Sign) {
|
||||
Sign s = (Sign) bs;
|
||||
if (s.getLine(3).equalsIgnoreCase(ChatColor.RED + "Offline")) {
|
||||
s.setLine(1, ChatColor.RED + "--" + ChatColor.DARK_GRAY + "/" + ChatColor.RED + "--");
|
||||
continue;
|
||||
}
|
||||
String maxplayers = s.getLine(1).substring(s.getLine(1).length() - 2);
|
||||
Boolean hasPlace = true;
|
||||
if (maxplayers.equals("--")) {
|
||||
hasPlace = true;
|
||||
} else if (Integer.parseInt(maxplayers) == playercount) {
|
||||
hasPlace = false;
|
||||
}
|
||||
if (hasPlace) {
|
||||
s.setLine(1, ChatColor.GREEN + String.valueOf(playercount) + ChatColor.DARK_GRAY + "/" + ChatColor.GREEN + maxplayers);
|
||||
} else {
|
||||
s.setLine(1, ChatColor.RED + String.valueOf(playercount) + ChatColor.DARK_GRAY + "/" + ChatColor.GREEN + maxplayers);
|
||||
}
|
||||
s.update();
|
||||
}
|
||||
} break;
|
||||
case "updatePermissions":
|
||||
AnuraCore.perms.reload();
|
||||
AnuraCore.perms.updateAllPlayers();
|
||||
break;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package de.anura.core;
|
||||
|
||||
import de.anura.core.API.Errors;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.util.HashMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
public class Teleports implements PluginMessageListener {
|
||||
|
||||
public final static HashMap<String, Location> queuedLocs = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] bytes) {
|
||||
try {
|
||||
if (!channel.equalsIgnoreCase("BungeeCord")) {
|
||||
return;
|
||||
}
|
||||
DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
|
||||
String subchannel = in.readUTF();
|
||||
if (subchannel.equalsIgnoreCase("teleport")) {
|
||||
String subsubChannel = in.readUTF();
|
||||
switch (subsubChannel) {
|
||||
case "player":
|
||||
String p = in.readUTF();
|
||||
String tar = in.readUTF();
|
||||
Player P = Bukkit.getPlayer(p);
|
||||
Player target = Bukkit.getPlayer(tar);
|
||||
if (target == null) return;
|
||||
if (P == null) {
|
||||
queuedLocs.put(p, target.getLocation());
|
||||
return;
|
||||
}
|
||||
P.teleport(target);
|
||||
break;
|
||||
case "coords":
|
||||
String p2 = in.readUTF();
|
||||
int x = in.readInt();
|
||||
int y = in.readInt();
|
||||
int z = in.readInt();
|
||||
Player P2 = Bukkit.getPlayer(p2);
|
||||
String mode = in.readUTF();
|
||||
Location loc;
|
||||
if (mode.equalsIgnoreCase("main-world")) {
|
||||
loc = new Location(Bukkit.getWorlds().get(0), x, y, z);
|
||||
} else {
|
||||
loc = new Location(P2.getWorld(), x, y, z);
|
||||
}
|
||||
if (P2 == null) {
|
||||
queuedLocs.put(p2, loc);
|
||||
} else {
|
||||
P2.teleport(loc);
|
||||
}
|
||||
break;
|
||||
case "worldcoords":
|
||||
String p3 = in.readUTF();
|
||||
int X = in.readInt();
|
||||
int Y = in.readInt();
|
||||
int Z = in.readInt();
|
||||
Player P3 = Bukkit.getPlayer(p3);
|
||||
String world = in.readUTF();
|
||||
World w = Bukkit.getWorld(world);
|
||||
if (w == null) return;
|
||||
Location l = new Location(w, X, Y, Z);
|
||||
if (P3 == null) {
|
||||
queuedLocs.put(p3, l);
|
||||
} else {
|
||||
P3.teleport(l);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Errors.reportException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package de.anura.core;
|
||||
|
||||
public class VillagerTask implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (AnuraVillager av : AnuraVillager.villagers.values()) {
|
||||
av.tp();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
package de.anura.core.commands;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.API.Tools;
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.AnuraVillager;
|
||||
import de.anura.core.AnuraVillager.VillagerType;
|
||||
import de.anura.core.Features.Feature;
|
||||
import de.anura.core.LanguageSupport;
|
||||
import de.anura.core.util.Data;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
|
||||
public class AdminCommands implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||
try {
|
||||
Player P = null;
|
||||
if (sender instanceof Player) {
|
||||
P = (Player) sender;
|
||||
}
|
||||
if (cmd.getName().equalsIgnoreCase("clearArrows")) {
|
||||
if (P == null) {
|
||||
Core.statusMsg(sender, "only_player_cmd", false);
|
||||
return true;
|
||||
}
|
||||
if (!sender.hasPermission("core.commands.cleararrows")) {
|
||||
Core.statusMsg(sender, "no_perms", false);
|
||||
return true;
|
||||
}
|
||||
for (Player pl : Data.sittingPlayer.keySet()) {
|
||||
Core.endSitting(pl);
|
||||
}
|
||||
for (Arrow a : P.getWorld().getEntitiesByClass(Arrow.class)) {
|
||||
a.remove();
|
||||
}
|
||||
Tools.sendStatusMsg(sender, "Done!", true);
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("core")) {
|
||||
if (!sender.hasPermission("core.commands.core")) {
|
||||
Core.statusMsg(sender, "no_perms", false);
|
||||
return true;
|
||||
}
|
||||
if (args.length != 1) {
|
||||
Core.statusMsg(sender, "wrong_args_count", false);
|
||||
return false;
|
||||
}
|
||||
if ((args[0].equalsIgnoreCase("reload") || args[0].equalsIgnoreCase("rl")) && sender.isOp()) {
|
||||
try {
|
||||
Core.getMainClass().getConfig().load(new File("plugins/Core/", "config.yml"));
|
||||
AnuraCore.lang = new LanguageSupport();
|
||||
Core.statusMsg(sender, "config_rl_done", true);
|
||||
} catch (IOException ex) {
|
||||
Core.statusMsg(sender, "config_rl_error_io", false);
|
||||
} catch (InvalidConfigurationException ex) {
|
||||
Core.statusMsg(sender, "config_rl_invalid", false);
|
||||
}
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("save") && sender.isOp()) {
|
||||
try {
|
||||
Core.getMainClass().getConfig().save(new File("plugins/Core/", "config.yml"));
|
||||
Core.statusMsg(sender, "config_save", true);
|
||||
} catch (IOException ex) {
|
||||
Core.statusMsg(sender, "config_save_io_err", false);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("debugclosemysql") && sender.isOp()) {
|
||||
Core.getMySql().closeConnection();
|
||||
Core.statusMsg(sender, "debug_mysql_closed", true);
|
||||
return true;
|
||||
}
|
||||
} else if (cmd.getName().equalsIgnoreCase("setspawn")) {
|
||||
if (P != null && P.hasPermission("core.commands.setspawn")) {
|
||||
Location l = P.getLocation();
|
||||
l.getWorld().setSpawnLocation((int) l.getX(), (int) l.getY(), (int) l.getZ());
|
||||
FileConfiguration c = Core.getMainClass().getConfig();
|
||||
c.set("spawn.X", l.getX());
|
||||
c.set("spawn.Y", l.getY());
|
||||
c.set("spawn.Z", l.getZ());
|
||||
c.set("spawn.yaw", (double)l.getYaw());
|
||||
c.set("spawn.pitch", (double)l.getPitch());
|
||||
c.set("spawn.world", l.getWorld().getName());
|
||||
Core.getMainClass().saveConfig();
|
||||
Core.statusMsg(P, "spawn_set", true);
|
||||
return true;
|
||||
}
|
||||
} else if (cmd.getName().equalsIgnoreCase("villager")) {
|
||||
if (P == null) {
|
||||
sender.sendMessage("Du bist kein Spieler!");
|
||||
return true;
|
||||
}
|
||||
if (!(P.hasPermission("core.commands.villager"))) {
|
||||
Core.statusMsg(P, "no_perms", false);
|
||||
return true;
|
||||
}
|
||||
if (args.length < 1) return false;
|
||||
if (args[0].equalsIgnoreCase("create")) {
|
||||
if (args.length < 2) return false;
|
||||
Feature f;
|
||||
try {
|
||||
f = Feature.valueOf(args[1].toUpperCase());
|
||||
} catch(IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
if (f == null) return false;
|
||||
if (AnuraVillager.getByType(VillagerType.getByFeature(f)) != null) {
|
||||
P.sendMessage("Es existiert bereits ein Villager diesen Types!");
|
||||
return true;
|
||||
}
|
||||
new AnuraVillager(VillagerType.getByFeature(f)).spawn(P.getLocation());
|
||||
P.sendMessage("Villager erfolgreich gespawnt!");
|
||||
} else if (args[0].equalsIgnoreCase("remove")) {
|
||||
for (Entity e : P.getNearbyEntities(1, 1, 1)) {
|
||||
if (e instanceof Villager) {
|
||||
Villager v = (Villager) e;
|
||||
if (AnuraVillager.getByEntity(v) == null) continue;
|
||||
AnuraVillager.getByEntity(v).remove();
|
||||
v.remove();
|
||||
P.sendMessage("Villager erfolgreich entfernt!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
P.sendMessage("Kein Anura-Villager gefunden!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
54
src/de/anura/core/commands/Answer.java
Normal file
54
src/de/anura/core/commands/Answer.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package de.anura.core.commands;
|
||||
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.msg.Messenger;
|
||||
import de.anura.core.msg.Msg;
|
||||
import de.anura.core.msg.Msg.MsgType;
|
||||
import de.anura.core.util.UUIDManager;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Answer implements CommandExecutor {
|
||||
|
||||
public static Map<Player, UUID> chatPartners = new WeakHashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||
if (!(sender instanceof Player)) return true;
|
||||
Player P = (Player) sender;
|
||||
if (!chatPartners.containsKey(P)) {
|
||||
Msg.send(P, AnuraCore.getInstance(), MsgType.INFO, "Starte eine Konversation mit /msg");
|
||||
return true;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
Msg.send(P, AnuraCore.getInstance(), MsgType.ERROR, "Gib eine Nachricht an!");
|
||||
return true;
|
||||
}
|
||||
String s = "";
|
||||
for (String st : args) {
|
||||
s += st + " ";
|
||||
}
|
||||
String msg = s;
|
||||
UUID partner = chatPartners.get(P);
|
||||
boolean sent = Messenger.receiveMsg(P.getUniqueId(), partner, msg);
|
||||
Player p2 = Bukkit.getPlayer(partner);
|
||||
if (p2 == null) {
|
||||
UUIDManager.getName(partner, (name) -> send(P, sent, name, msg));
|
||||
} else {
|
||||
send(P, sent, p2.getDisplayName(), msg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void send(Player P, boolean sent, String name, String msg) {
|
||||
P.sendMessage(P.getDisplayName() + ChatColor.GRAY + " -> " + name + ChatColor.GRAY + ": " + ChatColor.RESET + msg);
|
||||
if (!sent) Msg.send(P, AnuraCore.getInstance(), MsgType.INFO, "(Noch nicht zugestellt, Spieler ist nicht mehr online, Nachricht wird in seine Mailbox verschoben)");
|
||||
}
|
||||
}
|
||||
44
src/de/anura/core/commands/GameMode.java
Normal file
44
src/de/anura/core/commands/GameMode.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package de.anura.core.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class GameMode implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||
|
||||
if (args.length < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission("core.commands.gm")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = (sender instanceof Player) ? (Player) sender : null;
|
||||
if (player == null) {
|
||||
if (args.length < 2) {
|
||||
return false;
|
||||
}
|
||||
player = Bukkit.getPlayerExact(args[1]);
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
org.bukkit.GameMode mode = org.bukkit.GameMode.getByValue(Integer.parseInt(args[0]));
|
||||
|
||||
if (mode != null) {
|
||||
player.setGameMode(mode);
|
||||
return true;
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
81
src/de/anura/core/commands/MessageCmd.java
Normal file
81
src/de/anura/core/commands/MessageCmd.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package de.anura.core.commands;
|
||||
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.msg.Messenger;
|
||||
import de.anura.core.msg.Msg;
|
||||
import de.anura.core.msg.Msg.MsgType;
|
||||
import de.anura.core.util.UUIDManager;
|
||||
import de.anura.core.util.Util;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class MessageCmd implements CommandExecutor, TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
}
|
||||
if (!(sender instanceof Player)) return true;
|
||||
Player P = (Player) sender;
|
||||
if (args[0].equalsIgnoreCase("read")) {
|
||||
int page = 1;
|
||||
if (args.length > 1 && Util.isInteger(args[1])) page = Integer.parseInt(args[1]);
|
||||
Messenger.readMsgs(P, true, page);
|
||||
} else if (args[0].equalsIgnoreCase("list")) {
|
||||
int page = 1;
|
||||
if (args.length > 1 && Util.isInteger(args[1])) page = Integer.parseInt(args[1]);
|
||||
Messenger.readMsgs(P, false, page);
|
||||
} else if (args[0].equalsIgnoreCase("delete")) {
|
||||
Messenger.deleteMsgs(P);
|
||||
} else if (args.length == 1) {
|
||||
Msg.send(sender, AnuraCore.getInstance(), MsgType.ERROR, "Gib eine Nachricht an!");
|
||||
} else {
|
||||
String player = args[0];
|
||||
UUIDManager.getUUID(player, true, (uuid) -> {
|
||||
if (uuid == null) {
|
||||
Msg.send(sender, AnuraCore.getInstance(), MsgType.ERROR, "Spieler nicht gefunden!");
|
||||
return;
|
||||
}
|
||||
String s = "";
|
||||
for (String st : Arrays.copyOfRange(args, 1, args.length)) {
|
||||
s += st + " ";
|
||||
}
|
||||
String display = P.getDisplayName();
|
||||
boolean sent = Messenger.receiveMsg(P.getUniqueId(), uuid, s);
|
||||
Player p2 = Bukkit.getPlayer(uuid);
|
||||
P.sendMessage(display + ChatColor.GRAY + " -> " + (p2 == null ? player : p2.getDisplayName()) + ChatColor.GRAY + ": " + ChatColor.RESET + s);
|
||||
if (!sent) Msg.send(P, AnuraCore.getInstance(), MsgType.INFO, "(Noch nicht zugestellt, Spieler ist nicht online, Nachricht wird in seine Mailbox verschoben)");
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String whatever, String[] args) {
|
||||
List<String> matches = new ArrayList<>();
|
||||
if (args.length != 1) {
|
||||
return matches;
|
||||
}
|
||||
String search = args[0].toLowerCase();
|
||||
if ("read".startsWith(search)) {
|
||||
matches.add("read");
|
||||
}
|
||||
if ("list".startsWith(search)) {
|
||||
matches.add("list");
|
||||
}
|
||||
if ("delete".startsWith(search)) {
|
||||
matches.add("delete");
|
||||
}
|
||||
Bukkit.getOnlinePlayers().stream().map((player) -> player.getName()).filter((name) -> (name != null && name.toLowerCase().startsWith(search))).forEach(matches::add);
|
||||
return matches;
|
||||
}
|
||||
}
|
||||
90
src/de/anura/core/commands/MoneyCmd.java
Normal file
90
src/de/anura/core/commands/MoneyCmd.java
Normal file
@@ -0,0 +1,90 @@
|
||||
package de.anura.core.commands;
|
||||
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.Money;
|
||||
import de.anura.core.msg.Msg;
|
||||
import de.anura.core.msg.Msg.MsgType;
|
||||
import de.anura.core.util.UUIDManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class MoneyCmd implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("null")
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||
Player P = (sender instanceof Player) ? (Player) sender : null;
|
||||
|
||||
if (args.length == 0) {
|
||||
if (P == null) {
|
||||
Msg.send(sender, AnuraCore.getInstance(), MsgType.ERROR, "Dieser Befehl ist nur für Spieler!");
|
||||
return true;
|
||||
}
|
||||
Money.getMoney(P.getUniqueId(), (money) -> {
|
||||
Msg.send(P, AnuraCore.getInstance(), MsgType.SUCCESS, "Du hast %m", money);
|
||||
});
|
||||
return true;
|
||||
} else if ((args[0].equalsIgnoreCase("pay") || args[0].equalsIgnoreCase("send")) && (args.length == 3)) {
|
||||
Integer money;
|
||||
try {
|
||||
money = Integer.parseInt(args[2]);
|
||||
} catch (NumberFormatException ex) {
|
||||
Msg.send(P, AnuraCore.getInstance(), MsgType.ERROR, "Das Geld muss eine Zahl sein!");
|
||||
return true;
|
||||
}
|
||||
|
||||
String name = args[1];
|
||||
|
||||
Runnable payAction = () -> {
|
||||
UUIDManager.getUUID(name, true, (uuid2) -> {
|
||||
if (uuid2 == null) {
|
||||
Msg.send(P, AnuraCore.getInstance(), MsgType.ERROR, "Dieser Spieler ist unbekannt!");
|
||||
return;
|
||||
}
|
||||
Money.getMoney(uuid2, (money2) -> {
|
||||
if (money2 != -1) {
|
||||
Money.payMoney(uuid2, money);
|
||||
if (P != null && !P.hasPermission("core.money.endless")) {
|
||||
Money.payMoney(P.getUniqueId(), -money);
|
||||
}
|
||||
Player targetP = Bukkit.getPlayer(uuid2);
|
||||
String target = (targetP == null) ? name : targetP.getDisplayName();
|
||||
Msg.send(P, AnuraCore.getInstance(), MsgType.SUCCESS, "Du hast %s %m überwiesen!", target, money);
|
||||
Msg.send(uuid2, AnuraCore.getInstance(), MsgType.SUCCESS, "%s hat dir %m überwiesen!", (P != null) ? P.getDisplayName() : sender.getName(), money);
|
||||
} else {
|
||||
Msg.send(P, AnuraCore.getInstance(), MsgType.ERROR, "Ein Fehler ist aufgetreten");
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
if (sender.hasPermission("core.money.endless")) {
|
||||
payAction.run();
|
||||
} else {
|
||||
if (P == null || P.getName() == null) {
|
||||
Msg.send(P, AnuraCore.getInstance(), MsgType.ERROR, "Dieser Befehl ist nur für Spieler!");
|
||||
return true;
|
||||
}
|
||||
if (P.getName().equals(args[1])) {
|
||||
Msg.send(P, AnuraCore.getInstance(), MsgType.ERROR, "Du kannst dir nicht selbst Geld überweisen!");
|
||||
return true;
|
||||
}
|
||||
if (money <= 0) {
|
||||
Msg.send(P, AnuraCore.getInstance(), MsgType.ERROR, "Du musst einen positiven Wert angeben!");
|
||||
return true;
|
||||
}
|
||||
Money.getMoney(P.getUniqueId(), (currentMoney) -> {
|
||||
if (currentMoney < money) {
|
||||
Msg.send(P, AnuraCore.getInstance(), MsgType.ERROR, "Du hast nicht genug Geld!");
|
||||
} else {
|
||||
payAction.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package de.anura.core.commands;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.API.Inventories;
|
||||
import de.anura.core.API.Tools;
|
||||
import de.anura.core.util.Data;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class OtherCommands implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||
try {
|
||||
Player P = null;
|
||||
if (sender instanceof Player) {
|
||||
P = (Player) sender;
|
||||
}
|
||||
if (cmd.getName().equalsIgnoreCase("togglecommands")) {
|
||||
if (!(sender instanceof BlockCommandSender) && !(sender instanceof ConsoleCommandSender)) {
|
||||
Tools.sendStatusMsg(sender, "Only command block cmd!", false);
|
||||
return true;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
return false;
|
||||
}
|
||||
String action = args[1];
|
||||
if (!action.equals("disable") && !action.equals("enable")) {
|
||||
return true;
|
||||
}
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(args[0]);
|
||||
if (!op.isOnline()) {
|
||||
return true;
|
||||
}
|
||||
Boolean b = action.equals("disable");
|
||||
Data.disableCommandsAdventure.put(op.getPlayer(), b);
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("none")) {
|
||||
Core.statusMsg(sender, "cmd_not_found", false);
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("addAimTWWin")) {
|
||||
if (!(sender instanceof BlockCommandSender) && !(sender instanceof ConsoleCommandSender)) {
|
||||
Tools.sendStatusMsg(sender, "Only command block cmd!", false);
|
||||
return true;
|
||||
}
|
||||
if (args.length != 1) return false;
|
||||
String p = args[0];
|
||||
if (Bukkit.getOfflinePlayer(p).isOnline()) {
|
||||
Player player = Bukkit.getPlayer(p);
|
||||
Data.aimTheWaterWins.put(player, Data.aimTheWaterWins.get(player) + 1);
|
||||
return true;
|
||||
}
|
||||
} else if (cmd.getName().equalsIgnoreCase("addInvItems")) {
|
||||
Player pl;
|
||||
if (args.length == 0) {
|
||||
if (P == null) return true;
|
||||
pl = P;
|
||||
} else if (sender.hasPermission("core.addinvitems.other")) {
|
||||
if (!Bukkit.getOfflinePlayer(args[0]).isOnline()) return true;
|
||||
pl = Bukkit.getPlayer(args[0]);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
Inventories.addInvItems(pl);
|
||||
return true;
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,323 +1,97 @@
|
||||
package de.anura.core.commands;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.API.Money;
|
||||
import de.anura.core.API.Tools;
|
||||
import de.anura.core.Features;
|
||||
import java.sql.ResultSet;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
|
||||
public class PlayerCommands implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
|
||||
try {
|
||||
Player P = null;
|
||||
if (sender instanceof Player) {
|
||||
P = (Player) sender;
|
||||
}
|
||||
if (cmd.getName().equalsIgnoreCase("toggledbljump")) {
|
||||
if (P == null) {
|
||||
Core.statusMsg(sender, "only_player_cmd", false);
|
||||
return true;
|
||||
}
|
||||
if (P.getAllowFlight()) {
|
||||
Core.getMainClass().getFeatures().disableFeature(P, Features.Feature.DOUBLE_JUMP);
|
||||
} else {
|
||||
Core.getMainClass().getFeatures().enableFeature(P, Features.Feature.DOUBLE_JUMP);
|
||||
}
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("toggleboat")) {
|
||||
if (P == null) {
|
||||
Core.statusMsg(sender, "only_player_cmd", false);
|
||||
return true;
|
||||
}
|
||||
if (Core.getMainClass().getFeatures().hasFeature(P, Features.Feature.BOAT) && Core.getMainClass().getFeatures().featureEnabled.get(P).get(Features.Feature.BOAT)) {
|
||||
Core.getMainClass().getFeatures().disableFeature(P, Features.Feature.BOAT);
|
||||
} else {
|
||||
Core.getMainClass().getFeatures().enableFeature(P, Features.Feature.BOAT);
|
||||
}
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("bug")) {
|
||||
if (P == null) {
|
||||
Core.statusMsg(sender, "only_player_cmd", false);
|
||||
return true;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
}
|
||||
String msg = "";
|
||||
for (String part : args) {
|
||||
msg += part + " ";
|
||||
}
|
||||
Errors.bugReport(P, msg, Errors.make("plugin", "core"));
|
||||
Core.statusMsg(P, "bug_report_sent", true);
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("joinminigame")) {
|
||||
if (P == null) {
|
||||
Core.statusMsg(sender, "only_player_cmd", false);
|
||||
return true;
|
||||
}
|
||||
if (args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("xpbattle")) {
|
||||
Objective o = Bukkit.getScoreboardManager().getMainScoreboard().getObjective("xpBattleJoin");
|
||||
if (o == null) {
|
||||
return true;
|
||||
}
|
||||
o.getScore(P).setScore(1);
|
||||
Core.statusMsg(sender, "joined_xpBattle", true);
|
||||
return true;
|
||||
}
|
||||
} else if (cmd.getName().equalsIgnoreCase("leaveminigame")) {
|
||||
if (P == null) {
|
||||
Core.statusMsg(sender, "only_player_cmd", false);
|
||||
return true;
|
||||
}
|
||||
if (args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("xpbattle")) {
|
||||
Objective o = Bukkit.getScoreboardManager().getMainScoreboard().getObjective("xpBattleJoin");
|
||||
if (o == null) {
|
||||
return true;
|
||||
}
|
||||
o.getScore(P).setScore(0);
|
||||
Core.statusMsg(sender, "left_xpBattle", true);
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("pool")) {
|
||||
Objective o = Bukkit.getScoreboardManager().getMainScoreboard().getObjective("poolJoin");
|
||||
if (o == null) {
|
||||
return true;
|
||||
}
|
||||
o.getScore(P).setScore(0);
|
||||
Core.statusMsg(sender, "left_pool", true);
|
||||
return true;
|
||||
}
|
||||
} else if (cmd.getName().equalsIgnoreCase("toggleminigame")) {
|
||||
if (P == null) {
|
||||
Core.statusMsg(sender, "only_player_cmd", false);
|
||||
return true;
|
||||
}
|
||||
if (args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("xpbattle")) {
|
||||
Objective o = Bukkit.getScoreboardManager().getMainScoreboard().getObjective("xpBattleJoin");
|
||||
if (o == null) {
|
||||
return true;
|
||||
}
|
||||
if (o.getScore(P).getScore() == 0) {
|
||||
Bukkit.dispatchCommand(sender, "joinminigame xpBattle");
|
||||
return true;
|
||||
} else {
|
||||
Bukkit.dispatchCommand(sender, "leaveminigame xpBattle");
|
||||
return true;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("pool")) {
|
||||
Objective o = Bukkit.getScoreboardManager().getMainScoreboard().getObjective("poolJoin");
|
||||
if (o == null) {
|
||||
return true;
|
||||
}
|
||||
if (o.getScore(P).getScore() == 0) {
|
||||
Bukkit.dispatchCommand(sender, "joinminigame pool");
|
||||
return true;
|
||||
} else {
|
||||
Bukkit.dispatchCommand(sender, "leaveminigame pool");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (cmd.getName().equalsIgnoreCase("hilfe")) {
|
||||
if (!cmdLabel.equals("hilfe") && !cmdLabel.equals("help") && !cmdLabel.equals("?")) {
|
||||
cmdLabel = "hilfe";
|
||||
}
|
||||
if (sender.hasPermission("core.commands.help")) {
|
||||
sender.sendMessage(ChatColor.RED + "Achtung: " + ChatColor.YELLOW + "Die echte Hilfe gibts mit " + ChatColor.BLUE + "/?" + ChatColor.YELLOW + "!");
|
||||
}
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "-----------" + ChatColor.AQUA + "Hilfe" + ChatColor.YELLOW + "-----------");
|
||||
sender.sendMessage(ChatColor.GREEN + "Hilfe zu den Befehlen gibt es mit " + ChatColor.BLUE + "/" + cmdLabel + " commands");
|
||||
sender.sendMessage(ChatColor.GOLD + "Informationen zu unseren GameModes erhälst du mit " + ChatColor.BLUE + "/" + cmdLabel + " gamemodes");
|
||||
} else if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("commands")) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "-----------" + ChatColor.AQUA + "Befehle" + ChatColor.YELLOW + "-----------");
|
||||
sender.sendMessage(ChatColor.BLUE + "/lobby " + ChatColor.GREEN + "Bringt dich jederzeit zurück zur Lobby.");
|
||||
sender.sendMessage(ChatColor.BLUE + "/spawn " + ChatColor.GOLD + "Teleportiert dich zum Spawn.");
|
||||
sender.sendMessage(ChatColor.BLUE + "/money " + ChatColor.GREEN + "Zeigt dein Geld an.");
|
||||
sender.sendMessage(ChatColor.RED + "Befehle für den Smash-Gamemode siehst du mit " + ChatColor.BLUE + "/" + cmdLabel + " commands smash");
|
||||
} else if (args[0].equalsIgnoreCase("gamemodes")) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "-----------" + ChatColor.AQUA + "Gamemodes" + ChatColor.YELLOW + "-----------");
|
||||
sender.sendMessage(ChatColor.GRAY + "----------" + ChatColor.GREEN + "Smash PvP" + ChatColor.GRAY + "-----------");
|
||||
sender.sendMessage(ChatColor.BLUE + "In Smash PvP geht es darum, mithilfe von verschiedenen Klassen deine "
|
||||
+ "Gegner ins Wasser, in die Lava oder aus der Welt zu schlagen. "
|
||||
+ "Du kannst verschiedenen Arenen beitreten. Es gibt keine Begrenzung, wie "
|
||||
+ "lange du spielen kannst. Jeder Kill gibt dir Münzen. Stirbst du, verlierst du "
|
||||
+ "eine Münze.");
|
||||
sender.sendMessage(ChatColor.GOLD + "Mit " + ChatColor.RED + "/" + cmdLabel + " commands smash" + ChatColor.GOLD + " kannst du dir");
|
||||
sender.sendMessage(ChatColor.GOLD + "alle Befehle des Minigames anzeigen lassen.");
|
||||
}
|
||||
} else if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("commands") && args[1].equalsIgnoreCase("smash")) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "-----------" + ChatColor.AQUA + "Smash Befehle" + ChatColor.YELLOW + "-----------");
|
||||
sender.sendMessage(ChatColor.BLUE + "/join <Arena> " + ChatColor.GREEN + "Hiermit kannst du einem Smash Game beitreten.");
|
||||
sender.sendMessage(ChatColor.BLUE + "/leave " + ChatColor.GREEN + "Lässt dich ein Spiel verlassen.");
|
||||
sender.sendMessage(ChatColor.BLUE + "/class " + ChatColor.GREEN + "Damit kannst du während eines Spiels die Klasse wechseln.");
|
||||
sender.sendMessage(ChatColor.BLUE + "/classes " + ChatColor.GREEN + "Teleportiert dich in einen Raum, in dem du Klassen kaufen kannst.");
|
||||
sender.sendMessage(ChatColor.BLUE + "/bug <Beschreibung> " + ChatColor.GREEN + "Wenn du einen Bug gefunden hast, kannst du ihn so reporten.");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("spawn")) {
|
||||
if (args.length == 1) {
|
||||
if (sender.hasPermission("core.commands.spawn-other") || sender instanceof BlockCommandSender) {
|
||||
if (Bukkit.getOfflinePlayer(args[0]).isOnline()) {
|
||||
P = Bukkit.getPlayer(args[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (P == null) {
|
||||
Core.statusMsg(sender, "only_player_cmd", false);
|
||||
return true;
|
||||
}
|
||||
Core.toSpawn(P);
|
||||
Core.statusMsg(P, "spawn_tp_done", true);
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("warp")) {
|
||||
if (args.length == 0 || args.length > 2) {
|
||||
Core.statusMsg(P, "wrong_args_count", false);
|
||||
return false;
|
||||
}
|
||||
if (P == null) {
|
||||
if (args.length != 2) {
|
||||
Core.statusMsg(P, "wrong_args_count", false);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
if (args.length == 2) {
|
||||
String p = args[1];
|
||||
if (!Bukkit.getOfflinePlayer(p).isOnline()) {
|
||||
Core.statusMsg(P, "player_not_online", false);
|
||||
return false;
|
||||
}
|
||||
P = Bukkit.getPlayer(p);
|
||||
}
|
||||
String warpName = args[0];
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT world, X, Y, Z, userWarp, server FROM coreWarps WHERE name = '" + warpName + "'");
|
||||
rs.last();
|
||||
if (rs.getRow() == 0) {
|
||||
Core.statusMsg(P, "warp_not_exist", false);
|
||||
return true;
|
||||
}
|
||||
rs.first();
|
||||
if (P == null) {
|
||||
return false;
|
||||
}
|
||||
if (!rs.getBoolean("userWarp") && !P.hasPermission("core.commands.adminWarp")) {
|
||||
Core.statusMsg(P, "no_perms", false);
|
||||
return true;
|
||||
}
|
||||
int X = rs.getInt("X");
|
||||
int Y = rs.getInt("Y");
|
||||
int Z = rs.getInt("Z");
|
||||
String server = rs.getString("server");
|
||||
String world = rs.getString("world");
|
||||
if (!server.equals(Core.getMainClass().getConfig().getString("server-name"))) {
|
||||
Core.statusMsg(P, "warp_other_server", false);
|
||||
return true;
|
||||
}
|
||||
World w = Bukkit.getWorld(world);
|
||||
if (w == null) {
|
||||
Core.statusMsg(P, "warp_not_avail", false);
|
||||
return true;
|
||||
}
|
||||
Location loc = new Location(w, X, Y, Z);
|
||||
P.teleport(loc);
|
||||
Core.statusMsg(P, "warp_tp_done", true);
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("money")) {
|
||||
if (args.length == 0) {
|
||||
if (P == null) {
|
||||
Tools.sendStatusMsg(sender, "only_player_cmd", false);
|
||||
return true;
|
||||
}
|
||||
Integer money = Money.getMoney(P);
|
||||
Tools.sendStatusMsg(P, Core.getl("you_have", P) + " " + money + " " + Core.getl("coins", P), true);
|
||||
return true;
|
||||
} else if ((args[0].equalsIgnoreCase("pay")) && (args.length == 3)) {
|
||||
Integer money = Integer.parseInt(args[2]);
|
||||
boolean canPay;
|
||||
Integer geld = 0;
|
||||
if (sender.hasPermission("core.money.endless")) {
|
||||
if (P != null) {
|
||||
canPay = P.hasPermission("core.money.endless");
|
||||
} else {
|
||||
canPay = true;
|
||||
}
|
||||
} else {
|
||||
if (P == null) {
|
||||
Core.statusMsg(sender, "only_player_cmd", false);
|
||||
return true;
|
||||
}
|
||||
if (P.getName().equals(args[1])) {
|
||||
Core.statusMsg(P, "money_pay_yourself", false);
|
||||
return true;
|
||||
}
|
||||
if (!(money > 0)) {
|
||||
Core.statusMsg(P, "number_must_positive", false);
|
||||
return true;
|
||||
}
|
||||
int currentMoney = Money.getMoney(P);
|
||||
if (currentMoney < money) {
|
||||
Core.statusMsg(P, "not_enough_money", false);
|
||||
canPay = false;
|
||||
} else {
|
||||
geld = currentMoney;
|
||||
canPay = true;
|
||||
}
|
||||
}
|
||||
if (canPay) {
|
||||
OfflinePlayer oP = Bukkit.getOfflinePlayer(args[1]);
|
||||
if (!oP.hasPlayedBefore() && !oP.isOnline()) {
|
||||
Core.statusMsg(P, "never_seen_player", false);
|
||||
return true;
|
||||
}
|
||||
int currentMoney2 = Money.getMoney(oP);
|
||||
if (currentMoney2 != -1) {
|
||||
Money.payMoney(oP, money);
|
||||
if (P == null) {
|
||||
} else if (!P.hasPermission("core.money.endless")) {
|
||||
Money.payMoney(P, -money);
|
||||
}
|
||||
Tools.sendStatusMsg(sender, Core.getl("money_payed_1", sender) + " " + args[1] + " " + Core.getl("money_payed_2", sender) + " " + args[2] + " " + Core.getl("money_payed_3", sender), true);
|
||||
if (oP.isOnline()) {
|
||||
Tools.sendStatusMsg(oP.getPlayer(), Core.getl("money_got_1", oP.getPlayer()) + " " + args[2] + " " + Core.getl("money_got_2", oP.getPlayer()) + " " + sender.getName() + " " + Core.getl("money_got_3", oP.getPlayer()), true);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
Core.statusMsg(sender, "never_seen_player", false);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//package de.anura.core.commands;
|
||||
//
|
||||
//import de.anura.core.API.Core;
|
||||
//import de.anura.core.Money;
|
||||
//import de.anura.core.API.Tools;
|
||||
//import java.sql.ResultSet;
|
||||
//import org.bukkit.Bukkit;
|
||||
//import org.bukkit.Location;
|
||||
//import org.bukkit.OfflinePlayer;
|
||||
//import org.bukkit.World;
|
||||
//import org.bukkit.command.BlockCommandSender;
|
||||
//import org.bukkit.command.Command;
|
||||
//import org.bukkit.command.CommandExecutor;
|
||||
//import org.bukkit.command.CommandSender;
|
||||
//import org.bukkit.entity.Player;
|
||||
//
|
||||
//public class PlayerCommands implements CommandExecutor {
|
||||
//
|
||||
// @Override
|
||||
// public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
|
||||
// Player P = null;
|
||||
// if (sender instanceof Player) {
|
||||
// P = (Player) sender;
|
||||
// }
|
||||
//
|
||||
// if (cmd.getName().equalsIgnoreCase("spawn")) {
|
||||
// if (args.length == 1) {
|
||||
// if (sender.hasPermission("core.commands.spawn-other") || sender instanceof BlockCommandSender) {
|
||||
// if (Bukkit.getOfflinePlayer(args[0]).isOnline()) {
|
||||
// P = Bukkit.getPlayer(args[0]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (P == null) {
|
||||
// Core.statusMsg(sender, "only_player_cmd", false);
|
||||
// return true;
|
||||
// }
|
||||
// Core.toSpawn(P);
|
||||
// Core.statusMsg(P, "spawn_tp_done", true);
|
||||
// return true;
|
||||
// } else if (cmd.getName().equalsIgnoreCase("warp")) {
|
||||
// if (args.length == 0 || args.length > 2) {
|
||||
// Core.statusMsg(P, "wrong_args_count", false);
|
||||
// return false;
|
||||
// }
|
||||
// if (P == null) {
|
||||
// if (args.length != 2) {
|
||||
// Core.statusMsg(P, "wrong_args_count", false);
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// if (args.length == 2) {
|
||||
// String p = args[1];
|
||||
// if (!Bukkit.getOfflinePlayer(p).isOnline()) {
|
||||
// Core.statusMsg(P, "player_not_online", false);
|
||||
// return false;
|
||||
// }
|
||||
// P = Bukkit.getPlayer(p);
|
||||
// }
|
||||
// String warpName = args[0];
|
||||
// ResultSet rs = Core.getMySql().querySelect("SELECT world, X, Y, Z, userWarp, server FROM coreWarps WHERE name = '" + warpName + "'");
|
||||
// rs.last();
|
||||
// if (rs.getRow() == 0) {
|
||||
// Core.statusMsg(P, "warp_not_exist", false);
|
||||
// return true;
|
||||
// }
|
||||
// rs.first();
|
||||
// if (P == null) {
|
||||
// return false;
|
||||
// }
|
||||
// if (!rs.getBoolean("userWarp") && !P.hasPermission("core.commands.adminWarp")) {
|
||||
// Core.statusMsg(P, "no_perms", false);
|
||||
// return true;
|
||||
// }
|
||||
// int X = rs.getInt("X");
|
||||
// int Y = rs.getInt("Y");
|
||||
// int Z = rs.getInt("Z");
|
||||
// String server = rs.getString("server");
|
||||
// String world = rs.getString("world");
|
||||
// if (!server.equals(Core.getMainClass().getConfig().getString("server-name"))) {
|
||||
// Core.statusMsg(P, "warp_other_server", false);
|
||||
// return true;
|
||||
// }
|
||||
// World w = Bukkit.getWorld(world);
|
||||
// if (w == null) {
|
||||
// Core.statusMsg(P, "warp_not_avail", false);
|
||||
// return true;
|
||||
// }
|
||||
// Location loc = new Location(w, X, Y, Z);
|
||||
// P.teleport(loc);
|
||||
// Core.statusMsg(P, "warp_tp_done", true);
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//}
|
||||
|
||||
34
src/de/anura/core/commands/Spawn.java
Normal file
34
src/de/anura/core/commands/Spawn.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package de.anura.core.commands;
|
||||
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.msg.Msg;
|
||||
import de.anura.core.msg.Msg.MsgType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Spawn implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||
Player P;
|
||||
if (args.length > 0) {
|
||||
P = Bukkit.getPlayerExact(args[0]);
|
||||
} else if (sender instanceof Player) {
|
||||
P = (Player) sender;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (P == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// TODO: Wait time
|
||||
P.teleport(P.getWorld().getSpawnLocation());
|
||||
Msg.send(sender, AnuraCore.getInstance(), MsgType.SUCCESS, "Zum Spawn teleportiert!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,316 +1,125 @@
|
||||
package de.anura.core.commands;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.API.Tools;
|
||||
import de.anura.core.Features;
|
||||
import de.anura.core.FlowerPots;
|
||||
import de.anura.core.util.Data;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.CommandBlock;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class TeamCommands implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||
try {
|
||||
Player P = null;
|
||||
if (sender instanceof Player) {
|
||||
P = (Player) sender;
|
||||
}
|
||||
if (cmd.getName().equalsIgnoreCase("setcmd")) {
|
||||
if (P == null) {
|
||||
Core.statusMsg(sender, "only_player_cmd", false);
|
||||
return true;
|
||||
}
|
||||
if (!sender.hasPermission("core.commands.editcmd")) {
|
||||
Core.statusMsg(sender, "no_perms", false);
|
||||
return true;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
Core.statusMsg(sender, "wrong_args_count", false);
|
||||
return false;
|
||||
}
|
||||
Set<Material> transparent = new HashSet<>();
|
||||
transparent.add(Material.AIR);
|
||||
Block b = P.getTargetBlock(transparent, 100);
|
||||
if (b.getType().equals(Material.COMMAND)) {
|
||||
String command = "";
|
||||
for (String arg : args) {
|
||||
if (!command.isEmpty()) {
|
||||
command += " ";
|
||||
}
|
||||
command += arg;
|
||||
}
|
||||
CommandBlock cb = (CommandBlock) b.getState();
|
||||
cb.setCommand(command);
|
||||
cb.update();
|
||||
}
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("addcmd")) {
|
||||
if (P == null) {
|
||||
Core.statusMsg(sender, "only_player_cmd", false);
|
||||
return true;
|
||||
}
|
||||
if (!sender.hasPermission("core.commands.editcmd")) {
|
||||
Core.statusMsg(sender, "no_perms", false);
|
||||
return true;
|
||||
}
|
||||
if (args.length != 1) {
|
||||
Core.statusMsg(sender, "wrong_args_count", false);
|
||||
return false;
|
||||
}
|
||||
Set<Material> transparent = new HashSet<>();
|
||||
transparent.add(Material.AIR);
|
||||
Block b = P.getTargetBlock(transparent, 100);
|
||||
if (b.getType().equals(Material.COMMAND)) {
|
||||
CommandBlock cb = (CommandBlock) b.getState();
|
||||
String command = "";
|
||||
for (String arg : args) {
|
||||
if (!command.isEmpty()) {
|
||||
command += " ";
|
||||
}
|
||||
command += arg;
|
||||
}
|
||||
command = cb.getCommand() + command;
|
||||
cb.setCommand(command);
|
||||
cb.update();
|
||||
}
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("gm")) {
|
||||
String command = "gamemode ";
|
||||
for (String arg : args) {
|
||||
command += arg + " ";
|
||||
}
|
||||
Bukkit.dispatchCommand(sender, command);
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("stairmode")) {
|
||||
if (P == null) {
|
||||
Core.statusMsg(sender, "only_player_cmd", false);
|
||||
return true;
|
||||
}
|
||||
if (!P.hasPermission("core.commands.stairmode")) {
|
||||
Core.statusMsg(sender, "no_perms", false);
|
||||
return true;
|
||||
}
|
||||
if (Data.stairMode.contains(P)) {
|
||||
Data.stairMode.remove(P);
|
||||
} else {
|
||||
Data.stairMode.add(P);
|
||||
}
|
||||
Tools.sendStatusMsg(sender, "Done!", true);
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("flowerpot")) {
|
||||
if (P == null) {
|
||||
Core.statusMsg(sender, "only_player_cmd", false);
|
||||
return true;
|
||||
}
|
||||
if (!P.hasPermission("core.commands.flowerpot")) {
|
||||
Core.statusMsg(sender, "no_perms", false);
|
||||
return true;
|
||||
}
|
||||
if (args.length != 1) {
|
||||
Core.statusMsg(sender, "wrong_args_count", false);
|
||||
return false;
|
||||
}
|
||||
Location l = P.getLocation();
|
||||
if (Data.flowerPots.containsValue(l)) {
|
||||
Core.statusMsg(sender, "set_arch_exists", false);
|
||||
return true;
|
||||
}
|
||||
Core.getMySql().queryUpdate("INSERT INTO corePots(X,Y,Z,world,url,name,money,type) VALUES('" + l.getBlockX() + "','" + l.getBlockY() + "','" + l.getBlockZ() + "','" + l.getWorld().getName() + "','http://mc-anura.de','" + args[0] + "','1','0')");
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT id FROM corePots WHERE X = '" + l.getBlockX() + "' AND Y = '" + l.getBlockY() + "' AND Z = '" + l.getBlockZ() + "' AND world = '" + l.getWorld().getName() + "'");
|
||||
rs.first();
|
||||
Data.flowerPots.put(rs.getInt("id"), new Location(l.getWorld(), l.getBlockX(), l.getBlockY(), l.getBlockZ()));
|
||||
l.getBlock().setType(Material.BROWN_MUSHROOM);
|
||||
FlowerPots.refreshPot(rs.getInt("id"));
|
||||
Core.statusMsg(sender, "set_arch_ok", true);
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("sun")) {
|
||||
if (P != null) {
|
||||
if (P.hasPermission("core.commands.sun")) {
|
||||
World w = P.getLocation().getWorld();
|
||||
w.setTime(2000);
|
||||
w.setThundering(false);
|
||||
w.setStorm(false);
|
||||
Tools.sendStatusMsg(sender, "Sun!", true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (cmd.getName().equalsIgnoreCase("setjumper")) {
|
||||
if (P == null) {
|
||||
Core.statusMsg(sender, "only_player_cmd", false);
|
||||
return true;
|
||||
}
|
||||
if (args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
if (!P.hasPermission("core.commands.setjumper")) {
|
||||
Core.statusMsg(sender, "no_perms", false);
|
||||
return true;
|
||||
}
|
||||
if (Double.valueOf(args[0]) > 10 || Double.valueOf(args[0]) < 0.2) {
|
||||
Core.statusMsg(sender, "setjumper_wrong_number", false);
|
||||
return true;
|
||||
}
|
||||
Data.selectableJumper.put(P, Double.valueOf(args[0]));
|
||||
sender.sendMessage(ChatColor.GRAY + "[Anura] " + ChatColor.GREEN + Core.getl("setjumper_select_now", sender) + " " + Double.valueOf(args[0]) + ")");
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("flyspeed")) {
|
||||
if (P == null) {
|
||||
Core.statusMsg(sender, "only_player_cmd", false);
|
||||
return true;
|
||||
}
|
||||
if (!P.hasPermission("core.commands.flyspeed")) {
|
||||
Core.statusMsg(P, "no_perms", false);
|
||||
return true;
|
||||
}
|
||||
if (args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if (Float.parseFloat(args[0]) >= 10 || Float.parseFloat(args[0]) < 0) {
|
||||
Core.statusMsg(P, "flyspeed_wrong_number", false);
|
||||
return true;
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
Core.statusMsg(P, "flyspeed_wrong_number", false);
|
||||
return true;
|
||||
}
|
||||
P.setFlySpeed(Float.parseFloat(args[0]) / 10);
|
||||
Tools.sendStatusMsg(P, Core.getl("flyspeed_set_1", P) + " " + args[0] + Core.getl("flyspeed_set_2", P), true);
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("setwarp")) {
|
||||
if (P == null) {
|
||||
Core.statusMsg(sender, "only_player_cmd", false);
|
||||
return true;
|
||||
}
|
||||
if (!P.hasPermission("core.commands.setwarp")) {
|
||||
Core.statusMsg(P, "no_perms", false);
|
||||
return true;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
Core.statusMsg(P, "wrong_args_count", false);
|
||||
return false;
|
||||
}
|
||||
String userWarp = "0";
|
||||
if (args.length == 2) {
|
||||
if (args[1].equalsIgnoreCase("true")) {
|
||||
userWarp = "1";
|
||||
}
|
||||
}
|
||||
Location loc = P.getLocation();
|
||||
int X = loc.getBlockX();
|
||||
int Y = loc.getBlockY();
|
||||
int Z = loc.getBlockZ();
|
||||
String world = loc.getWorld().getName();
|
||||
String server = Core.getMainClass().getConfig().getString("server-name");
|
||||
String name = args[0];
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT `name` FROM coreWarps WHERE name = '" + name + "'");
|
||||
rs.last();
|
||||
if (rs.getRow() != 0) {
|
||||
Core.statusMsg(P, "warp_alr_exist", false);
|
||||
return true;
|
||||
}
|
||||
Core.getMySql().queryUpdate("INSERT INTO coreWarps(`name`, server, world, X, Y, Z, userWarp) VALUES('" + name + "', '" + server + "', '" + world + "', '" + X + "', '" + Y + "', '" + Z + "', '" + userWarp + "')");
|
||||
Core.statusMsg(P, "warp_set", true);
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("remwarp")) {
|
||||
if (args.length != 1) {
|
||||
Core.statusMsg(P, "wrong_args_count", false);
|
||||
return false;
|
||||
}
|
||||
if (!sender.hasPermission("core.commands.remwarp")) {
|
||||
Core.statusMsg(P, "no_perms", false);
|
||||
return true;
|
||||
}
|
||||
String map = args[0];
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT name FROM coreWarps WHERE name = '" + map + "'");
|
||||
rs.last();
|
||||
if (rs.getRow() == 0) {
|
||||
Core.statusMsg(P, "warp_not_exist", false);
|
||||
return true;
|
||||
}
|
||||
Core.getMySql().queryUpdate("DELETE FROM coreWarps WHERE name = '" + map + "'");
|
||||
Core.statusMsg(P, "warp_rem_done", true);
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("toggleBoatFlight")) {
|
||||
if (P != null && P.hasPermission("core.boat.toggleflight")) {
|
||||
if (Features.wantFlight.contains(P.getUniqueId())) {
|
||||
Features.wantFlight.remove(P.getUniqueId());
|
||||
P.sendMessage("Du wurdest aus der Liste entfernt!");
|
||||
} else {
|
||||
Features.wantFlight.add(P.getUniqueId());
|
||||
P.sendMessage("Du wurdest zu der Liste hinzugefügt!");
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
Core.statusMsg(P, "no_perms", false);
|
||||
return true;
|
||||
}
|
||||
} else if (cmd.getName().equalsIgnoreCase("warplist")) {
|
||||
if (P == null) return false;
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT name, userWarp FROM coreWarps WHERE server = '" + Core.getMainClass().getConfig().getString("server-name") + "'");
|
||||
while (rs.next()) {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + P.getName() + " {color:\"" + (rs.getBoolean("userWarp") ? "green" : "blue") + "\",text:\"" + rs.getString("name") + "\",clickEvent:{action:run_command,value:\"/warp " + rs.getString("name") + "\"}}");
|
||||
}
|
||||
return true;
|
||||
} else if (cmd.getName().equalsIgnoreCase("i")) {
|
||||
if (P != null && P.hasPermission("core.commands.i")) {
|
||||
if (args.length == 0) return false;
|
||||
String item = args[0];
|
||||
boolean d = args.length == 2 && Core.isInteger(args[1]);
|
||||
short dam = d ? Short.valueOf(args[1]) : 0;
|
||||
if (Core.isInteger(item)) {
|
||||
P.getInventory().addItem(new ItemStack(Integer.valueOf(item), 1, dam));
|
||||
} else {
|
||||
Material m = Material.matchMaterial(item);
|
||||
if (m == null) return true;
|
||||
P.getInventory().addItem(new ItemStack(m, 1, dam));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else if (cmd.getName().equalsIgnoreCase("mute")) {
|
||||
if (sender.hasPermission("core.commands.mute")) {
|
||||
if (args.length == 0) return false;
|
||||
Player p = Bukkit.getPlayer(args[0]);
|
||||
if (p == null) {
|
||||
sender.sendMessage("Spieler ist nicht online!");
|
||||
return true;
|
||||
}
|
||||
Core.getMySql().queryUpdate("UPDATE players SET muted = 1 WHERE uuid = '"+p.getUniqueId().toString()+"'");
|
||||
sender.sendMessage("Spieler gemutet!");
|
||||
return true;
|
||||
}
|
||||
} else if (cmd.getName().equalsIgnoreCase("unmute")) {
|
||||
if (sender.hasPermission("core.commands.mute")) {
|
||||
if (args.length == 0) return false;
|
||||
Player p = Bukkit.getPlayer(args[0]);
|
||||
if (p == null) {
|
||||
sender.sendMessage("Spieler ist nicht online!");
|
||||
return true;
|
||||
}
|
||||
Core.getMySql().queryUpdate("UPDATE players SET muted = 0 WHERE uuid = '"+p.getUniqueId().toString()+"'");
|
||||
sender.sendMessage("Spieler entmutet!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//package de.anura.core.commands;
|
||||
//
|
||||
//import de.anura.core.API.Core;
|
||||
//import de.anura.core.API.Tools;
|
||||
//import java.sql.ResultSet;
|
||||
//import org.bukkit.Bukkit;
|
||||
//import org.bukkit.GameMode;
|
||||
//import org.bukkit.Location;
|
||||
//import org.bukkit.World;
|
||||
//import org.bukkit.command.Command;
|
||||
//import org.bukkit.command.CommandExecutor;
|
||||
//import org.bukkit.command.CommandSender;
|
||||
//import org.bukkit.entity.Player;
|
||||
//
|
||||
//public class TeamCommands implements CommandExecutor {
|
||||
//
|
||||
// @Override
|
||||
// public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||
// Player P = null;
|
||||
// if (sender instanceof Player) {
|
||||
// P = (Player) sender;
|
||||
// }
|
||||
// if (cmd.getName().equalsIgnoreCase("gm")) {
|
||||
//
|
||||
//
|
||||
// } else if (cmd.getName().equalsIgnoreCase("sun")) {
|
||||
// if (P != null) {
|
||||
// if (P.hasPermission("core.commands.sun")) {
|
||||
// World w = P.getLocation().getWorld();
|
||||
// w.setTime(2000);
|
||||
// w.setThundering(false);
|
||||
// w.setStorm(false);
|
||||
// Tools.sendStatusMsg(sender, "Sun!", true);
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// } else if (cmd.getName().equalsIgnoreCase("setwarp")) {
|
||||
// if (P == null) {
|
||||
// Core.statusMsg(sender, "only_player_cmd", false);
|
||||
// return true;
|
||||
// }
|
||||
// if (!P.hasPermission("core.commands.setwarp")) {
|
||||
// Core.statusMsg(P, "no_perms", false);
|
||||
// return true;
|
||||
// }
|
||||
// if (args.length < 1) {
|
||||
// Core.statusMsg(P, "wrong_args_count", false);
|
||||
// return false;
|
||||
// }
|
||||
// String userWarp = "0";
|
||||
// if (args.length == 2) {
|
||||
// if (args[1].equalsIgnoreCase("true")) {
|
||||
// userWarp = "1";
|
||||
// }
|
||||
// }
|
||||
// Location loc = P.getLocation();
|
||||
// int X = loc.getBlockX();
|
||||
// int Y = loc.getBlockY();
|
||||
// int Z = loc.getBlockZ();
|
||||
// String world = loc.getWorld().getName();
|
||||
// String server = Core.getMainClass().getConfig().getString("server-name");
|
||||
// String name = args[0];
|
||||
// ResultSet rs = Core.getMySql().querySelect("SELECT `name` FROM coreWarps WHERE name = '" + name + "'");
|
||||
// rs.last();
|
||||
// if (rs.getRow() != 0) {
|
||||
// Core.statusMsg(P, "warp_alr_exist", false);
|
||||
// return true;
|
||||
// }
|
||||
// Core.getMySql().queryUpdate("INSERT INTO coreWarps(`name`, server, world, X, Y, Z, userWarp) VALUES('" + name + "', '" + server + "', '" + world + "', '" + X + "', '" + Y + "', '" + Z + "', '" + userWarp + "')");
|
||||
// Core.statusMsg(P, "warp_set", true);
|
||||
// return true;
|
||||
// } else if (cmd.getName().equalsIgnoreCase("remwarp")) {
|
||||
// if (args.length != 1) {
|
||||
// Core.statusMsg(P, "wrong_args_count", false);
|
||||
// return false;
|
||||
// }
|
||||
// if (!sender.hasPermission("core.commands.remwarp")) {
|
||||
// Core.statusMsg(P, "no_perms", false);
|
||||
// return true;
|
||||
// }
|
||||
// String map = args[0];
|
||||
// ResultSet rs = Core.getMySql().querySelect("SELECT name FROM coreWarps WHERE name = '" + map + "'");
|
||||
// rs.last();
|
||||
// if (rs.getRow() == 0) {
|
||||
// Core.statusMsg(P, "warp_not_exist", false);
|
||||
// return true;
|
||||
// }
|
||||
// Core.getMySql().queryUpdate("DELETE FROM coreWarps WHERE name = '" + map + "'");
|
||||
// Core.statusMsg(P, "warp_rem_done", true);
|
||||
// return true;
|
||||
// } else if (cmd.getName().equalsIgnoreCase("warplist")) {
|
||||
// if (P == null) return false;
|
||||
// ResultSet rs = Core.getMySql().querySelect("SELECT name, userWarp FROM coreWarps WHERE server = '" + Core.getMainClass().getConfig().getString("server-name") + "'");
|
||||
// while (rs.next()) {
|
||||
// Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + P.getName() + " {color:\"" + (rs.getBoolean("userWarp") ? "green" : "blue") + "\",text:\"" + rs.getString("name") + "\",clickEvent:{action:run_command,value:\"/warp " + rs.getString("name") + "\"}}");
|
||||
// }
|
||||
// return true;
|
||||
// } else if (cmd.getName().equalsIgnoreCase("mute")) {
|
||||
// if (sender.hasPermission("core.commands.mute")) {
|
||||
// if (args.length == 0) return false;
|
||||
// Player p = Bukkit.getPlayer(args[0]);
|
||||
// if (p == null) {
|
||||
// sender.sendMessage("Spieler ist nicht online!");
|
||||
// return true;
|
||||
// }
|
||||
// Core.getMySql().queryUpdate("UPDATE players SET muted = 1 WHERE uuid = '"+p.getUniqueId().toString()+"'");
|
||||
// sender.sendMessage("Spieler gemutet!");
|
||||
// return true;
|
||||
// }
|
||||
// } else if (cmd.getName().equalsIgnoreCase("unmute")) {
|
||||
// if (sender.hasPermission("core.commands.mute")) {
|
||||
// if (args.length == 0) return false;
|
||||
// Player p = Bukkit.getPlayer(args[0]);
|
||||
// if (p == null) {
|
||||
// sender.sendMessage("Spieler ist nicht online!");
|
||||
// return true;
|
||||
// }
|
||||
// Core.getMySql().queryUpdate("UPDATE players SET muted = 0 WHERE uuid = '"+p.getUniqueId().toString()+"'");
|
||||
// sender.sendMessage("Spieler entmutet!");
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//}
|
||||
|
||||
94
src/de/anura/core/database/DB.java
Normal file
94
src/de/anura/core/database/DB.java
Normal file
@@ -0,0 +1,94 @@
|
||||
package de.anura.core.database;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class DB {
|
||||
|
||||
private static final String DEFAULT_DB = "anura_freebuild";
|
||||
|
||||
private static final HashMap<String, MySQL> dbs = new HashMap<>();
|
||||
|
||||
public static MySQL get() {
|
||||
return get(DEFAULT_DB);
|
||||
}
|
||||
|
||||
public static MySQL get(String dbName) {
|
||||
synchronized (dbs) {
|
||||
if (dbs.containsKey(dbName)) {
|
||||
return dbs.get(dbName);
|
||||
} else {
|
||||
MySQL m = new MySQL(dbName);
|
||||
dbs.put(dbName, m);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void queryUpdate(boolean async, String query, Object... args) {
|
||||
get().queryUpdate(async, query, args);
|
||||
}
|
||||
|
||||
public static void queryUpdate(String query, Object... args) {
|
||||
get().queryUpdate(query, args);
|
||||
}
|
||||
|
||||
public static void queryUpdate(boolean async, Consumer<ResultSet> generatedKeys, String query, Object... args) {
|
||||
get().queryUpdate(async, generatedKeys, query, args);
|
||||
}
|
||||
|
||||
public static void queryUpdate(Consumer<ResultSet> generatedKeys, String query, Object... args) {
|
||||
get().queryUpdate(generatedKeys, query, args);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static MySQL.PreparedUpdate queryPrepUpdate(String query) {
|
||||
return get().queryPrepUpdate(query);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static MySQL.PreparedUpdate queryPrepUpdate(Consumer<ResultSet> generatedKeys, String query) {
|
||||
return get().queryPrepUpdate(generatedKeys, query);
|
||||
}
|
||||
|
||||
public static ResultSet querySelect(String query, Object... args) {
|
||||
return get().querySelect(query, args);
|
||||
}
|
||||
|
||||
public static void closeRessources(ResultSet rs) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Consumer<ResultSet> getFirstKey(Consumer<Integer> callback) {
|
||||
return keys -> {
|
||||
try {
|
||||
if (!keys.next()) {
|
||||
callback.accept(null);
|
||||
return;
|
||||
}
|
||||
callback.accept(keys.getInt(1));
|
||||
} catch (SQLException e) {
|
||||
callback.accept(null);
|
||||
Logger.getLogger(DB.class.getName()).log(Level.SEVERE, null, e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void stop() {
|
||||
synchronized (dbs) {
|
||||
for (MySQL sql : dbs.values()) {
|
||||
sql.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
190
src/de/anura/core/database/ErrorAppender.java
Normal file
190
src/de/anura/core/database/ErrorAppender.java
Normal file
@@ -0,0 +1,190 @@
|
||||
package de.anura.core.database;
|
||||
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.AnuraThread;
|
||||
import de.anura.core.database.MySQL.PreparedUpdate;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.core.LogEvent;
|
||||
import org.apache.logging.log4j.core.appender.AbstractAppender;
|
||||
import org.apache.logging.log4j.core.filter.AbstractFilter;
|
||||
import org.apache.logging.log4j.core.layout.AbstractStringLayout;
|
||||
|
||||
public class ErrorAppender extends AbstractAppender {
|
||||
|
||||
private static final String[] errorFilterStarts = new String[] {
|
||||
"**** SERVER IS RUNNING",
|
||||
"The server will make no attempt",
|
||||
"Please see http://www.spigotmc",
|
||||
"To change this, set",
|
||||
"handleDisconnection",
|
||||
"Whilst this makes it possible to use BungeeCord",
|
||||
"[SimpleBackup] Unable to backup file",
|
||||
"A manual (plugin-induced) save has been detected",
|
||||
"[NoCheatPlus] The Minecraft version seems to be more recent",
|
||||
"Invalid statistic in"
|
||||
};
|
||||
|
||||
private static final String[] errorFilterContains = new String[] {
|
||||
"moved too quickly",
|
||||
"moved wrongly!",
|
||||
"was kicked for floating too long!"
|
||||
};
|
||||
|
||||
public ErrorAppender() {
|
||||
super("AnuraAppender", new AbstractFilter() {
|
||||
}, new AbstractStringLayout(Charset.defaultCharset()) {
|
||||
|
||||
@Override
|
||||
public byte[] toByteArray(LogEvent le) {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getContentFormat() {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSerializable(LogEvent le) {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
this.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void append(LogEvent le) {
|
||||
if (le.getLevel().equals(Level.ERROR) || le.getLevel().equals(Level.FATAL) || le.getLevel().equals(Level.WARN)) {
|
||||
String msg = le.getMessage().getFormattedMessage();
|
||||
if (msg != null) {
|
||||
for (String s : errorFilterStarts) {
|
||||
if (msg.startsWith(s)) return;
|
||||
}
|
||||
for (String s : errorFilterContains) {
|
||||
if (msg.contains(s)) return;
|
||||
}
|
||||
}
|
||||
Runnable save = () -> saveError(msg, le.getThrown(), "Logger: " + le.getLoggerName(), "Thread: " + le.getThreadName());
|
||||
if (!AnuraCore.getInstance().isEnabled()) {
|
||||
save.run();
|
||||
} else {
|
||||
AnuraThread.async(save);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveError(String error, Throwable ex, String... info) {
|
||||
String infoStr = "";
|
||||
for (String s : info) {
|
||||
infoStr += s + "\n";
|
||||
}
|
||||
DB.queryUpdate(DB.getFirstKey((id) -> saveStackTrace(id, ex)), "INSERT INTO errors (error, exception, message, info, timestamp) VALUES (?, ?, ?, ?, ?)", error, ex == null ? null : ex.getClass().toString(),
|
||||
ex == null ? "" : ex.getLocalizedMessage(), infoStr, System.currentTimeMillis() / 1000);
|
||||
}
|
||||
|
||||
private static void saveStackTrace(int id, Throwable ex) {
|
||||
if (ex == null || (ex.getStackTrace().length == 0 && ex.getCause() == null)) {
|
||||
return;
|
||||
}
|
||||
PreparedUpdate upd = DB.queryPrepUpdate("INSERT INTO errorStack (errorId, className, fileName, methodName, lineNumber, nativeMethod) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
if (upd == null) return;
|
||||
List<TraceElement> elems = Arrays.asList(ex.getStackTrace()).stream().map((elem) -> (TraceElement) new TraceElementStack(elem)).collect(Collectors.toList());
|
||||
while (ex.getCause() != null) {
|
||||
ex = ex.getCause();
|
||||
elems.add(new TraceElementString("Caused by: ", ex.getLocalizedMessage(), ex.getClass().getName()));
|
||||
elems.addAll(Arrays.asList(ex.getStackTrace()).stream().map((elem) -> (TraceElement) new TraceElementStack(elem)).collect(Collectors.toList()));
|
||||
}
|
||||
elems.forEach((elem) -> upd.add(id, elem.getClassName(), elem.getFileName(), elem.getMethodName(), elem.getLineNumber(), elem.isNative()));
|
||||
upd.done();
|
||||
}
|
||||
|
||||
private static class TraceElementString extends TraceElement {
|
||||
|
||||
private final String[] msg;
|
||||
|
||||
private TraceElementString(String... msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getClassName() {
|
||||
return msg.length > 0 ? msg[0] : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
String getFileName() {
|
||||
return msg.length > 1 ? msg[1] : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
String getMethodName() {
|
||||
return msg.length > 2 ? msg[2] : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
int getLineNumber() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isNative() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class TraceElementStack extends TraceElement {
|
||||
|
||||
private final StackTraceElement elem;
|
||||
|
||||
private TraceElementStack(StackTraceElement elem) {
|
||||
this.elem = elem;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getClassName() {
|
||||
return elem.getClassName();
|
||||
}
|
||||
|
||||
@Override
|
||||
String getFileName() {
|
||||
return elem.getFileName();
|
||||
}
|
||||
|
||||
@Override
|
||||
String getMethodName() {
|
||||
return elem.getMethodName();
|
||||
}
|
||||
|
||||
@Override
|
||||
int getLineNumber() {
|
||||
return elem.getLineNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isNative() {
|
||||
return elem.isNativeMethod();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static abstract class TraceElement {
|
||||
|
||||
abstract String getClassName();
|
||||
abstract String getFileName();
|
||||
abstract String getMethodName();
|
||||
abstract int getLineNumber();
|
||||
abstract boolean isNative();
|
||||
}
|
||||
}
|
||||
322
src/de/anura/core/database/MySQL.java
Normal file
322
src/de/anura/core/database/MySQL.java
Normal file
@@ -0,0 +1,322 @@
|
||||
package de.anura.core.database;
|
||||
|
||||
import de.anura.core.AnuraThread;
|
||||
import de.anura.core.msg.Message;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.annotation.Nullable;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class MySQL {
|
||||
|
||||
private static final int QUEUE_LIMIT = 5000;
|
||||
|
||||
private static final Logger log = Logger.getLogger(MySQL.class.getName());
|
||||
private static long lastPrint = 0;
|
||||
private static int queryCounter = 0;
|
||||
private static final Map<String, Integer> queryCount = new ConcurrentHashMap<>();
|
||||
|
||||
private Connection conn;
|
||||
private final FileConfiguration config;
|
||||
private volatile boolean reconnecting = false;
|
||||
private final String db;
|
||||
private ThreadPoolExecutor executor;
|
||||
|
||||
MySQL(String dbName) {
|
||||
db = dbName;
|
||||
File file = new File("plugins/database/", "db_" + dbName + ".yml");
|
||||
FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
|
||||
cfg.addDefault("host", "localhost");
|
||||
cfg.addDefault("port", 3306);
|
||||
cfg.addDefault("username", "username");
|
||||
cfg.addDefault("pw", "pw");
|
||||
cfg.options().copyDefaults(true);
|
||||
try {
|
||||
cfg.save(file);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
this.config = cfg;
|
||||
lastPrint = System.currentTimeMillis();
|
||||
initializeThreadPool();
|
||||
if (!this.openConnection()) {
|
||||
Message.broadcast(ChatColor.RED + "Keine Datenbankverbindung!");
|
||||
connectFailed();
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean openConnection() {
|
||||
try {
|
||||
String host = config.getString("host");
|
||||
int port = config.getInt("port");
|
||||
String username = config.getString("username");
|
||||
String pw = config.getString("pw");
|
||||
String dataB = config.getString("db", db);
|
||||
Connection connLoc = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + dataB + "?serverTimezone=Europe/Berlin", username, pw);
|
||||
this.conn = connLoc;
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
log.log(Level.WARNING, e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasConnection() {
|
||||
try {
|
||||
return this.conn != null && this.conn.isValid(1) && !reconnecting;
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void queryUpdate(boolean async, String query, Object... args) {
|
||||
queryUpdate(async, null, query, args);
|
||||
}
|
||||
|
||||
public void queryUpdate(String query, Object... args) {
|
||||
queryUpdate(false, null, query, args);
|
||||
}
|
||||
|
||||
public void queryUpdate(boolean async, Consumer<ResultSet> generatedKeys, String query, Object... args) {
|
||||
if (async) executor.execute(() -> queryUpdate(generatedKeys, query, args));
|
||||
else queryUpdate(generatedKeys, query, args);
|
||||
}
|
||||
|
||||
public void queryUpdate(Consumer<ResultSet> generatedKeys, String query, Object... args) {
|
||||
queryCount.put(query, queryCount.getOrDefault(query, 0) + 1);
|
||||
printThreadLog();
|
||||
if (!hasConnection()) {
|
||||
if (!tryReconnect()) {
|
||||
connectFailed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
Connection connLoc = conn;
|
||||
PreparedStatement st = null;
|
||||
try {
|
||||
st = connLoc.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
|
||||
int i = 1;
|
||||
for (Object o : args) {
|
||||
st.setObject(i, o);
|
||||
i++;
|
||||
}
|
||||
st.executeUpdate();
|
||||
if (generatedKeys != null) {
|
||||
generatedKeys.accept(st.getGeneratedKeys());
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.log(Level.SEVERE, "Failed to send update: {0} - {1}", new Object[] { query, e.getLocalizedMessage() });
|
||||
}
|
||||
closeRessources(st);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PreparedUpdate queryPrepUpdate(String query) {
|
||||
return queryPrepUpdate(null, query);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PreparedUpdate queryPrepUpdate(Consumer<ResultSet> generatedKeys, String query) {
|
||||
if (!hasConnection()) {
|
||||
if (!tryReconnect()) {
|
||||
connectFailed();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
PreparedStatement st;
|
||||
try {
|
||||
st = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
|
||||
return new PreparedUpdate(st, generatedKeys);
|
||||
} catch (SQLException e) {
|
||||
log.log(Level.SEVERE, "Failed to send update: " + query, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ResultSet querySelect(String query, Object... args) {
|
||||
if (!hasConnection()) {
|
||||
if (!tryReconnect()) {
|
||||
connectFailed();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
try {
|
||||
PreparedStatement st = conn.prepareStatement(query);
|
||||
int i = 1;
|
||||
for (Object o : args) {
|
||||
st.setObject(i, o);
|
||||
i++;
|
||||
}
|
||||
return querySelect(st);
|
||||
} catch (SQLException ex) {
|
||||
log.log(Level.SEVERE, "Error trying to build Prepared Statement", ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ResultSet querySelect(PreparedStatement st) {
|
||||
if (!hasConnection()) {
|
||||
if (!tryReconnect()) {
|
||||
connectFailed();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
ResultSet rs;
|
||||
try {
|
||||
rs = st.executeQuery();
|
||||
} catch (SQLException e) {
|
||||
log.log(Level.SEVERE, "Failed to send SELECT query: " + st.toString(), e);
|
||||
return null;
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
||||
@SuppressWarnings("SleepWhileInLoop")
|
||||
private boolean tryReconnect() {
|
||||
int count = 0;
|
||||
while (!reconnect()) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException ex) {}
|
||||
count++;
|
||||
if (count == 100) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean reconnect() {
|
||||
if (reconnecting) {
|
||||
return false;
|
||||
}
|
||||
if (hasConnection()) {
|
||||
return true;
|
||||
}
|
||||
reconnecting = true;
|
||||
log.log(Level.INFO, "Reconnecting...");
|
||||
closeConnection();
|
||||
if (!openConnection()) {
|
||||
reconnecting = false;
|
||||
Message.broadcast(ChatColor.RED + "Keine Datenbankverbindung!");
|
||||
return false;
|
||||
} else {
|
||||
reconnecting = false;
|
||||
log.log(Level.INFO, "Database reconnect successful!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void connectFailed() {
|
||||
log.log(Level.WARNING, "Gave up database reconnect. Kicking all players...");
|
||||
AnuraThread.sync(() -> {
|
||||
for (Player P : Bukkit.getOnlinePlayers()) {
|
||||
P.kickPlayer(ChatColor.RED + "Datenbankverbindung fehlgeschlagen. Versuche es doch in ein paar Minuten erneut!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void closeRessources(PreparedStatement st) {
|
||||
if (st != null) {
|
||||
try {
|
||||
st.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
public void closeConnection() {
|
||||
try {
|
||||
if (this.conn != null) {
|
||||
this.conn.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
} finally {
|
||||
this.conn = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeThreadPool() {
|
||||
executor = new ThreadPoolExecutor(6, 6, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<>(QUEUE_LIMIT));
|
||||
}
|
||||
|
||||
private void printThreadLog() {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastPrint > 60 * 1000) {
|
||||
lastPrint = now;
|
||||
synchronized (queryCount) {
|
||||
for (Entry<String, Integer> queries : queryCount.entrySet()) {
|
||||
queryCounter += queries.getValue();
|
||||
if (queries.getValue() < 30) continue;
|
||||
Logger.getLogger(MySQL.class.getName()).log(queries.getValue() > 100 ? Level.WARNING : Level.INFO, "{0}: {1}", new Object[] {queries.getKey(), queries.getValue()});
|
||||
}
|
||||
}
|
||||
queryCount.clear();
|
||||
Logger.getLogger(MySQL.class.getName()).log(Level.INFO, getThreadInfo());
|
||||
}
|
||||
}
|
||||
|
||||
void stop() {
|
||||
executor.shutdown();
|
||||
}
|
||||
|
||||
private String getThreadInfo() {
|
||||
return "SQL Threads: Active: " + executor.getActiveCount() + " (Queue: " + executor.getQueue().size() + ") - Pool size: " + executor.getPoolSize() + " (Max: " + executor.getLargestPoolSize()+ ") - Completed: " + executor.getCompletedTaskCount() + " (Total: " + queryCounter + ")";
|
||||
}
|
||||
|
||||
public class PreparedUpdate {
|
||||
|
||||
private final PreparedStatement stmt;
|
||||
private final Consumer<ResultSet> keys;
|
||||
|
||||
public PreparedUpdate(PreparedStatement statement, Consumer<ResultSet> generatedKeys) {
|
||||
stmt = statement;
|
||||
keys = generatedKeys;
|
||||
}
|
||||
|
||||
public PreparedUpdate add(Object... args) {
|
||||
try {
|
||||
int i = 1;
|
||||
for (Object o : args) {
|
||||
stmt.setObject(i, o);
|
||||
i++;
|
||||
}
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
log.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void done() {
|
||||
try {
|
||||
if (keys != null) {
|
||||
keys.accept(stmt.getGeneratedKeys());
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
log.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
closeRessources(stmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/de/anura/core/events/AnuraLeaveEvent.java
Normal file
22
src/de/anura/core/events/AnuraLeaveEvent.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class AnuraLeaveEvent extends AnuraPlayerEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public AnuraLeaveEvent(Player who) {
|
||||
super(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
33
src/de/anura/core/events/AnuraPlayerEvent.java
Normal file
33
src/de/anura/core/events/AnuraPlayerEvent.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class AnuraPlayerEvent extends Event {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final Player player;
|
||||
|
||||
public AnuraPlayerEvent(Player player) {
|
||||
this(player, false);
|
||||
}
|
||||
|
||||
public AnuraPlayerEvent(Player player, boolean async) {
|
||||
super(async);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.util.Data;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.material.Stairs;
|
||||
|
||||
public class BlockBreak implements Listener {
|
||||
|
||||
public BlockBreak(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
try {
|
||||
if (plugin.getConfig().getBoolean("no-change-blocks")) {
|
||||
if (!event.getPlayer().hasPermission("core.rules.blocks.break")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (Data.flowerPots.containsValue(event.getBlock().getLocation())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if ((event.getBlock().getType() == Material.ENDER_CHEST || event.getBlock().getType() == Material.RAILS)) {
|
||||
int X = (int) event.getBlock().getLocation().getX();
|
||||
int Y = (int) event.getBlock().getLocation().getY();
|
||||
int Z = (int) event.getBlock().getLocation().getZ();
|
||||
String world = event.getBlock().getLocation().getWorld().getName();
|
||||
String sql = "DELETE FROM coreJumpers WHERE X = '" + X + "' AND Y = '" + Y + "' AND Z = '" + Z + "' AND world = '" + world + "'";
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
AnuraCore.getSql().queryUpdate(sql);
|
||||
});
|
||||
} else if (event.getBlock().getState() instanceof Sign) {
|
||||
Sign s = (Sign) event.getBlock().getState();
|
||||
Location loc = s.getLocation();
|
||||
int X = loc.getBlockX();
|
||||
int Y = loc.getBlockY();
|
||||
int Z = loc.getBlockZ();
|
||||
String world = loc.getWorld().getName();
|
||||
String server = plugin.getConfig().getString("server-name");
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
Core.getMySql().queryUpdate("DELETE FROM coreWarpSigns WHERE X = '" + X + "' AND Y = '" + Y + "' AND Z = '" + Z + "' AND world = '" + world + "' AND server = '" + server + "'");
|
||||
});
|
||||
} else if (event.getBlock().getState().getData() instanceof Stairs) {
|
||||
if (Data.sittingBlocks.containsValue(event.getBlock())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.AnuraCore;
|
||||
import java.util.Arrays;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockFadeEvent;
|
||||
|
||||
public class BlockFade implements Listener {
|
||||
|
||||
public BlockFade(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockFade(BlockFadeEvent event) {
|
||||
Material[] cancelled = new Material[] { Material.ICE, Material.SNOW, Material.SNOW_BLOCK };
|
||||
if (Core.getMainClass().getConfig().getBoolean("no-snow-melt") && Arrays.asList(cancelled).contains(event.getBlock().getType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.FlowerPots;
|
||||
import de.anura.core.util.Data;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
public class BlockPlace implements Listener {
|
||||
|
||||
public BlockPlace(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
try {
|
||||
if (plugin.getConfig().getBoolean("no-change-blocks")) {
|
||||
if (!event.getPlayer().hasPermission("core.rules.blocks.place")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
if (Data.flowerPots.containsValue(event.getBlock().getLocation())) {
|
||||
event.setCancelled(true);
|
||||
final Block b = event.getBlock();
|
||||
final int pot = Core.getKeyByValue(Data.flowerPots, b.getLocation());
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
|
||||
b.setType(Material.BROWN_MUSHROOM);
|
||||
FlowerPots.refreshPot(pot);
|
||||
}, 3);
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockSpreadEvent;
|
||||
|
||||
public class BlockSpread implements Listener {
|
||||
|
||||
public BlockSpread(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockSpread(BlockSpreadEvent event) {
|
||||
try {
|
||||
if (event.getNewState().getType().equals(Material.BROWN_MUSHROOM) && plugin.getConfig().getBoolean("disable-mushroom-spread")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.util.Data;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class CmdPreprocess implements Listener {
|
||||
|
||||
public CmdPreprocess(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
try {
|
||||
if (event.getMessage().startsWith("/?")) {
|
||||
if (!event.getPlayer().hasPermission("core.commands.help")) {
|
||||
event.setCancelled(true);
|
||||
Core.statusMsg(event.getPlayer(), "help_command_info", true);
|
||||
}
|
||||
} else if (Data.disableCommandsAdventure.containsKey(event.getPlayer()) && Data.disableCommandsAdventure.get(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
Core.statusMsg(event.getPlayer(), "no_command_red_mg", ChatColor.YELLOW);
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
|
||||
public class DropItem implements Listener {
|
||||
|
||||
public DropItem(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
try {
|
||||
if (AnuraCore.getInstance().getConfig().getBoolean("is-main-lobby") && !event.getPlayer().hasPermission("core.inventory.interact")) {
|
||||
event.setCancelled(true);
|
||||
final Player P = event.getPlayer();
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(AnuraCore.getInstance(), P::updateInventory, 1);
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.AnuraCore;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
|
||||
public class EntityChangeBlock implements Listener {
|
||||
|
||||
public EntityChangeBlock(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||
if (event.getEntityType() == EntityType.BOAT && event.getEntity().getPassenger() instanceof Player && Core.getMainClass().getConfig().getBoolean("no-change-blocks")) {
|
||||
Player P = (Player) event.getEntity().getPassenger();
|
||||
if (!P.hasPermission("core.rules.blocks.break")) {
|
||||
event.setCancelled(true);
|
||||
P.sendBlockChange(event.getBlock().getLocation(), event.getBlock().getType(), event.getBlock().getData());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
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.EntityDamageEvent.DamageCause;
|
||||
|
||||
public class EntityDamage implements Listener {
|
||||
|
||||
public EntityDamage(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
try {
|
||||
if (event.getEntity() instanceof Player && plugin.getConfig().getBoolean("no-damage")) {
|
||||
if (event.getCause().equals(DamageCause.FIRE_TICK)) {
|
||||
event.getEntity().setFireTicks(0);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
public class EntityDamageByE implements Listener {
|
||||
|
||||
public EntityDamageByE(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDamageByE(EntityDamageByEntityEvent event) {
|
||||
try {
|
||||
if ((event.getEntity() instanceof ItemFrame || event.getEntity() instanceof ArmorStand) && plugin.getConfig().getBoolean("no-change-blocks")) {
|
||||
if (event.getDamager() instanceof Player) {
|
||||
if (!event.getDamager().hasPermission("core.rules.blocks.break")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
|
||||
public class FoodChange implements Listener {
|
||||
|
||||
public FoodChange(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFoodLChange(FoodLevelChangeEvent event) {
|
||||
try {
|
||||
if (plugin.getConfig().getBoolean("no-hunger")) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
((Player) event.getEntity()).setFoodLevel(20);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||
|
||||
public class HangingEBreak implements Listener {
|
||||
|
||||
public HangingEBreak(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onHangingBreakByE(HangingBreakByEntityEvent event) {
|
||||
try {
|
||||
Player P;
|
||||
if (event.getRemover() instanceof Player) {
|
||||
P = (Player) event.getRemover();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (plugin.getConfig().getBoolean("no-change-blocks")) {
|
||||
if (!P.hasPermission("core.rules.blocks.break")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class InvClick implements Listener {
|
||||
|
||||
private final AnuraCore plugin;
|
||||
|
||||
public InvClick(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInvClick(InventoryClickEvent event) {
|
||||
try {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (!player.hasPermission("core.inventory.interact") && plugin.getConfig().getBoolean("is-main-lobby")) {
|
||||
event.setCancelled(true);
|
||||
final Player p = player;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
|
||||
p.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
p.updateInventory();
|
||||
}, 1);
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.LeavesDecayEvent;
|
||||
|
||||
public class LeavesDecay implements Listener {
|
||||
|
||||
public LeavesDecay(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLeavesDecay(LeavesDecayEvent event) {
|
||||
try {
|
||||
if (!plugin.getConfig().getBoolean("enable-leaves-decay")) {
|
||||
Block b = event.getBlock();
|
||||
byte data = b.getData();
|
||||
if ((data & 0x4) == 0) {
|
||||
data = (byte) (data | 0x4);
|
||||
}
|
||||
b.setData(data);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.IllegalFormatException;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
public class PlayerChat implements Listener {
|
||||
|
||||
public PlayerChat(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
try {
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT muted FROM players WHERE uuid = '"+event.getPlayer().getUniqueId().toString()+"'");
|
||||
rs.first();
|
||||
if (rs.getBoolean("muted")) {
|
||||
event.setCancelled(true);
|
||||
Core.statusMsg(event.getPlayer(), "you_are_muted", false);
|
||||
return;
|
||||
}
|
||||
if (event.isAsynchronous()) {
|
||||
event.setFormat("%s" + ChatColor.GRAY + ":" + ChatColor.WHITE + " %s");
|
||||
}
|
||||
} catch(IllegalFormatException | NullPointerException | SQLException e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,200 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.API.Tools;
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.FlowerPots;
|
||||
import de.anura.core.util.Data;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Arrays;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.material.Stairs;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class PlayerInteract implements Listener {
|
||||
|
||||
public PlayerInteract(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
try {
|
||||
final Block block = event.getClickedBlock();
|
||||
if (Data.selectableJumper.containsKey(event.getPlayer())) {
|
||||
if (event.getPlayer().hasPermission("core.commands.setjumper")) {
|
||||
if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) || event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
|
||||
String type;
|
||||
if (event.getClickedBlock().getType().equals(Material.ENDER_CHEST)) {
|
||||
type = "high";
|
||||
} else if (event.getClickedBlock().getType().equals(Material.RAILS)) {
|
||||
type = "far";
|
||||
} else {
|
||||
Core.statusMsg(event.getPlayer(), "setjumper_block_not_supported", false);
|
||||
Data.selectableJumper.remove(event.getPlayer());
|
||||
return;
|
||||
}
|
||||
double X = event.getClickedBlock().getLocation().getX();
|
||||
double Y = event.getClickedBlock().getLocation().getY();
|
||||
double Z = event.getClickedBlock().getLocation().getZ();
|
||||
String world = event.getClickedBlock().getLocation().getWorld().getName();
|
||||
String sql = "INSERT INTO coreJumpers(X,Y,Z,world,height,type) VALUES('" + X + "','" + Y + "','" + Z + "','" + world + "','" + Data.selectableJumper.get(event.getPlayer()) + "','" + type + "')";
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
AnuraCore.getSql().queryUpdate(sql);
|
||||
});
|
||||
Data.selectableJumper.remove(event.getPlayer());
|
||||
Core.statusMsg(event.getPlayer(), "setjumper_done", true);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} else if (block != null) {
|
||||
if (block.getState() instanceof Sign && event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
Sign sign = (Sign) block.getState();
|
||||
Location loc = sign.getLocation();
|
||||
Player P = event.getPlayer();
|
||||
int X = loc.getBlockX();
|
||||
int Y = loc.getBlockY();
|
||||
int Z = loc.getBlockZ();
|
||||
String world = loc.getWorld().getName();
|
||||
String server = plugin.getConfig().getString("server-name");
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT type, value FROM coreWarpSigns WHERE X = '" + X + "' AND Y = '" + Y + "' AND Z = '" + Z + "' AND world = '" + world + "' AND server = '" + server + "'");
|
||||
rs.last();
|
||||
if (rs.getRow() != 0) {
|
||||
rs.first();
|
||||
if (rs.getString("type").equalsIgnoreCase("warp")) {
|
||||
String warp = rs.getString("value");
|
||||
ResultSet rs2 = Core.getMySql().querySelect("SELECT world, X, Y, Z FROM coreWarps WHERE name = '" + warp + "' AND server = '" + plugin.getConfig().getString("server-name") + "'");
|
||||
rs2.last();
|
||||
if (rs2.getRow() == 0) {
|
||||
Core.statusMsg(P, "warpsign_warp_not_exist", false);
|
||||
} else {
|
||||
if (plugin.getServer().getWorld(rs2.getString("world")) != null) {
|
||||
Location target = new Location(plugin.getServer().getWorld(rs2.getString("world")), rs2.getInt("X"), rs2.getInt("Y"), rs2.getInt("Z"));
|
||||
P.teleport(target);
|
||||
}
|
||||
}
|
||||
} else if (rs.getString("type").equalsIgnoreCase("spawn")) {
|
||||
Core.toSpawn(P);
|
||||
} else if (rs.getString("type").equalsIgnoreCase("server")) {
|
||||
String targetServer = rs.getString("value");
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(b);
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF(targetServer);
|
||||
P.sendPluginMessage(plugin, "BungeeCord", b.toByteArray());
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (block.getState().getData() instanceof Stairs) {
|
||||
if (Data.stairMode.contains(event.getPlayer()) && event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
event.setCancelled(true);
|
||||
if (Data.sittableBlocks.contains(block)) {
|
||||
Data.sittableBlocks.remove(block);
|
||||
Tools.sendStatusMsg(event.getPlayer(), "Removed!", false);
|
||||
int X = block.getLocation().getBlockX();
|
||||
int Y = block.getLocation().getBlockY();
|
||||
int Z = block.getLocation().getBlockZ();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
Core.getMySql().queryUpdate("DELETE FROM coreStairs WHERE server = '" + plugin.getConfig().getString("server-name") + "' AND world = '" + block.getWorld().getName() + "' AND X = '" + X + "' AND Y = '" + Y + "' AND Z = '" + Z + "'");
|
||||
});
|
||||
} else {
|
||||
Data.sittableBlocks.add(block);
|
||||
Tools.sendStatusMsg(event.getPlayer(), "Added!", true);
|
||||
int X = block.getLocation().getBlockX();
|
||||
int Y = block.getLocation().getBlockY();
|
||||
int Z = block.getLocation().getBlockZ();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
Core.getMySql().queryUpdate("INSERT INTO coreStairs(server,world,X,Y,Z) VALUES('" + plugin.getConfig().getString("server-name") + "','" + block.getWorld().getName() + "','" + X + "','" + Y + "','" + Z + "')");
|
||||
});
|
||||
}
|
||||
} else if (plugin.getConfig().getBoolean("allow-stairs-sit") && event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && Data.sittableBlocks.contains(block) && !Data.denySit.contains(event.getPlayer())) {
|
||||
if (Data.sittingPlayer.containsKey(event.getPlayer())) {
|
||||
Core.statusMsg(event.getPlayer(), "sitting_already", false);
|
||||
event.setCancelled(true);
|
||||
} else if (Data.sittingBlocks.containsValue(block)) {
|
||||
Core.statusMsg(event.getPlayer(), "sitting_occupied", false);
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
Stairs s = (Stairs) block.getState().getData();
|
||||
if (!s.isInverted()) {
|
||||
Location loc = block.getLocation();
|
||||
loc = loc.add(0.5, 0.05, 0.5);
|
||||
loc.add(s.getFacing().getModX() * 0.2, 0, s.getFacing().getModZ() * 0.2);
|
||||
Arrow a = loc.getWorld().spawnArrow(loc, new Vector(0, 0, 0), 0, 0);
|
||||
a.setPassenger(event.getPlayer());
|
||||
Data.sittingPlayer.put(event.getPlayer(), a);
|
||||
Data.sittingBlocks.put(event.getPlayer(), block);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (Data.flowerPots.containsValue(block.getLocation())) {
|
||||
event.setCancelled(true);
|
||||
final Player p = event.getPlayer();
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
|
||||
p.sendBlockChange(block.getLocation(), Material.AIR, (byte) 0);
|
||||
}, 3);
|
||||
FlowerPots.playerFoundPot(event.getPlayer(), Core.getKeyByValue(Data.flowerPots, block.getLocation()));
|
||||
}
|
||||
}
|
||||
if (plugin.getConfig().getBoolean("no-change-blocks")) {
|
||||
if (!event.getPlayer().hasPermission("core.rules.blocks.interact")) {
|
||||
Boolean cancelled = true;
|
||||
Material[] doors = new Material[] {
|
||||
Material.WOODEN_DOOR,
|
||||
Material.ACACIA_DOOR,
|
||||
Material.SPRUCE_DOOR,
|
||||
Material.BIRCH_DOOR,
|
||||
Material.JUNGLE_DOOR,
|
||||
Material.DARK_OAK_DOOR
|
||||
};
|
||||
if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
if (event.getClickedBlock().getType().equals(Material.STONE_BUTTON)) {
|
||||
cancelled = false;
|
||||
} else if (event.getClickedBlock().getType().equals(Material.WOOD_BUTTON)) {
|
||||
cancelled = false;
|
||||
} else if (Arrays.asList(doors).contains(event.getClickedBlock().getType())) {
|
||||
cancelled = false;
|
||||
}
|
||||
} else if (event.getAction().equals(Action.PHYSICAL)) {
|
||||
if (event.getClickedBlock().getType() != Material.SOIL) {
|
||||
cancelled = false;
|
||||
}
|
||||
} else if (event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
|
||||
}
|
||||
if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
if (event.getPlayer().getItemInHand().getType().equals(Material.BOW)) {
|
||||
cancelled = false;
|
||||
} else if (event.getPlayer().getItemInHand().getType().equals(Material.EXP_BOTTLE)) {
|
||||
cancelled = false;
|
||||
} else if (event.getPlayer().getItemInHand().getType().equals(Material.ENDER_PEARL)) {
|
||||
cancelled = false;
|
||||
}
|
||||
}
|
||||
event.setCancelled(cancelled);
|
||||
}
|
||||
} else if (plugin.getConfig().getBoolean("no-bed-explode")) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.BED_BLOCK) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
public class PlayerInteractE implements Listener {
|
||||
|
||||
public PlayerInteractE(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteractE(PlayerInteractEntityEvent event) {
|
||||
try {
|
||||
if (event.getRightClicked().getType().equals(EntityType.ITEM_FRAME) && plugin.getConfig().getBoolean("no-change-blocks")) {
|
||||
if (!event.getPlayer().hasPermission("core.rules.blocks.interact")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (event.getRightClicked() instanceof ArmorStand && plugin.getConfig().getBoolean("no-change-blocks")) {
|
||||
if (!event.getPlayer().hasPermission("core.rules.blocks.interact")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.FlowerPots;
|
||||
import de.anura.core.Teleports;
|
||||
import de.anura.core.util.Data;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class PlayerJoin implements Listener {
|
||||
|
||||
public PlayerJoin(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
try {
|
||||
FileConfiguration c = plugin.getConfig();
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
ResultSet rs;
|
||||
rs = AnuraCore.getSql().querySelect("SELECT name FROM players WHERE uuid LIKE '" + uuid.toString() + "'");
|
||||
if (rs == null) {
|
||||
if (c.getBoolean("is-main-lobby")) {
|
||||
event.getPlayer().kickPlayer("Please try again");
|
||||
} else {
|
||||
Core.kickToLobby(event.getPlayer());
|
||||
}
|
||||
event.setJoinMessage(null);
|
||||
return;
|
||||
}
|
||||
rs.last();
|
||||
if (rs.getRow() != 1) {
|
||||
/*Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
AnuraCore.getSql().queryUpdate("INSERT INTO players(`uuid`,`game`,`waiting`,`gameName`) VALUES('" + uuid.toString() + "','none','none','')");
|
||||
});*/
|
||||
}
|
||||
event.setJoinMessage(null);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
FlowerPots.refreshCache(event.getPlayer());
|
||||
FlowerPots.refreshPlayer(event.getPlayer());
|
||||
Data.disableCommandsAdventure.put(event.getPlayer(), false);
|
||||
Data.joinTime.put(event.getPlayer(), (int) (System.currentTimeMillis() / 1000));
|
||||
Data.aimTheWaterWins.put(event.getPlayer(), 0);
|
||||
Core.getLevel().loadLevel(event.getPlayer());
|
||||
});
|
||||
plugin.getFeatures().updateFeatures(event.getPlayer());
|
||||
String name = event.getPlayer().getName();
|
||||
if (Teleports.queuedLocs.containsKey(name)) {
|
||||
event.getPlayer().teleport(Teleports.queuedLocs.get(name));
|
||||
Teleports.queuedLocs.remove(name);
|
||||
} else if (c.getBoolean("on-join-to-spawn")) {
|
||||
Core.toSpawn(event.getPlayer());
|
||||
}
|
||||
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.util.Data;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
|
||||
public class PlayerKick implements Listener {
|
||||
|
||||
public PlayerKick(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
try {
|
||||
Data.disableCommandsAdventure.remove(event.getPlayer());
|
||||
if (plugin.getConfig().getBoolean("allow-stairs-sit")) {
|
||||
Core.endSitting(event.getPlayer());
|
||||
}
|
||||
event.setLeaveMessage(null);
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.FlowerPots;
|
||||
import de.anura.core.util.Data;
|
||||
import java.sql.ResultSet;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.material.Sign;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class PlayerMove implements Listener {
|
||||
|
||||
private final AnuraCore plugin;
|
||||
|
||||
public PlayerMove(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
try {
|
||||
Player p = event.getPlayer();
|
||||
Block block = event.getTo().clone().getBlock();
|
||||
Block under = block.getLocation().subtract(0, 1, 0).getBlock();
|
||||
|
||||
if (event.getTo().getY() <= -40 && plugin.getConfig().getBoolean("no-void-death")) {
|
||||
p.performCommand("spawn");
|
||||
} else if (block.getType().equals(Material.CARPET) && under.getType().equals(Material.SIGN_POST)) {
|
||||
p.setWalkSpeed(0.6F);
|
||||
} else if (block.getType().equals(Material.CARPET) && under.getType().equals(Material.ENDER_CHEST)) {
|
||||
double X = under.getLocation().getX();
|
||||
double Y = under.getLocation().getY();
|
||||
double Z = under.getLocation().getZ();
|
||||
String world = under.getLocation().getWorld().getName();
|
||||
String sql = "SELECT * FROM coreJumpers WHERE X = '" + (int) X + "' AND Y = '" + (int) Y + "' AND Z = '" + (int) Z + "' AND world = '" + world + "' AND type = 'high'";
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
ResultSet rs = AnuraCore.getSql().querySelect(sql);
|
||||
rs.last();
|
||||
if (rs.getRow() > 0) {
|
||||
p.setVelocity(new Vector(0, rs.getDouble("height"), 0));
|
||||
p.getWorld().spigot().playEffect(p.getLocation(), Effect.FIREWORKS_SPARK, 0, 0, (float) 0.1, (float) 0.1, (float) 0.1, (float) 0.3, 10, 1);
|
||||
}
|
||||
} catch(Throwable ex) {
|
||||
Errors.reportException(ex);
|
||||
}
|
||||
});
|
||||
p.setWalkSpeed(0.2F);
|
||||
} else if (block.getType().equals(Material.CARPET) && under.getType().equals(Material.RAILS)) {
|
||||
double X = under.getLocation().getX();
|
||||
double Y = under.getLocation().getY();
|
||||
double Z = under.getLocation().getZ();
|
||||
String world = under.getLocation().getWorld().getName();
|
||||
String sql = "SELECT * FROM coreJumpers WHERE X = '" + (int) X + "' AND Y = '" + (int) Y + "' AND Z = '" + (int) Z + "' AND world = '" + world + "' AND type = 'far'";
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
ResultSet rs = AnuraCore.getSql().querySelect(sql);
|
||||
rs.last();
|
||||
if (rs.getRow() > 0) {
|
||||
p.setVelocity(p.getLocation().getDirection().multiply(new Vector(rs.getDouble("height"), 1, rs.getDouble("height"))));
|
||||
p.setVelocity(p.getVelocity().setY(1.3));
|
||||
p.getWorld().spigot().playEffect(p.getLocation(), Effect.LAVA_POP, 0, 0, (float) 0.1, (float) 0.1, (float) 0.1, (float) 0.3, 10, 1);
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1, 1);
|
||||
}
|
||||
} catch(Throwable ex) {
|
||||
Errors.reportException(ex);
|
||||
}
|
||||
});
|
||||
p.setWalkSpeed(0.2F);
|
||||
} else {
|
||||
p.setWalkSpeed(0.2F);
|
||||
}
|
||||
Block sign = null;
|
||||
Block isSign = block.getLocation().getWorld().getBlockAt(block.getLocation().add(0, 1, 0));
|
||||
if (isSign.getType().equals(Material.WALL_SIGN)) {
|
||||
sign = isSign;
|
||||
} else if (block.getType().equals(Material.WALL_SIGN)) {
|
||||
sign = block;
|
||||
}
|
||||
if (sign != null && !event.getPlayer().hasPermission("core.rules.hideSign")) {
|
||||
Sign s = (Sign) sign.getState().getData();
|
||||
BlockFace bf = s.getFacing();
|
||||
if (bf.equals(BlockFace.EAST)) {
|
||||
event.getPlayer().setVelocity(new Vector(0.3, 0, 0));
|
||||
}
|
||||
if (bf.equals(BlockFace.WEST)) {
|
||||
event.getPlayer().setVelocity(new Vector(-0.3, 0, 0));
|
||||
}
|
||||
if (bf.equals(BlockFace.SOUTH)) {
|
||||
event.getPlayer().setVelocity(new Vector(0, 0, 0.3));
|
||||
}
|
||||
if (bf.equals(BlockFace.NORTH)) {
|
||||
event.getPlayer().setVelocity(new Vector(0, 0, -0.3));
|
||||
}
|
||||
}
|
||||
if (!Data.lastLoc.containsKey(p) || !Data.lastLoc.get(p).getWorld().equals(p.getLocation().getWorld()) || Data.lastLoc.get(p).distance(p.getLocation()) > 1) {
|
||||
FlowerPots.refreshPlayer(p);
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.API.Money;
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.util.Data;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class PlayerQuit implements Listener {
|
||||
|
||||
public PlayerQuit(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
try {
|
||||
if(event.getPlayer().getVehicle() != null){
|
||||
if(event.getPlayer().getVehicle().getType().equals(EntityType.BOAT)){
|
||||
Boat b = (Boat) event.getPlayer().getVehicle();
|
||||
b.remove();
|
||||
}
|
||||
}
|
||||
event.setQuitMessage(null);
|
||||
Core.endSitting(event.getPlayer());
|
||||
Data.disableCommandsAdventure.remove(event.getPlayer());
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Core.getMainClass(), () -> {
|
||||
Money.saveMoney(event.getPlayer());
|
||||
});
|
||||
Core.getLevel().update(event.getPlayer());
|
||||
Bukkit.getScoreboardManager().getMainScoreboard().resetScores(event.getPlayer());
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.util.Data;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Arrow;
|
||||
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;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.material.Stairs;
|
||||
|
||||
public class PlayerTeleport implements Listener {
|
||||
|
||||
public PlayerTeleport(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
if (Data.sittingPlayer.containsKey(event.getPlayer()) && !event.getCause().equals(TeleportCause.PLUGIN)) {
|
||||
if (event.getPlayer().isSneaking()) {
|
||||
Player P = event.getPlayer();
|
||||
Block b = Data.sittingBlocks.get(P);
|
||||
MaterialData md = b.getState().getData();
|
||||
if (md instanceof Stairs) {
|
||||
Stairs s = (Stairs) md;
|
||||
Location loc = b.getRelative(s.getFacing()).getLocation();
|
||||
if (!hasPlace(loc)) {
|
||||
for (BlockFace f : new BlockFace[] {BlockFace.SOUTH, BlockFace.WEST, BlockFace.NORTH, BlockFace.EAST}) {
|
||||
if (f == s.getFacing()) continue;
|
||||
if (hasPlace(b.getRelative(f).getLocation())) {
|
||||
loc = b.getRelative(f).getLocation();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
loc.add(0.5, 0, 0.5);
|
||||
Arrow a = Data.sittingPlayer.get(P);
|
||||
event.setTo(loc);
|
||||
P.setSneaking(false);
|
||||
a.remove();
|
||||
Data.sittingPlayer.remove(P);
|
||||
Data.sittingBlocks.remove(P);
|
||||
return;
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasPlace(Location loc) {
|
||||
return loc.getBlock().getType() == Material.AIR && loc.clone().add(0, 1, 0).getBlock().getType() == Material.AIR;
|
||||
}
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map.Entry;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
public class SignChange implements Listener {
|
||||
|
||||
public SignChange(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
try {
|
||||
if (event.getLine(0).endsWith("[Warp]")) {
|
||||
if (!event.getPlayer().hasPermission("core.signs.warp")) {
|
||||
event.setLine(0, ChatColor.STRIKETHROUGH + "[Warp]");
|
||||
event.setLine(1, ChatColor.RED + "You don't");
|
||||
event.setLine(2, ChatColor.RED + "have");
|
||||
event.setLine(3, ChatColor.RED + "Permission!");
|
||||
return;
|
||||
}
|
||||
if (event.getLine(1).endsWith("Warp")) {
|
||||
ResultSet rs = Core.getMySql().querySelect("SELECT name FROM coreWarps WHERE name = '" + event.getLine(2) + "'");
|
||||
rs.last();
|
||||
if (rs.getRow() == 0) {
|
||||
event.setLine(0, ChatColor.STRIKETHROUGH + "[Warp]");
|
||||
event.setLine(1, ChatColor.RED + "Der Warp");
|
||||
event.setLine(2, ChatColor.YELLOW + event.getLine(2) + ChatColor.RED + "exis-");
|
||||
event.setLine(3, ChatColor.RED + "tiert nicht!");
|
||||
} else {
|
||||
Location loc = event.getBlock().getLocation();
|
||||
int X = loc.getBlockX();
|
||||
int Y = loc.getBlockY();
|
||||
int Z = loc.getBlockZ();
|
||||
String world = loc.getWorld().getName();
|
||||
String server = plugin.getConfig().getString("server-name");
|
||||
Core.getMySql().queryUpdate("INSERT INTO coreWarpSigns(X,Y,Z,world,server,type,value,info) VALUES('" + X + "','" + Y + "','" + Z + "','" + world + "','" + server + "','warp','" + event.getLine(2) + "','" + event.getLine(3) + "')");
|
||||
event.setLine(0, "[" + ChatColor.GREEN + "Warp" + ChatColor.BLACK + "]");
|
||||
event.setLine(1, ChatColor.DARK_GRAY + "--------");
|
||||
event.setLine(2, ChatColor.AQUA + event.getLine(2));
|
||||
event.setLine(3, ChatColor.BLUE + event.getLine(3));
|
||||
Core.statusMsg(event.getPlayer(), "warpsign_created", true);
|
||||
}
|
||||
} else if (event.getLine(1).endsWith("Spawn")) {
|
||||
Location loc = event.getBlock().getLocation();
|
||||
int X = loc.getBlockX();
|
||||
int Y = loc.getBlockY();
|
||||
int Z = loc.getBlockZ();
|
||||
String world = loc.getWorld().getName();
|
||||
String server = plugin.getConfig().getString("server-name");
|
||||
Core.getMySql().queryUpdate("INSERT INTO coreWarpSigns(X,Y,Z,world,server,type,value,info) VALUES('" + X + "','" + Y + "','" + Z + "','" + world + "','" + server + "','spawn','none','" + event.getLine(3) + "')");
|
||||
event.setLine(0, ChatColor.DARK_GRAY + "---------");
|
||||
event.setLine(1, ChatColor.BLACK + "[" + ChatColor.GREEN + "Spawn" + ChatColor.BLACK + "]");
|
||||
event.setLine(2, ChatColor.DARK_GRAY + "---------");
|
||||
event.setLine(3, ChatColor.BLUE + event.getLine(3));
|
||||
Core.statusMsg(event.getPlayer(), "spawnsign_created", true);
|
||||
} else if (event.getLine(1).endsWith("Server")) {
|
||||
Location loc = event.getBlock().getLocation();
|
||||
int X = loc.getBlockX();
|
||||
int Y = loc.getBlockY();
|
||||
int Z = loc.getBlockZ();
|
||||
String world = loc.getWorld().getName();
|
||||
String server = event.getLine(2);
|
||||
String curServer = plugin.getConfig().getString("server-name");
|
||||
Core.getMySql().queryUpdate("INSERT INTO coreWarpSigns(X,Y,Z,world,server,type,value,info) VALUES('" + X + "','" + Y + "','" + Z + "','" + world + "','" + curServer + "','server','" + server + "','" + event.getLine(3) + "')");
|
||||
event.setLine(0, ChatColor.BLACK + "[" + ChatColor.GREEN + "Server" + ChatColor.BLACK + "]");
|
||||
event.setLine(1, ChatColor.GREEN + "--" + ChatColor.DARK_GRAY + "/" + ChatColor.GREEN + "--");
|
||||
event.setLine(2, ChatColor.AQUA + event.getLine(2));
|
||||
event.setLine(3, ChatColor.BLUE + event.getLine(3));
|
||||
Core.statusMsg(event.getPlayer(), "serversign_created", true);
|
||||
}
|
||||
} else {
|
||||
if (event.getPlayer().hasPermission("core.signs.chars")) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
String l = event.getLine(i);
|
||||
l = ChatColor.translateAlternateColorCodes('&', l);
|
||||
if (l.contains("%")) {
|
||||
String[] parts = l.split("%");
|
||||
ArrayList<Entry<String, String>> toReplace = new ArrayList<>();
|
||||
Boolean first = true;
|
||||
for (String s : parts) {
|
||||
if (!first) {
|
||||
String num = s.split(" ")[0];
|
||||
if (Core.isInteger(num)) {
|
||||
int number = Integer.valueOf(num);
|
||||
Entry<String, String> e = new SimpleEntry<>("%" + number, Character.toString((char) number));
|
||||
toReplace.add(e);
|
||||
}
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
for (Entry<String, String> entry : toReplace) {
|
||||
l = l.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
event.setLine(i, l);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Core;
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.AnuraVillager;
|
||||
import de.anura.core.Features;
|
||||
import de.anura.core.Features.Feature;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
|
||||
public class VillagerEvents implements Listener {
|
||||
|
||||
public VillagerEvents(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClick(PlayerInteractEntityEvent e) {
|
||||
Entity e1 = e.getRightClicked();
|
||||
if (!e1.getType().equals(EntityType.VILLAGER) || !e1.isValid()) return;
|
||||
Villager v = (Villager) e1;
|
||||
if (AnuraVillager.getByEntity(v) == null) return;
|
||||
AnuraVillager av = AnuraVillager.getByEntity(v);
|
||||
Feature f = av.getType().getFeature();
|
||||
Features fs = Core.getMainClass().getFeatures();
|
||||
Player P = e.getPlayer();
|
||||
if (fs.hasFeature(P, f)) {
|
||||
Core.statusMsg(P, "already_has_feature", Boolean.FALSE);
|
||||
return;
|
||||
}
|
||||
Core.getMySql().queryUpdate("INSERT INTO coreFeatures (playerId, featureId) VALUES ((SELECT id FROM players WHERE uuid='" + P.getUniqueId().toString() + "'),'"+f.getId()+"');");
|
||||
Core.statusMsg(P, "feature_unlocked_" + f.name().toLowerCase(), Boolean.TRUE);
|
||||
Core.updateFeatures(P);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(EntityDamageEvent e) {
|
||||
Entity en = e.getEntity();
|
||||
if (en.isValid() && e.getEntityType().equals(EntityType.VILLAGER)) {
|
||||
Villager ven = (Villager) en;
|
||||
if (AnuraVillager.getByEntity(ven) != null) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLoad(ChunkLoadEvent e) {
|
||||
AnuraVillager.addVillagers(e.getChunk().getEntities());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onUnload(ChunkUnloadEvent e) {
|
||||
AnuraVillager.removeVillagers(e.getChunk().getEntities());
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package de.anura.core.events;
|
||||
|
||||
import de.anura.core.API.Errors;
|
||||
import de.anura.core.AnuraCore;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||
|
||||
public class WeatherChange implements Listener {
|
||||
|
||||
public WeatherChange(AnuraCore plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWeatherChange(WeatherChangeEvent event) {
|
||||
try {
|
||||
if (event.toWeatherState() && plugin.getConfig().getBoolean("no-rain")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Errors.reportException(e);
|
||||
}
|
||||
}
|
||||
private final AnuraCore plugin;
|
||||
}
|
||||
17
src/de/anura/core/listeners/EntityDamage.java
Normal file
17
src/de/anura/core/listeners/EntityDamage.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package de.anura.core.listeners;
|
||||
|
||||
import de.anura.core.tools.Villagers;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
public class EntityDamage implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(EntityDamageEvent event) {
|
||||
if (!(event.getEntityType() == EntityType.VILLAGER)) return;
|
||||
if (Villagers.is((Villager) event.getEntity())) event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
38
src/de/anura/core/listeners/EntityFish.java
Normal file
38
src/de/anura/core/listeners/EntityFish.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package de.anura.core.listeners;
|
||||
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.AnuraThread;
|
||||
import de.anura.core.tools.Villagers;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class EntityFish implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerFish(PlayerFishEvent e) {
|
||||
Entity entity = e.getCaught();
|
||||
if (!e.getState().equals(PlayerFishEvent.State.CAUGHT_ENTITY) || entity == null) return;
|
||||
if (entity.getType() == EntityType.PLAYER) {
|
||||
e.setCancelled(true);
|
||||
e.getHook().remove();
|
||||
return;
|
||||
}
|
||||
if (entity.getType() == EntityType.VILLAGER) {
|
||||
Villager v = (Villager) entity;
|
||||
if (Villagers.is(v)) {
|
||||
Location loc = v.getLocation();
|
||||
AnuraThread.add(Bukkit.getScheduler().runTaskLater(AnuraCore.getInstance(), () -> {
|
||||
entity.setVelocity(new Vector(0, 0, 0));
|
||||
entity.teleport(loc);
|
||||
}, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
src/de/anura/core/listeners/InteractEntity.java
Normal file
20
src/de/anura/core/listeners/InteractEntity.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package de.anura.core.listeners;
|
||||
|
||||
import de.anura.core.tools.Villagers;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
public class InteractEntity implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEntityEvent event) {
|
||||
if (event.getRightClicked().getType() == EntityType.VILLAGER) {
|
||||
if (Villagers.doClick((Villager) event.getRightClicked(), event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
46
src/de/anura/core/listeners/InventoryEvent.java
Normal file
46
src/de/anura/core/listeners/InventoryEvent.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package de.anura.core.listeners;
|
||||
|
||||
import de.anura.core.tools.TownInventory;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class InventoryEvent implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInvClick(InventoryClickEvent event) {
|
||||
Inventory i = event.getView().getTopInventory();
|
||||
Player P = (Player) event.getWhoClicked();
|
||||
TownInventory inv = TownInventory.getOpenInv(P);
|
||||
if (inv == null) return;
|
||||
event.setCancelled(true);
|
||||
if (i == event.getClickedInventory()) {
|
||||
inv.checkInvClick(event.getSlot(), P, event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY);
|
||||
} else {
|
||||
inv.checkPlayerInvClick(P, event);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInvDrag(InventoryDragEvent event) {
|
||||
Player P = (Player) event.getWhoClicked();
|
||||
TownInventory inv = TownInventory.getOpenInv(P);
|
||||
if (inv == null) return;
|
||||
event.setCancelled(true);
|
||||
inv.checkInvClick(event.getInventorySlots().iterator().next(), P, false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInvClose(InventoryCloseEvent event) {
|
||||
Inventory i = event.getInventory();
|
||||
Player P = (Player) event.getPlayer();
|
||||
TownInventory inv = TownInventory.getOpenInv(P);
|
||||
if (inv == null) return;
|
||||
inv.close(P);
|
||||
}
|
||||
}
|
||||
66
src/de/anura/core/listeners/JoinEvent.java
Normal file
66
src/de/anura/core/listeners/JoinEvent.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package de.anura.core.listeners;
|
||||
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.AnuraThread;
|
||||
import de.anura.core.Money;
|
||||
import de.anura.core.database.DB;
|
||||
import de.anura.core.events.AnuraLeaveEvent;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
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.permissions.PermissionAttachment;
|
||||
|
||||
public class JoinEvent implements Listener {
|
||||
|
||||
private static final Map<Player, PermissionAttachment> attachments = new WeakHashMap<>();
|
||||
|
||||
@EventHandler(priority=EventPriority.LOWEST)
|
||||
public void onPlayerJoinEarly(PlayerJoinEvent event) {
|
||||
try {
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
ResultSet rs = DB.querySelect("SELECT id FROM players WHERE uuid = ?", uuid.toString());
|
||||
if (rs.next()) {
|
||||
DB.queryUpdate("UPDATE players SET name = ? WHERE id = ?", event.getPlayer().getName(), rs.getInt("id"));
|
||||
} else {
|
||||
DB.queryUpdate("INSERT INTO players (uuid, name, money) VALUES (?, ?, ?)", uuid.toString(), event.getPlayer().getName(), Money.INITIAL_MONEY);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(JoinEvent.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
//event.setJoinMessage(null);
|
||||
addAttachment(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(AnuraLeaveEvent event) {
|
||||
if (attachments.containsKey(event.getPlayer())) {
|
||||
event.getPlayer().removeAttachment(attachments.remove(event.getPlayer()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void addAttachment(Player P) {
|
||||
AnuraThread.queueSync(() -> {
|
||||
PermissionAttachment att = P.addAttachment(AnuraCore.getInstance());
|
||||
attachments.put(P, att);
|
||||
att.setPermission("minecraft.command.me", false);
|
||||
att.setPermission("minecraft.command.tell", false);
|
||||
att.setPermission("minecraft.command.help", false);
|
||||
att.setPermission("bukkit.command.version", false);
|
||||
att.setPermission("bukkit.command.plugins", false);
|
||||
att.setPermission("bukkit.command.help", false);
|
||||
});
|
||||
}
|
||||
}
|
||||
38
src/de/anura/core/listeners/LeaveEvent.java
Normal file
38
src/de/anura/core/listeners/LeaveEvent.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package de.anura.core.listeners;
|
||||
|
||||
import de.anura.core.events.AnuraLeaveEvent;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class LeaveEvent implements Listener {
|
||||
|
||||
private final Set<Player> hasLeft = Collections.newSetFromMap(new WeakHashMap<>());
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
//event.setQuitMessage(null);
|
||||
disconnect(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@SuppressWarnings("null")
|
||||
public void onKick(PlayerKickEvent event) {
|
||||
//event.setLeaveMessage(null);
|
||||
// TODO: Implement better join/leave msgs
|
||||
disconnect(event.getPlayer());
|
||||
}
|
||||
|
||||
private void disconnect(Player P) {
|
||||
if (hasLeft.contains(P)) return;
|
||||
hasLeft.add(P);
|
||||
AnuraLeaveEvent ev = new AnuraLeaveEvent(P);
|
||||
Bukkit.getPluginManager().callEvent(ev);
|
||||
}
|
||||
}
|
||||
28
src/de/anura/core/listeners/PlayerChat.java
Normal file
28
src/de/anura/core/listeners/PlayerChat.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package de.anura.core.listeners;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
public class PlayerChat implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
// try {
|
||||
// TODO: Correct muting implementation
|
||||
// ResultSet rs = DB.querySelect("SELECT muted FROM players WHERE uuid = ?", event.getPlayer().getUniqueId().toString());
|
||||
// rs.first();
|
||||
// if (rs.getBoolean("muted")) {
|
||||
// event.setCancelled(true);
|
||||
// Msg.send(event.getPlayer(), AnuraCore.getInstance(), MsgType.ERROR, "Du bist gemuted!");
|
||||
// return;
|
||||
// }
|
||||
if (event.isAsynchronous()) {
|
||||
event.setFormat("%s" + ChatColor.GRAY + ":" + ChatColor.WHITE + " %s");
|
||||
}
|
||||
// } catch (IllegalFormatException | SQLException ex) {
|
||||
// Logger.getLogger(PlayerChat.class.getName()).log(Level.SEVERE, null, ex);
|
||||
// }
|
||||
}
|
||||
}
|
||||
61
src/de/anura/core/listeners/PotionEvents.java
Normal file
61
src/de/anura/core/listeners/PotionEvents.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package de.anura.core.listeners;
|
||||
|
||||
import de.anura.core.events.AnuraLeaveEvent;
|
||||
import de.anura.core.tools.Potions;
|
||||
import de.anura.core.tools.Villagers;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent;
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent.Action;
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent.Cause;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
||||
public class PotionEvents implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPotionChange(EntityPotionEffectEvent event) {
|
||||
if (event.getEntityType() == EntityType.VILLAGER && event.getAction() == Action.ADDED && event.getCause() != Cause.COMMAND) {
|
||||
if (Villagers.is((Villager) event.getEntity())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (event.getEntityType() != EntityType.PLAYER) return;
|
||||
if (event.getCause() == Cause.PLUGIN) return;
|
||||
Player P = (Player) event.getEntity();
|
||||
switch (event.getAction()) {
|
||||
case ADDED:
|
||||
case CHANGED:
|
||||
Potions.addNativePotion(P, event.getNewEffect());
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
case REMOVED:
|
||||
Potions.removeNativePotion(P, event.getOldEffect(), event.getCause() != Cause.EXPIRATION);
|
||||
break;
|
||||
case CLEARED:
|
||||
Potions.removeNativePotion(P, event.getOldEffect(), true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.LOWEST)
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
Potions.join(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.LOWEST)
|
||||
public void onDisconnect(AnuraLeaveEvent event) {
|
||||
Potions.logout(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRespawn(PlayerRespawnEvent event) {
|
||||
Potions.refresh(event.getPlayer());
|
||||
}
|
||||
}
|
||||
51
src/de/anura/core/msg/Message.java
Normal file
51
src/de/anura/core/msg/Message.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package de.anura.core.msg;
|
||||
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.minecraft.server.v1_14_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_14_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutTitle;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutTitle.EnumTitleAction;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class Message {
|
||||
|
||||
public static void sendActionBar(Player P, String text) {
|
||||
P.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(text));
|
||||
}
|
||||
|
||||
public static void sendActionBar(String text) {
|
||||
Bukkit.getOnlinePlayers().forEach((P) -> { sendActionBar(P, text); });
|
||||
}
|
||||
|
||||
public static void resetTitle(Player P) {
|
||||
PacketPlayOutTitle reset = new PacketPlayOutTitle(EnumTitleAction.RESET, IChatBaseComponent.ChatSerializer.a(""));
|
||||
((CraftPlayer) P).getHandle().playerConnection.sendPacket(reset);
|
||||
}
|
||||
|
||||
public static void configTitle(Player P, int fadeIn, int stay, int fadeOut) {
|
||||
PacketPlayOutTitle times = new PacketPlayOutTitle(fadeIn, stay, fadeOut);
|
||||
EntityPlayer pl = ((CraftPlayer) P).getHandle();
|
||||
pl.playerConnection.sendPacket(times);
|
||||
}
|
||||
|
||||
public static void sendTitle(Player P, String title, String subtitle) {
|
||||
IChatBaseComponent titleComp = IChatBaseComponent.ChatSerializer.a("{\"text\":\"" + title + "\"}");
|
||||
IChatBaseComponent subtitleComp = IChatBaseComponent.ChatSerializer.a("{\"text\":\"" + subtitle + "\"}");
|
||||
PacketPlayOutTitle titlePack = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleComp);
|
||||
PacketPlayOutTitle subtitlePack = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, subtitleComp);
|
||||
EntityPlayer pl = ((CraftPlayer) P).getHandle();
|
||||
pl.playerConnection.sendPacket(subtitlePack);
|
||||
pl.playerConnection.sendPacket(titlePack);
|
||||
}
|
||||
|
||||
public static void sendTitle(String title, String subtitle) {
|
||||
Bukkit.getOnlinePlayers().forEach((P) -> { sendTitle(P, title, subtitle); });
|
||||
}
|
||||
|
||||
public static void broadcast(String msg) {
|
||||
Bukkit.broadcastMessage(msg);
|
||||
}
|
||||
}
|
||||
206
src/de/anura/core/msg/Messenger.java
Normal file
206
src/de/anura/core/msg/Messenger.java
Normal file
@@ -0,0 +1,206 @@
|
||||
package de.anura.core.msg;
|
||||
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.AnuraThread;
|
||||
import de.anura.core.commands.Answer;
|
||||
import de.anura.core.database.DB;
|
||||
import de.anura.core.msg.Msg.MsgType;
|
||||
import de.anura.core.util.UUIDManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class Messenger {
|
||||
|
||||
private static final Map<Player, Queue<MessengerMsg>> queue = new HashMap<>();
|
||||
|
||||
public static boolean send(String from, UUID to, String msg) {
|
||||
return receiveMsg(from, to, msg);
|
||||
}
|
||||
|
||||
public static boolean send(UUID from, UUID to, String msg) {
|
||||
return receiveMsg(from, to, msg);
|
||||
}
|
||||
|
||||
public static boolean receiveMsg(String from, UUID to, String msg) {
|
||||
if (to == null) return false;
|
||||
Player P = Bukkit.getPlayer(to);
|
||||
if (P != null) {
|
||||
P.sendMessage(from + ChatColor.GRAY + " -> " + P.getDisplayName() + ChatColor.GRAY + ": " + ChatColor.RESET + msg);
|
||||
saveToMailbox(to, from, msg, true);
|
||||
return true;
|
||||
} else {
|
||||
saveToMailbox(to, from, msg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean receiveMsg(UUID from, UUID to, String msg) {
|
||||
Player toP = Bukkit.getPlayer(to);
|
||||
if (toP != null) {
|
||||
Answer.chatPartners.put(toP, from);
|
||||
Player fromP = Bukkit.getPlayer(from);
|
||||
if (fromP != null) {
|
||||
Answer.chatPartners.put(fromP, to);
|
||||
toP.sendMessage(fromP.getDisplayName() + ChatColor.GRAY + " -> " + toP.getDisplayName() + ChatColor.GRAY + ": " + ChatColor.RESET + msg);
|
||||
} else {
|
||||
UUIDManager.getName(from, (name) -> toP.sendMessage(name + ChatColor.GRAY + " -> " + toP.getDisplayName() + ChatColor.GRAY + ": " + ChatColor.RESET + msg));
|
||||
}
|
||||
saveToMailbox(to, from, msg, true);
|
||||
return true;
|
||||
} else {
|
||||
saveToMailbox(to, from, msg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveToMailbox(UUID owner, String from, String msg) {
|
||||
saveToMailbox(owner, from, msg, false);
|
||||
}
|
||||
|
||||
private static void saveToMailbox(UUID owner, UUID from, String msg) {
|
||||
saveToMailbox(owner, from, msg, false);
|
||||
}
|
||||
|
||||
private static void saveToMailbox(UUID owner, UUID from, String msg, boolean read) {
|
||||
String name = null;
|
||||
Player tempPlayer = Bukkit.getPlayer(from);
|
||||
if (tempPlayer != null) {
|
||||
name = tempPlayer.getDisplayName();
|
||||
}
|
||||
DB.queryUpdate(true, "INSERT INTO playermailbox (toId, sender, fromId, msg, isRead, time) VALUES ((SELECT id FROM players WHERE uuid = ?), ?, (SELECT id FROM players WHERE uuid = ?), ?, ?, ?)",
|
||||
owner.toString(), name, from.toString(), msg, read, (int) (System.currentTimeMillis() / 1000));
|
||||
}
|
||||
|
||||
private static void saveToMailbox(UUID owner, String from, String msg, boolean read) {
|
||||
DB.queryUpdate(true, "INSERT INTO playermailbox (toId, sender, msg, isRead, time) VALUES ((SELECT id FROM players WHERE uuid = ?), ?, ?, ?, ?)", owner.toString(), from, msg, read, (int) (System.currentTimeMillis() / 1000));
|
||||
}
|
||||
|
||||
public static void checkMsgs(Player P) {
|
||||
AnuraThread.async(() -> {
|
||||
ResultSet rs = DB.querySelect("SELECT count(*) as count FROM playermailbox WHERE isRead = 0 AND toId = (SELECT id FROM players WHERE uuid = ?)", P.getUniqueId().toString());
|
||||
try {
|
||||
if (!rs.next()) return;
|
||||
int count = rs.getInt("count");
|
||||
if (count == 0) return;
|
||||
Msg.send(P, AnuraCore.getInstance(), MsgType.INFO, "Du hast %i neue Nachricht" + (count > 1 ? "en" : "") + "! %s", count, "(/msg read)");
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(Messenger.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void readMsgs(Player P, boolean onlyUnread, int page) {
|
||||
if (page < 1) return;
|
||||
AnuraThread.async(() -> {
|
||||
String read = (onlyUnread ? "isRread = 0 AND " : "");
|
||||
ResultSet num = DB.querySelect("SELECT count(*) as num FROM playermailbox WHERE " + read + "toId = (SELECT id FROM players WHERE uuid = ?)", P.getUniqueId().toString());
|
||||
try {
|
||||
if (!num.next() || num.getInt("num") == 0) {
|
||||
Msg.send(P, AnuraCore.getInstance(), MsgType.INFO, "Keine " + (onlyUnread ? "ungelesenen " : "") + "Nachrichten!");
|
||||
return;
|
||||
}
|
||||
int perPage = 9;
|
||||
ResultSet rs = DB.querySelect("SELECT players.uuid as fromP, sender, msg, time, playermailbox.id as msgid FROM playermailbox "
|
||||
+ "LEFT JOIN players ON players.id = playermailbox.fromId "
|
||||
+ "WHERE " + read + "toId = (SELECT id FROM players WHERE uuid = ?) ORDER BY time DESC LIMIT ? OFFSET ?",
|
||||
P.getUniqueId().toString(), perPage, (page - 1) * perPage);
|
||||
if (!rs.last()) {
|
||||
Msg.send(P, AnuraCore.getInstance(), MsgType.INFO, "Keine " + (onlyUnread ? "ungelesenen " : "") + "Nachrichten!");
|
||||
return;
|
||||
}
|
||||
int lastTime = rs.getInt("time");
|
||||
int lastId = rs.getInt("msgid");
|
||||
rs.first();
|
||||
int firstTime = rs.getInt("time");
|
||||
int firstId = rs.getInt("msgid");
|
||||
DB.queryUpdate("UPDATE playermailbox SET isRead = 1 WHERE " + read + "toId = (SELECT id FROM players WHERE uuid = ?) "
|
||||
+ "AND time BETWEEN ? AND ? AND id BETWEEN ? AND ? ORDER BY time DESC LIMIT ?",
|
||||
P.getUniqueId().toString(), lastTime, firstTime, lastId, firstId, perPage);
|
||||
rs.beforeFirst();
|
||||
int count = 0;
|
||||
while (rs.next()) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTimeInMillis((long) rs.getInt("time") * 1000);
|
||||
Calendar now = Calendar.getInstance();
|
||||
String time;
|
||||
if (c.get(Calendar.DAY_OF_YEAR) == now.get(Calendar.DAY_OF_YEAR) && c.get(Calendar.YEAR) == now.get(Calendar.YEAR)) {
|
||||
String hour = String.valueOf(c.get(Calendar.HOUR_OF_DAY));
|
||||
hour = hour.length() == 1 ? "0" + hour : hour;
|
||||
String min = String.valueOf(c.get(Calendar.MINUTE));
|
||||
min = min.length() == 1 ? "0" + min : min;
|
||||
time = hour + ":" + min;
|
||||
} else {
|
||||
time = c.get(Calendar.DAY_OF_MONTH) + "." + (c.get(Calendar.MONTH) + 1) + "." + c.get(Calendar.YEAR);
|
||||
}
|
||||
count++;
|
||||
String msg = rs.getString("msg");
|
||||
UUID fromUU = rs.getString("fromP") == null ? null : UUID.fromString(rs.getString("fromP"));
|
||||
if (!queue.containsKey(P)) queue.put(P, new ConcurrentLinkedQueue<>());
|
||||
queue.get(P).add(new MessengerMsg(fromUU, rs.getString("from"), time, msg, P));
|
||||
}
|
||||
while (!queue.get(P).isEmpty()) {
|
||||
queue.get(P).poll().send();
|
||||
}
|
||||
if (count > 0) Msg.send(P, AnuraCore.getInstance(), MsgType.INFO, "Seite %i von %i", page, (int) Math.ceil((double) num.getInt("num") / perPage));
|
||||
else Msg.send(P, AnuraCore.getInstance(), MsgType.INFO, "Keine " + (onlyUnread ? "ungelesenen " : "") + "Nachrichten!");
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(Messenger.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void deleteMsgs(Player P) {
|
||||
AnuraThread.async(() -> {
|
||||
DB.queryUpdate("DELETE FROM playermailbox WHERE toId = (SELECT id FROM players WHERE uuid = ?)", P.getUniqueId().toString());
|
||||
Msg.send(P, AnuraCore.getInstance(), MsgType.SUCCESS, "Nachrichten gelöscht!");
|
||||
});
|
||||
}
|
||||
|
||||
private static class MessengerMsg {
|
||||
|
||||
private String resolved = null;
|
||||
private final String time, msg;
|
||||
private final Player to;
|
||||
|
||||
@SuppressWarnings("null")
|
||||
MessengerMsg(UUID fromUU, String from, String time, String msg, Player to) {
|
||||
this.time = time;
|
||||
this.msg = msg;
|
||||
this.to = to;
|
||||
if (fromUU == null) {
|
||||
resolved = from;
|
||||
} else if (Bukkit.getPlayer(fromUU) != null) {
|
||||
resolved = Bukkit.getPlayer(fromUU).getDisplayName();
|
||||
} else if (from != null) {
|
||||
resolved = from;
|
||||
} else {
|
||||
UUIDManager.getName(fromUU, (name) -> {
|
||||
resolved = name;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("SleepWhileInLoop")
|
||||
public void send() {
|
||||
while (resolved == null) {
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.getLogger(Messenger.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
to.sendMessage(ChatColor.DARK_GRAY + "[" + time + "] " + ChatColor.RESET + resolved + ChatColor.GRAY + " -> " + to.getDisplayName() + ChatColor.GRAY + ": " + ChatColor.RESET + msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
179
src/de/anura/core/msg/Msg.java
Normal file
179
src/de/anura/core/msg/Msg.java
Normal file
@@ -0,0 +1,179 @@
|
||||
package de.anura.core.msg;
|
||||
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.Money;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public abstract class Msg {
|
||||
|
||||
private static final HashMap<Plugin, PluginData> plugins = new HashMap<>();
|
||||
|
||||
public static void register(Plugin plugin, String name, PluginType type) {
|
||||
plugins.put(plugin, new PluginData(name, type));
|
||||
}
|
||||
|
||||
public static void noPerms(CommandSender sender) {
|
||||
send(sender, AnuraCore.getInstance(), MsgType.ERROR, "Du hast keine Berechtigung diesen Befehl auszuführen!");
|
||||
}
|
||||
|
||||
public static void send(Plugin plugin, MsgType type, String msg, Object... data) {
|
||||
if (!plugins.containsKey(plugin)) {
|
||||
throw new RuntimeException("Plugin has to be registered (Msg::register)!");
|
||||
}
|
||||
send(plugins.get(plugin), type, msg, data);
|
||||
}
|
||||
|
||||
public static void send(PluginData pData, MsgType type, String msg, Object... data) {
|
||||
String message = getMsg(pData, type, false, msg, data);
|
||||
Message.broadcast(message);
|
||||
}
|
||||
|
||||
public static void send(CommandSender sender, Plugin plugin, MsgType type, String msg, Object... data) {
|
||||
if (!plugins.containsKey(plugin)) {
|
||||
throw new RuntimeException("Plugin has to be registered (Msg::register)!");
|
||||
}
|
||||
send(sender, plugins.get(plugin), type, msg, data);
|
||||
}
|
||||
|
||||
public static void send(CommandSender sender, PluginData pData, MsgType type, String msg, Object... data) {
|
||||
sender.sendMessage(getMsg(pData, type, false, msg, data));
|
||||
}
|
||||
|
||||
public static void send(UUID uuid, Plugin plugin, MsgType type, String msg, Object... data) {
|
||||
if (!plugins.containsKey(plugin)) {
|
||||
throw new RuntimeException("Plugin has to be registered (Msg::register)!");
|
||||
}
|
||||
send(uuid, plugins.get(plugin), type, msg, data);
|
||||
}
|
||||
|
||||
public static void send(UUID uuid, PluginData pData, MsgType type, String msg, Object... data) {
|
||||
send(uuid, getPrefix(pData, true), getMsg(pData, type, true, msg, data));
|
||||
}
|
||||
|
||||
private static void send(UUID uuid, String prefix, String msg) {
|
||||
Messenger.send(prefix, uuid, msg);
|
||||
}
|
||||
|
||||
public static String getMsg(Plugin plugin, MsgType type, boolean noPrefix, String msg, Object... data) {
|
||||
if (!plugins.containsKey(plugin)) {
|
||||
throw new RuntimeException("Plugin has to be registered (Msg::register)!");
|
||||
}
|
||||
return getMsg(plugins.get(plugin), type, noPrefix, msg, data);
|
||||
}
|
||||
|
||||
public static String getMsg(PluginData pData, MsgType type, boolean noPrefix, String msg, Object... data) {
|
||||
ChatColor baseColor = type.getColor(pData.getType());
|
||||
return (noPrefix ? "" : getPrefix(pData, false)) + baseColor + buildValues(baseColor, msg, data);
|
||||
}
|
||||
|
||||
private static String buildValues(ChatColor baseColor, String msg, Object... data) {
|
||||
if (data.length == 0) return msg;
|
||||
String finalMsg = "";
|
||||
int dataAt = 0;
|
||||
boolean hadChar = false;
|
||||
boolean hadAll = false;
|
||||
for (char c : msg.toCharArray()) {
|
||||
if (!hadAll && hadChar) {
|
||||
hadChar = false;
|
||||
switch (c) {
|
||||
case 's':
|
||||
finalMsg += ChatColor.BLUE + String.valueOf(data[dataAt]) + baseColor;
|
||||
break;
|
||||
case 'i':
|
||||
finalMsg += ChatColor.GOLD + String.valueOf(data[dataAt]) + baseColor;
|
||||
break;
|
||||
case 'm':
|
||||
finalMsg += ChatColor.GOLD + String.valueOf(data[dataAt]) + " " + Money.CURRENCY + baseColor;
|
||||
break;
|
||||
default:
|
||||
finalMsg += "%" + c;
|
||||
continue;
|
||||
}
|
||||
dataAt++;
|
||||
if (data.length == dataAt) hadAll = true;
|
||||
} else if (!hadAll && c == '%') {
|
||||
hadChar = true;
|
||||
} else {
|
||||
finalMsg += c;
|
||||
}
|
||||
}
|
||||
return finalMsg;
|
||||
}
|
||||
|
||||
public static String getPrefix(Plugin plugin, boolean shortPrefix) {
|
||||
if (!plugins.containsKey(plugin)) {
|
||||
throw new RuntimeException("Plugin has to be registered (Msg::register)!");
|
||||
}
|
||||
return getPrefix(plugins.get(plugin), shortPrefix);
|
||||
}
|
||||
|
||||
public static String getPrefix(PluginData data, boolean shortPrefix) {
|
||||
if (shortPrefix) {
|
||||
return data.getType().getColor() + data.getName();
|
||||
} else {
|
||||
if (data.getType() != PluginType.GAMEPLAY) {
|
||||
return ChatColor.GRAY + "[" + data.getType().getColor() + data.getName() + ChatColor.GRAY + "] ";
|
||||
} else {
|
||||
return data.getType().getColor() + data.getName() + ChatColor.GRAY + "> ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static enum PluginType {
|
||||
SYSTEM(ChatColor.RED),
|
||||
ADMIN(ChatColor.DARK_PURPLE),
|
||||
GAMEPLAY(ChatColor.DARK_AQUA);
|
||||
|
||||
private PluginType(ChatColor color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
private final ChatColor color;
|
||||
|
||||
public ChatColor getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum MsgType {
|
||||
SUCCESS(ChatColor.GREEN, ChatColor.DARK_GREEN),
|
||||
ERROR(ChatColor.RED, ChatColor.RED),
|
||||
INFO(ChatColor.YELLOW, ChatColor.AQUA),
|
||||
SPECIAL(ChatColor.LIGHT_PURPLE, ChatColor.LIGHT_PURPLE),
|
||||
CRITICAL(ChatColor.DARK_RED, ChatColor.DARK_RED);
|
||||
|
||||
private final ChatColor systemColor, gameplayColor;
|
||||
|
||||
private MsgType(ChatColor systemColor, ChatColor gameplayColor) {
|
||||
this.gameplayColor = gameplayColor;
|
||||
this.systemColor = systemColor;
|
||||
}
|
||||
|
||||
public ChatColor getColor(PluginType type) {
|
||||
return type == PluginType.GAMEPLAY ? gameplayColor : systemColor;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PluginData {
|
||||
|
||||
private final String name;
|
||||
private final PluginType type;
|
||||
|
||||
public PluginData(String name, PluginType type) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public PluginType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
}
|
||||
99
src/de/anura/core/selections/CuboidSelection.java
Normal file
99
src/de/anura/core/selections/CuboidSelection.java
Normal file
@@ -0,0 +1,99 @@
|
||||
package de.anura.core.selections;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
public class CuboidSelection extends Selection {
|
||||
|
||||
public CuboidSelection(Location corner1, Location corner2) {
|
||||
locations.add(corner1);
|
||||
locations.add(corner2);
|
||||
}
|
||||
|
||||
public CuboidSelection(Block middleBlock, int radius) {
|
||||
Validate.notNull(middleBlock);
|
||||
Block b1 = middleBlock.getRelative(BlockFace.DOWN, radius).getRelative(BlockFace.NORTH_WEST, radius);
|
||||
Block b2 = middleBlock.getRelative(BlockFace.UP, radius).getRelative(BlockFace.SOUTH_EAST, radius);
|
||||
locations.add(b1.getLocation());
|
||||
locations.add(b2.getLocation());
|
||||
}
|
||||
|
||||
public Location getMinCorner() {
|
||||
updateMinMax();
|
||||
return min.toLocation(getWorld());
|
||||
}
|
||||
|
||||
public Location getMaxCorner() {
|
||||
updateMinMax();
|
||||
return max.toLocation(getWorld());
|
||||
}
|
||||
|
||||
public void setCorner1(Location b) {
|
||||
locations.set(0, b);
|
||||
}
|
||||
|
||||
public void setCorner2(Location b) {
|
||||
locations.set(1, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeID() {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean expand(int size, BlockFace bf) {
|
||||
Location minLoc = getMinCorner(), maxLoc = getMaxCorner();
|
||||
switch (bf) {
|
||||
case DOWN:
|
||||
minLoc.setY(minLoc.getY() - size);
|
||||
break;
|
||||
|
||||
case NORTH:
|
||||
minLoc.setX(minLoc.getX() - size);
|
||||
break;
|
||||
|
||||
case EAST:
|
||||
minLoc.setZ(minLoc.getZ() + size);
|
||||
break;
|
||||
|
||||
case UP:
|
||||
maxLoc.setY(maxLoc.getY() + size);
|
||||
break;
|
||||
|
||||
case SOUTH:
|
||||
maxLoc.setX(maxLoc.getX() + size);
|
||||
break;
|
||||
|
||||
case WEST:
|
||||
maxLoc.setZ(maxLoc.getZ() + size);
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
setCorner1(minLoc);
|
||||
setCorner2(maxLoc);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(BlockVector bv) {
|
||||
updateMinMax();
|
||||
int X = bv.getBlockX();
|
||||
int Y = bv.getBlockY();
|
||||
int Z = bv.getBlockZ();
|
||||
if ((X >= min.getX())
|
||||
&& (X <= max.getX())
|
||||
&& (Y >= min.getY())
|
||||
&& (Y <= max.getY())
|
||||
&& (Z >= min.getZ())
|
||||
&& (Z <= max.getZ())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
110
src/de/anura/core/selections/PolygonSelection.java
Normal file
110
src/de/anura/core/selections/PolygonSelection.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package de.anura.core.selections;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PolygonSelection extends Selection {
|
||||
|
||||
public PolygonSelection(List<Location> locations) {
|
||||
this.locations = locations;
|
||||
}
|
||||
|
||||
public void addLocation(Location loc) {
|
||||
this.locations.add(loc);
|
||||
}
|
||||
|
||||
public List<Location> getLocations() {
|
||||
return locations;
|
||||
}
|
||||
|
||||
public void setLocations(ArrayList<Location> locations) {
|
||||
this.locations = locations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeID() {
|
||||
return "polygon2d";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean expand(int size, BlockFace bf) {
|
||||
Location loc = locations.get(0);
|
||||
switch (bf) {
|
||||
case DOWN:
|
||||
loc.setY(loc.getY() - size);
|
||||
break;
|
||||
|
||||
case UP:
|
||||
loc.setY(loc.getY() + size);
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(BlockVector bv) {
|
||||
updateMinMax();
|
||||
int targetX = bv.getBlockX(); // Width
|
||||
int targetY = bv.getBlockY(); // Height
|
||||
int targetZ = bv.getBlockZ(); // Depth
|
||||
|
||||
if (targetY < min.getY() || targetY > max.getY()) {
|
||||
return false;
|
||||
}
|
||||
//Quick and dirty check.
|
||||
if (targetX < min.getBlockX() || targetX > max.getBlockX() || targetZ < min.getBlockZ() || targetZ > max.getBlockZ()) {
|
||||
return false;
|
||||
}
|
||||
boolean inside = false;
|
||||
int npoints = locations.size();
|
||||
int xNew, zNew;
|
||||
int xOld, zOld;
|
||||
int x1, z1;
|
||||
int x2, z2;
|
||||
long crossproduct;
|
||||
int i;
|
||||
|
||||
xOld = locations.get(npoints - 1).getBlockX();
|
||||
zOld = locations.get(npoints - 1).getBlockZ();
|
||||
|
||||
for (i = 0; i < npoints; i++) {
|
||||
xNew = locations.get(i).getBlockX();
|
||||
zNew = locations.get(i).getBlockZ();
|
||||
//Check for corner
|
||||
if (xNew == targetX && zNew == targetZ) {
|
||||
return true;
|
||||
}
|
||||
if (xNew > xOld) {
|
||||
x1 = xOld;
|
||||
x2 = xNew;
|
||||
z1 = zOld;
|
||||
z2 = zNew;
|
||||
} else {
|
||||
x1 = xNew;
|
||||
x2 = xOld;
|
||||
z1 = zNew;
|
||||
z2 = zOld;
|
||||
}
|
||||
if (x1 <= targetX && targetX <= x2) {
|
||||
crossproduct = ((long) targetZ - (long) z1) * (long) (x2 - x1)
|
||||
- ((long) z2 - (long) z1) * (long) (targetX - x1);
|
||||
if (crossproduct == 0) {
|
||||
if ((z1 <= targetZ) == (targetZ <= z2)) return true; // on edge
|
||||
} else if (crossproduct < 0 && (x1 != targetX)) {
|
||||
inside = !inside;
|
||||
}
|
||||
}
|
||||
xOld = xNew;
|
||||
zOld = zNew;
|
||||
}
|
||||
|
||||
return inside;
|
||||
}
|
||||
}
|
||||
212
src/de/anura/core/selections/Selection.java
Normal file
212
src/de/anura/core/selections/Selection.java
Normal file
@@ -0,0 +1,212 @@
|
||||
package de.anura.core.selections;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
public abstract class Selection {
|
||||
|
||||
protected BlockVector min, max;
|
||||
protected List<Location> locations = new ArrayList<>();
|
||||
|
||||
public List<BlockVector> getBlockVectors() {
|
||||
ArrayList<BlockVector> returnArray = new ArrayList<>();
|
||||
locations.forEach(location -> returnArray.add(location.toVector().toBlockVector()));
|
||||
return returnArray;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return locations.get(0).getWorld();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.locations = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void clear(Location loc) {
|
||||
this.locations = new ArrayList<>();
|
||||
locations.add(loc);
|
||||
}
|
||||
|
||||
public abstract boolean expand(int size, BlockFace bf);
|
||||
|
||||
public boolean expandVert() {
|
||||
return (expand(255, BlockFace.UP) && expand(255, BlockFace.DOWN));
|
||||
}
|
||||
|
||||
public abstract boolean contains(BlockVector bv);
|
||||
|
||||
public boolean contains(Location loc) {
|
||||
return contains(loc.toVector().toBlockVector());
|
||||
}
|
||||
|
||||
public int getCornerCount() {
|
||||
final int[] count = {0};
|
||||
locations.stream().filter(location -> location != null).forEach(location -> count[0]++);
|
||||
return count[0];
|
||||
}
|
||||
|
||||
public void updateMinMax() {
|
||||
int xMin = Integer.MAX_VALUE;
|
||||
int xMax = Integer.MIN_VALUE;
|
||||
int yMin = Integer.MAX_VALUE;
|
||||
int yMax = Integer.MIN_VALUE;
|
||||
int zMin = Integer.MAX_VALUE;
|
||||
int zMax = Integer.MIN_VALUE;
|
||||
for (Location loc : locations) {
|
||||
BlockVector vector = loc.toVector().toBlockVector();
|
||||
if (vector.getBlockX() < xMin) {
|
||||
xMin = vector.getBlockX();
|
||||
}
|
||||
if (vector.getBlockX() > xMax) {
|
||||
xMax = vector.getBlockX();
|
||||
}
|
||||
|
||||
if (vector.getBlockY() < yMin) {
|
||||
yMin = vector.getBlockY();
|
||||
}
|
||||
if (vector.getBlockY() > yMax) {
|
||||
yMax = vector.getBlockY();
|
||||
}
|
||||
|
||||
if (vector.getBlockZ() < zMin) {
|
||||
zMin = vector.getBlockZ();
|
||||
}
|
||||
if (vector.getBlockZ() > zMax) {
|
||||
zMax = vector.getBlockZ();
|
||||
}
|
||||
}
|
||||
min = new BlockVector(xMin, yMin, zMin);
|
||||
max = new BlockVector(xMax, yMax, zMax);
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<Block> getWallBlocks() {
|
||||
updateMinMax();
|
||||
ArrayList<Block> blocklist = new ArrayList<>();
|
||||
World w = getWorld();
|
||||
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
|
||||
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
|
||||
blocklist.add(w.getBlockAt(x, y, min.getBlockZ()));
|
||||
blocklist.add(w.getBlockAt(x, y, max.getBlockZ()));
|
||||
}
|
||||
}
|
||||
|
||||
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
|
||||
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
|
||||
blocklist.add(w.getBlockAt(min.getBlockX(), y, z));
|
||||
blocklist.add(w.getBlockAt(max.getBlockX(), y, z));
|
||||
}
|
||||
}
|
||||
return blocklist;
|
||||
}
|
||||
|
||||
public void setWall(BlockData m) {
|
||||
getWallBlocks().forEach(b -> {
|
||||
BlockState bs = b.getState();
|
||||
bs.setBlockData(m);
|
||||
bs.update(true);
|
||||
});
|
||||
}
|
||||
|
||||
public void setWall(Material m) {
|
||||
setWall(m.createBlockData());
|
||||
}
|
||||
|
||||
public ArrayList<Block> getCuboidBlocks() {
|
||||
updateMinMax();
|
||||
ArrayList<Block> blocklist = new ArrayList<>();
|
||||
World w = getWorld();
|
||||
for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
|
||||
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
|
||||
for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
|
||||
if (contains(new BlockVector(x, y, z))) {
|
||||
blocklist.add(w.getBlockAt(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return blocklist;
|
||||
}
|
||||
|
||||
public ArrayList<Block> getBlocks(BlockData m) {
|
||||
ArrayList<Block> blocklist = new ArrayList<>();
|
||||
getCuboidBlocks().forEach(b -> {
|
||||
if (m == null || b.getBlockData().equals(m)) blocklist.add(b);
|
||||
});
|
||||
return blocklist;
|
||||
}
|
||||
|
||||
public ArrayList<Block> getBlocks(Material m) {
|
||||
ArrayList<Block> blocklist = new ArrayList<>();
|
||||
getCuboidBlocks().forEach(b -> {
|
||||
if (m == null || b.getType() == m) blocklist.add(b);
|
||||
});
|
||||
return blocklist;
|
||||
}
|
||||
|
||||
public void replaceBlock(BlockData from, BlockData to) {
|
||||
getBlocks(from).forEach(b -> {
|
||||
BlockState bs = b.getState();
|
||||
bs.setBlockData(to);
|
||||
bs.update(true);
|
||||
});
|
||||
}
|
||||
|
||||
public void replaceBlock(Material from, Material to) {
|
||||
getBlocks(from).forEach(b -> {
|
||||
BlockState bs = b.getState();
|
||||
bs.setType(to);
|
||||
bs.update(true);
|
||||
});
|
||||
}
|
||||
|
||||
public void setBlock(BlockData m) {
|
||||
replaceBlock(null, m);
|
||||
}
|
||||
|
||||
public void setBlock(Material m) {
|
||||
replaceBlock(null, m);
|
||||
}
|
||||
|
||||
public void setAir() {
|
||||
setBlock(Material.AIR);
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return getCuboidBlocks().size();
|
||||
}
|
||||
|
||||
public int getCount(BlockData m) {
|
||||
return getBlocks(m).size();
|
||||
}
|
||||
|
||||
public int getCount(Material m) {
|
||||
return getBlocks(m).size();
|
||||
}
|
||||
|
||||
public int getCount(Material... m) {
|
||||
int count = 0;
|
||||
final ArrayList<Block> blocks = getCuboidBlocks();
|
||||
for (Material mSingle : m) {
|
||||
count += blocks.stream().filter(block -> block.getType().equals(mSingle)).count();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public abstract String getTypeID();
|
||||
|
||||
public int getArea() {
|
||||
return (int) ((max.getX() - min.getX() + 1) *
|
||||
(max.getY() - min.getY() + 1) *
|
||||
(max.getZ() - min.getZ() + 1));
|
||||
}
|
||||
}
|
||||
330
src/de/anura/core/tools/Potions.java
Normal file
330
src/de/anura/core/tools/Potions.java
Normal file
@@ -0,0 +1,330 @@
|
||||
package de.anura.core.tools;
|
||||
|
||||
import de.anura.core.AnuraThread;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public class Potions {
|
||||
|
||||
private static final Map<Player, Map<PotionEffectType, Set<CustomPotion>>> customPotions = new ConcurrentHashMap<>();
|
||||
private static final Map<Player, Map<PotionEffectType, Set<NativePotion>>> nativePotions = new ConcurrentHashMap<>();
|
||||
private static final Map<Player, Map<PotionEffectType, Long>> needsRefresh = new ConcurrentHashMap<>();
|
||||
private static final Set<Player> isReady = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
private static boolean end = false, init = false;
|
||||
|
||||
@SuppressWarnings("NestedSynchronizedStatement")
|
||||
public static void init() {
|
||||
if (init) {
|
||||
return;
|
||||
}
|
||||
init = true;
|
||||
|
||||
AnuraThread.async(() -> {
|
||||
while (!end) {
|
||||
synchronized (needsRefresh) {
|
||||
for (Entry<Player, Map<PotionEffectType, Long>> refreshPlayers : needsRefresh.entrySet()) {
|
||||
if (!isReady.contains(refreshPlayers.getKey())) continue;
|
||||
Set<Entry<PotionEffectType, Long>> pots = refreshPlayers.getValue().entrySet();
|
||||
synchronized (pots) {
|
||||
Iterator<Entry<PotionEffectType, Long>> refreshIt = pots.iterator();
|
||||
while (refreshIt.hasNext()) {
|
||||
Entry<PotionEffectType, Long> refresh = refreshIt.next();
|
||||
if (refresh.getValue() <= System.currentTimeMillis()) {
|
||||
long next = recalculate(refreshPlayers.getKey(), refresh.getKey(), true);
|
||||
if (next < 0) {
|
||||
refreshIt.remove();
|
||||
} else {
|
||||
refresh.setValue(next);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(20);
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.getLogger(Potions.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void addCustomPotion(Player P, CustomPotion holder) {
|
||||
PotionEffectType type = holder.potion.getType();
|
||||
initMaps(P, type);
|
||||
if (customPotions.get(P).get(type).add(holder)) {
|
||||
setNeedsRefresh(P, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addNativePotion(Player P, PotionEffect effect) {
|
||||
PotionEffectType type = effect.getType();
|
||||
initMaps(P, type);
|
||||
nativePotions.get(P).get(type).add(makeNative(effect));
|
||||
setNeedsRefresh(P, type);
|
||||
}
|
||||
|
||||
public static void removeCustomPotion(Player P, CustomPotion potion) {
|
||||
PotionEffectType type = potion.potion.getType();
|
||||
if (!customPotions.containsKey(P) || !customPotions.get(P).containsKey(type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (customPotions.get(P).get(type).remove(potion)) {
|
||||
setNeedsRefresh(P, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeNativePotion(Player P, PotionEffect effect, boolean removeAll) {
|
||||
PotionEffectType type = effect.getType();
|
||||
if (removeAll && nativePotions.containsKey(P)) {
|
||||
nativePotions.get(P).remove(type);
|
||||
}
|
||||
setNeedsRefresh(P, type);
|
||||
}
|
||||
|
||||
public static void join(Player P) {
|
||||
for (PotionEffect effect : P.getActivePotionEffects()) {
|
||||
addNativePotion(P, effect);
|
||||
}
|
||||
isReady.add(P);
|
||||
}
|
||||
|
||||
public static void logout(Player P) {
|
||||
isReady.remove(P);
|
||||
customPotions.remove(P);
|
||||
if (needsRefresh.containsKey(P)) {
|
||||
for (PotionEffectType type : needsRefresh.get(P).keySet()) {
|
||||
recalculate(P, type, false);
|
||||
}
|
||||
}
|
||||
nativePotions.remove(P);
|
||||
needsRefresh.remove(P);
|
||||
}
|
||||
|
||||
public static void refresh(Player P) {
|
||||
if (!needsRefresh.containsKey(P)) return;
|
||||
for (PotionEffectType type : needsRefresh.get(P).keySet()) {
|
||||
setNeedsRefresh(P, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static void disable() {
|
||||
end = true;
|
||||
for (Player P : Bukkit.getOnlinePlayers()) {
|
||||
logout(P);
|
||||
}
|
||||
}
|
||||
|
||||
private static long recalculate(Player P, PotionEffectType type, boolean resync) {
|
||||
clearOld(P);
|
||||
boolean hasCustomPot = customPotions.containsKey(P) && customPotions.get(P).containsKey(type);
|
||||
boolean hasNativePot = nativePotions.containsKey(P) && nativePotions.get(P).containsKey(type);
|
||||
|
||||
int bestLevel = 0, bestTime = 0;
|
||||
HandledPotion bestPotion = null;
|
||||
if (hasCustomPot) {
|
||||
Set<CustomPotion> pots = customPotions.get(P).get(type);
|
||||
synchronized (pots) {
|
||||
for (CustomPotion pot : pots) {
|
||||
if (hasNativePot && !pot.overrideNative) {
|
||||
continue;
|
||||
}
|
||||
if (bestPotion == null || pot.potion.getAmplifier() > bestLevel) {
|
||||
bestPotion = pot;
|
||||
bestLevel = pot.potion.getAmplifier();
|
||||
bestTime = Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasNativePot) {
|
||||
Set<NativePotion> pots = nativePotions.get(P).get(type);
|
||||
synchronized (pots) {
|
||||
for (NativePotion pot : pots) {
|
||||
int time = (int) (pot.until - System.currentTimeMillis() / 50);
|
||||
if (bestPotion == null || pot.potion.getAmplifier() > bestLevel) {
|
||||
bestPotion = pot;
|
||||
bestLevel = pot.potion.getAmplifier();
|
||||
bestTime = time;
|
||||
} else if (pot.potion.getAmplifier() == bestLevel && time > bestTime) {
|
||||
bestPotion = pot;
|
||||
bestTime = time;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PotionEffect effect = null;
|
||||
if (bestPotion != null) {
|
||||
effect = new PotionEffect(type, bestTime, bestLevel, bestPotion.potion.isAmbient(), bestPotion.potion.hasParticles(), bestPotion.potion.hasIcon());
|
||||
}
|
||||
|
||||
PotionEffect finalEffect = effect;
|
||||
Runnable toDo;
|
||||
if (finalEffect == null) {
|
||||
toDo = () -> P.removePotionEffect(type);
|
||||
} else {
|
||||
toDo = () -> P.addPotionEffect(finalEffect, true);
|
||||
}
|
||||
|
||||
if (resync) {
|
||||
AnuraThread.queueSync(toDo);
|
||||
} else {
|
||||
toDo.run();
|
||||
}
|
||||
|
||||
if (bestTime == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
long refreshTarget = bestTime > 20 * 60 * 10 ? 20 * 60 * 10 : bestTime + 3;
|
||||
return System.currentTimeMillis() + refreshTarget * 50;
|
||||
}
|
||||
|
||||
private static NativePotion makeNative(PotionEffect effect) {
|
||||
long until = System.currentTimeMillis() / 50 + effect.getDuration();
|
||||
return new NativePotion(until, effect);
|
||||
}
|
||||
|
||||
private static void setNeedsRefresh(Player P, PotionEffectType type) {
|
||||
if (!needsRefresh.containsKey(P)) {
|
||||
needsRefresh.put(P, new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
needsRefresh.get(P).put(type, 0L);
|
||||
}
|
||||
|
||||
@SuppressWarnings("NestedSynchronizedStatement")
|
||||
private static void clearOld(Player P) {
|
||||
if (!nativePotions.containsKey(P)) return;
|
||||
Collection<Set<NativePotion>> natPots = nativePotions.get(P).values();
|
||||
synchronized (natPots) {
|
||||
for (Set<NativePotion> pots : natPots) {
|
||||
synchronized (pots) {
|
||||
Iterator<NativePotion> potions = pots.iterator();
|
||||
while (potions.hasNext()) {
|
||||
NativePotion pot = potions.next();
|
||||
if (pot.until <= System.currentTimeMillis() / 50) {
|
||||
potions.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void initMaps(Player P, PotionEffectType type) {
|
||||
if (!nativePotions.containsKey(P)) {
|
||||
nativePotions.put(P, new ConcurrentHashMap<>());
|
||||
}
|
||||
if (!nativePotions.get(P).containsKey(type)) {
|
||||
nativePotions.get(P).put(type, ConcurrentHashMap.newKeySet());
|
||||
}
|
||||
if (!customPotions.containsKey(P)) {
|
||||
customPotions.put(P, new ConcurrentHashMap<>());
|
||||
}
|
||||
if (!customPotions.get(P).containsKey(type)) {
|
||||
customPotions.get(P).put(type, ConcurrentHashMap.newKeySet());
|
||||
}
|
||||
}
|
||||
|
||||
private static class NativePotion extends HandledPotion {
|
||||
private final long until;
|
||||
|
||||
private NativePotion(long until, PotionEffect potion) {
|
||||
super(potion);
|
||||
this.until = until;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 5;
|
||||
hash = 97 * hash + (int) (this.until ^ (this.until >>> 32));
|
||||
hash = 97 * hash + this.potion.getAmplifier();
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final NativePotion other = (NativePotion) obj;
|
||||
if (this.until != other.until) {
|
||||
return false;
|
||||
}
|
||||
return this.potion.getAmplifier() == other.potion.getAmplifier();
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomPotion extends HandledPotion {
|
||||
private final boolean overrideNative;
|
||||
|
||||
public CustomPotion(PotionEffect potion, boolean overrideNative) {
|
||||
super(potion);
|
||||
this.overrideNative = overrideNative;
|
||||
}
|
||||
|
||||
public CustomPotion(PotionEffect potion) {
|
||||
this(potion, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 47 * hash + Objects.hashCode(this.potion);
|
||||
hash = 47 * hash + (this.overrideNative ? 1 : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final CustomPotion other = (CustomPotion) obj;
|
||||
if (this.overrideNative != other.overrideNative) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(this.potion, other.potion);
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class HandledPotion {
|
||||
protected final PotionEffect potion;
|
||||
|
||||
public HandledPotion(PotionEffect potion) {
|
||||
this.potion = potion;
|
||||
}
|
||||
}
|
||||
}
|
||||
311
src/de/anura/core/tools/TownInventory.java
Normal file
311
src/de/anura/core/tools/TownInventory.java
Normal file
@@ -0,0 +1,311 @@
|
||||
package de.anura.core.tools;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class TownInventory {
|
||||
|
||||
private final HashMap<Integer, InvItem> items = new HashMap<>();
|
||||
private final HashSet<ClickItemCallback> itemClicks = new HashSet<>();
|
||||
|
||||
private Inventory inv;
|
||||
private String title;
|
||||
private ChatColor color;
|
||||
private int size;
|
||||
private final boolean destroy;
|
||||
private Consumer<Player> closeListener = null;
|
||||
|
||||
public TownInventory(String title, ChatColor color, int size, boolean destroyOnEnd) {
|
||||
assert(size % 9 == 0);
|
||||
destroy = destroyOnEnd;
|
||||
settings(title, color, size);
|
||||
invs.add(this);
|
||||
}
|
||||
|
||||
public TownInventory(String title, ChatColor color, boolean destroyOnEnd) {
|
||||
this(title, color, 9, destroyOnEnd);
|
||||
}
|
||||
|
||||
public TownInventory(String title) {
|
||||
this(title, 9, false);
|
||||
}
|
||||
|
||||
public TownInventory(String title, int size) {
|
||||
this(title, size, false);
|
||||
}
|
||||
|
||||
public TownInventory(String title, int size, boolean destroyOnEnd) {
|
||||
this(title, ChatColor.RESET, size, destroyOnEnd);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return color + title;
|
||||
}
|
||||
|
||||
public TownInventory settings(String name, ChatColor color, int size) {
|
||||
title = name;
|
||||
this.color = color;
|
||||
this.size = size;
|
||||
createInventory();
|
||||
return this;
|
||||
}
|
||||
|
||||
public TownInventory settings(String name, int size) {
|
||||
return settings(name, ChatColor.RESET, size);
|
||||
}
|
||||
|
||||
public TownInventory settings(int size) {
|
||||
return settings(title, color, size);
|
||||
}
|
||||
|
||||
public TownInventory putItem(int slot, InvItem item) {
|
||||
assert(slot < size);
|
||||
items.put(slot, item);
|
||||
inv.setItem(slot, item.getItem());
|
||||
return this;
|
||||
}
|
||||
|
||||
public TownInventory open(Player P) {
|
||||
P.openInventory(inv);
|
||||
openInvs.put(P, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean checkInvClick(int slot, Player P, boolean isShift) {
|
||||
if (!isOpen(P)) return false;
|
||||
if (!items.containsKey(slot)) return true;
|
||||
items.get(slot).click(P, isShift);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void checkPlayerInvClick(Player P, InventoryClickEvent event) {
|
||||
itemClicks.forEach((cb) -> cb.onClick(P, event.getSlot(), event.getAction(), event));
|
||||
}
|
||||
|
||||
private void createInventory() {
|
||||
inv = Bukkit.createInventory(null, size, color + title);
|
||||
items.entrySet().stream().filter((i) -> i.getKey() <= size).forEach((i) -> inv.setItem(i.getKey(), i.getValue().getItem()));
|
||||
}
|
||||
|
||||
public void close(Player P) {
|
||||
if (isOpen(P)) {
|
||||
openInvs.remove(P);
|
||||
if (closeListener != null) {
|
||||
closeListener.accept(P);
|
||||
}
|
||||
if (destroy) {
|
||||
invs.remove(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
Iterator<Entry<Player, TownInventory>> invsIt = openInvs.entrySet().iterator();
|
||||
while (invsIt.hasNext()) {
|
||||
Entry<Player, TownInventory> pInv = invsIt.next();
|
||||
if (pInv.getValue().equals(this)) {
|
||||
invsIt.remove();
|
||||
pInv.getKey().closeInventory();
|
||||
if (closeListener != null) {
|
||||
closeListener.accept(pInv.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
invs.remove(this);
|
||||
}
|
||||
|
||||
public boolean isOpen(Player P) {
|
||||
return openInvs.containsKey(P) && openInvs.get(P) == this;
|
||||
}
|
||||
|
||||
public void playerInvCallback(ClickItemCallback cb) {
|
||||
itemClicks.add(cb);
|
||||
}
|
||||
|
||||
public void setCloseListener(Consumer<Player> cb) {
|
||||
closeListener = cb;
|
||||
}
|
||||
|
||||
public static class InvItem {
|
||||
|
||||
private final ItemStack stack;
|
||||
private final String name;
|
||||
private final ChatColor color;
|
||||
private final ChatColor loreColor;
|
||||
private final List<String> lores = new ArrayList<>();
|
||||
private final HashSet<ActionData> actions = new HashSet<>();
|
||||
|
||||
public InvItem(ItemStack stack) {
|
||||
this(stack, null, ChatColor.RESET, null);
|
||||
}
|
||||
|
||||
public InvItem(ItemStack stack, String name, String... lores) {
|
||||
this(stack, name, ChatColor.RESET, ChatColor.RESET, lores);
|
||||
}
|
||||
|
||||
public InvItem(ItemStack stack, ChatColor loreColor, String... lores) {
|
||||
this(stack, null, ChatColor.RESET, loreColor, lores);
|
||||
}
|
||||
|
||||
public InvItem(ItemStack stack, String name, ChatColor nameColor, ChatColor loreColor, String... lores) {
|
||||
this.stack = stack;
|
||||
this.name = name;
|
||||
this.color = nameColor;
|
||||
this.loreColor = loreColor;
|
||||
this.lores.addAll(Arrays.asList(lores));
|
||||
}
|
||||
|
||||
public InvItem addAction(ActionData data) {
|
||||
actions.add(data);
|
||||
return this;
|
||||
}
|
||||
|
||||
public InvItem addAction(Consumer<Player> cb) {
|
||||
actions.add(new ActionData(Action.EXEC, cb));
|
||||
return this;
|
||||
}
|
||||
|
||||
public InvItem addLore(String lore) {
|
||||
lores.add(lore);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
ItemStack item = stack.clone();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (name != null) meta.setDisplayName(color + name);
|
||||
if (!lores.isEmpty()) {
|
||||
List<String> lore = new ArrayList<>();
|
||||
lores.forEach((l) -> lore.add(loreColor + l));
|
||||
meta.setLore(lore);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void click(Player P, boolean isShift) {
|
||||
for (ActionData action : actions) {
|
||||
if (action.isShift() != isShift) continue;
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
Object data = action.getData();
|
||||
if (action.closeInv) {
|
||||
P.closeInventory();
|
||||
}
|
||||
switch (action.getAction()) {
|
||||
case OPEN_INV:
|
||||
if (data instanceof TownInventory) {
|
||||
((TownInventory)data).open(P);
|
||||
}
|
||||
break;
|
||||
case TELEPORT:
|
||||
if (data instanceof Location) {
|
||||
P.teleport((Location) data);
|
||||
}
|
||||
break;
|
||||
case MESSAGE:
|
||||
if (data instanceof String) {
|
||||
P.sendMessage((String) data);
|
||||
}
|
||||
break;
|
||||
case COMMAND:
|
||||
if (data instanceof String) {
|
||||
Bukkit.getServer().dispatchCommand(P, (String) data);
|
||||
}
|
||||
break;
|
||||
case EXEC:
|
||||
if (data instanceof Consumer) {
|
||||
((Consumer<Player>) data).accept(P);
|
||||
}
|
||||
break;
|
||||
}
|
||||
stopwatch.stop();
|
||||
if (stopwatch.elapsed(TimeUnit.MILLISECONDS) > 10) {
|
||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Inventory click listener {0} took {1}",
|
||||
new Object[]{action.data.getClass().getName(), stopwatch.toString()});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ActionData {
|
||||
|
||||
private final Action action;
|
||||
private final Object data;
|
||||
private final boolean isShift;
|
||||
private final boolean closeInv;
|
||||
|
||||
public ActionData(Action a, boolean shiftClick, Object d) {
|
||||
this(a, shiftClick, false, d);
|
||||
}
|
||||
|
||||
public ActionData(Action a, boolean shiftClick, boolean close, Object d) {
|
||||
action = a;
|
||||
data = d;
|
||||
isShift = shiftClick;
|
||||
closeInv = close;
|
||||
}
|
||||
|
||||
public ActionData(Action a, Object d) {
|
||||
this(a, false, d);
|
||||
}
|
||||
|
||||
public Action getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public boolean isShift() {
|
||||
return isShift;
|
||||
}
|
||||
|
||||
public boolean isCloseInv() {
|
||||
return closeInv;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Action {
|
||||
OPEN_INV,
|
||||
TELEPORT,
|
||||
MESSAGE,
|
||||
COMMAND,
|
||||
EXEC
|
||||
}
|
||||
|
||||
public interface ClickItemCallback {
|
||||
void onClick(Player P, int slot, InventoryAction action, InventoryClickEvent event);
|
||||
}
|
||||
|
||||
private static final HashSet<TownInventory> invs = new HashSet<>();
|
||||
private static final HashMap<Player, TownInventory> openInvs = new HashMap<>();
|
||||
|
||||
public static HashSet<TownInventory> getInvs() {
|
||||
return invs;
|
||||
}
|
||||
|
||||
public static TownInventory getOpenInv(Player P) {
|
||||
return openInvs.get(P);
|
||||
}
|
||||
}
|
||||
84
src/de/anura/core/tools/Villagers.java
Normal file
84
src/de/anura/core/tools/Villagers.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package de.anura.core.tools;
|
||||
|
||||
import de.anura.core.AnuraCore;
|
||||
import de.anura.core.AnuraThread;
|
||||
import java.util.HashMap;
|
||||
import java.util.function.Consumer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.entity.Villager.Profession;
|
||||
import org.bukkit.scoreboard.ScoreboardManager;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
import org.bukkit.scoreboard.Team.Option;
|
||||
import org.bukkit.scoreboard.Team.OptionStatus;
|
||||
|
||||
public abstract class Villagers {
|
||||
|
||||
private static Team t;
|
||||
private static final HashMap<String, Consumer<Player>> clicks = new HashMap<>();
|
||||
|
||||
public static void init() {
|
||||
AnuraThread.add(Bukkit.getScheduler().runTaskLater(AnuraCore.getInstance(), () -> { //The scoreboard seems to be initialized later
|
||||
ScoreboardManager boardMan = Bukkit.getScoreboardManager();
|
||||
if (boardMan == null)
|
||||
return;
|
||||
|
||||
t = boardMan.getMainScoreboard().getTeam("noMoveEntity");
|
||||
if (t == null) {
|
||||
t = boardMan.getMainScoreboard().registerNewTeam("noMoveEntity");
|
||||
t.setOption(Option.COLLISION_RULE, OptionStatus.NEVER);
|
||||
}
|
||||
}, 1));
|
||||
}
|
||||
|
||||
public static void spawn(Location loc, String id, String name, Profession profession) {
|
||||
if (loc == null || loc.getWorld() == null)
|
||||
return;
|
||||
|
||||
Villager v = loc.getWorld().spawn(loc, Villager.class);
|
||||
v.teleport(loc);
|
||||
v.setAI(false);
|
||||
v.setProfession(profession);
|
||||
v.setCanPickupItems(false);
|
||||
v.setCustomName(name);
|
||||
v.setCustomNameVisible(true);
|
||||
v.setSilent(true);
|
||||
v.setGravity(false);
|
||||
v.addScoreboardTag(id);
|
||||
v.addScoreboardTag("townVillager");
|
||||
t.addEntry(v.getUniqueId().toString());
|
||||
}
|
||||
|
||||
public static void spawn(Location loc, String id, String name) {
|
||||
spawn(loc, id, name, Profession.LIBRARIAN);
|
||||
}
|
||||
|
||||
public static void removeIfMatch(Villager v) {
|
||||
if (is(v)) {
|
||||
t.removeEntry(v.getUniqueId().toString());
|
||||
v.remove();
|
||||
}
|
||||
}
|
||||
|
||||
public static void onClick(String id, Consumer<Player> cb) {
|
||||
clicks.put(id, cb);
|
||||
}
|
||||
|
||||
public static boolean doClick(Villager v, Player P) {
|
||||
if (!t.hasEntry(v.getUniqueId().toString())) return false;
|
||||
boolean done = false;
|
||||
for (String s : v.getScoreboardTags()) {
|
||||
if (clicks.containsKey(s)) {
|
||||
clicks.get(s).accept(P);
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
public static boolean is(Villager v) {
|
||||
return v.getScoreboardTags().contains("townVillager");
|
||||
}
|
||||
}
|
||||
57
src/de/anura/core/util/Blocks.java
Normal file
57
src/de/anura/core/util/Blocks.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package de.anura.core.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
public abstract class Blocks {
|
||||
|
||||
public static Block getMin(Block block1, Block block2) {
|
||||
checkWorld(block1, block2);
|
||||
int x = Math.min(block1.getX(), block2.getX());
|
||||
int y = Math.min(block1.getY(), block2.getY());
|
||||
int z = Math.min(block1.getZ(), block2.getZ());
|
||||
return block1.getWorld().getBlockAt(x, y, z);
|
||||
}
|
||||
|
||||
public static Block getMax(Block block1, Block block2) {
|
||||
checkWorld(block1, block2);
|
||||
int x = Math.max(block1.getX(), block2.getX());
|
||||
int y = Math.max(block1.getY(), block2.getY());
|
||||
int z = Math.max(block1.getZ(), block2.getZ());
|
||||
return block1.getWorld().getBlockAt(x, y, z);
|
||||
}
|
||||
|
||||
public static Block center(Block block1, Block block2) {
|
||||
checkWorld(block1, block2);
|
||||
Block min = getMin(block1, block2);
|
||||
Block max = getMax(block1, block2);
|
||||
int x = min.getX() + Math.round(max.getX() - min.getX() / 2);
|
||||
int y = min.getY() + Math.round(max.getY() - min.getY() / 2);
|
||||
int z = min.getZ() + Math.round(max.getZ() - min.getZ() / 2);
|
||||
return block1.getWorld().getBlockAt(x, y, z);
|
||||
}
|
||||
|
||||
private static void checkWorld(Block block1, Block block2) {
|
||||
if (!block1.getWorld().equals(block2.getWorld()))
|
||||
throw new IllegalArgumentException("The blocks have to be in the same world");
|
||||
}
|
||||
|
||||
public static float faceToYaw(BlockFace face) {
|
||||
switch (face) {
|
||||
case NORTH:
|
||||
return 180;
|
||||
case EAST:
|
||||
return 270;
|
||||
case WEST:
|
||||
return 90;
|
||||
case SOUTH:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean blockEquals(Location l1, Location l2) {
|
||||
return l1.getBlockX() == l2.getBlockX() && l1.getBlockY() == l2.getBlockY() && l1.getBlockZ() == l2.getBlockZ();
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package de.anura.core.util;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Data {
|
||||
public static HashMap<Player, Double> selectableJumper = new HashMap<>();
|
||||
public static HashMap<Player, String> permGroup = new HashMap<>();
|
||||
public static HashMap<Player, Arrow> sittingPlayer = new HashMap<>();
|
||||
public static HashMap<Player, Block> sittingBlocks = new HashMap<>();
|
||||
public static HashMap<Integer, Location> flowerPots = new HashMap<>();
|
||||
public static HashMap<Integer, Integer> flowerPotsWait = new HashMap<>();
|
||||
public static HashMap<Player, Location> lastLoc = new HashMap<>();
|
||||
public static HashMap<String, BufferedImage> renderedImgs = new HashMap<>();
|
||||
public static ArrayList<Player> stairMode = new ArrayList<>();
|
||||
public static ArrayList<Block> sittableBlocks = new ArrayList<>();
|
||||
public static HashMap<Player, Integer> golfPower = new HashMap<>();
|
||||
public static HashMap<Player, Boolean> releaseGolf = new HashMap<>();
|
||||
public static HashMap<Player, Entity> golfBall = new HashMap<>();
|
||||
public static HashMap<Player, Boolean> disableCommandsAdventure = new HashMap<>();
|
||||
public static HashMap<Player, Integer> joinTime = new HashMap<>();
|
||||
public static HashMap<Player, Integer> aimTheWaterWins = new HashMap<>();
|
||||
public static ArrayList<Player> denySit = new ArrayList<>();
|
||||
}
|
||||
67
src/de/anura/core/util/Head.java
Normal file
67
src/de/anura/core/util/Head.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package de.anura.core.util;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
public abstract class Head {
|
||||
|
||||
private static final Field properties, profile;
|
||||
|
||||
static {
|
||||
Field props = null;
|
||||
Field prof = null;
|
||||
try {
|
||||
props = GameProfile.class.getDeclaredField("properties");
|
||||
props.setAccessible(true);
|
||||
prof = Head.class.getClassLoader().loadClass("org.bukkit.craftbukkit.v1_14_R2.inventory.CraftMetaSkull").getDeclaredField("profile");
|
||||
prof.setAccessible(true);
|
||||
} catch (NoSuchFieldException | SecurityException | ClassNotFoundException ex) {
|
||||
Logger.getLogger(Head.class.getName()).log(Level.SEVERE, "Failed reflection in Head util", ex);
|
||||
}
|
||||
properties = props;
|
||||
profile = prof;
|
||||
}
|
||||
|
||||
public static ItemStack get(String name) {
|
||||
ItemStack is = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta meta = (SkullMeta) is.getItemMeta();
|
||||
if (meta == null)
|
||||
return is;
|
||||
|
||||
meta.setOwningPlayer(Bukkit.getOfflinePlayer(name));
|
||||
is.setItemMeta(meta);
|
||||
return is;
|
||||
}
|
||||
|
||||
public static ItemStack getWithTexture(String textureString) {
|
||||
ItemStack stack = new ItemStack(Material.PLAYER_HEAD);
|
||||
addTexture(stack, textureString);
|
||||
return stack;
|
||||
}
|
||||
|
||||
private static void addTexture(ItemStack stack, String textureString) {
|
||||
try {
|
||||
if (stack == null || !stack.getType().equals(Material.PLAYER_HEAD)) return;
|
||||
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
PropertyMap propertyMap = new PropertyMap();
|
||||
propertyMap.put("textures", new Property("textures", textureString));
|
||||
GameProfile gprofile = new GameProfile(UUID.randomUUID(), null);
|
||||
properties.set(gprofile, propertyMap);
|
||||
profile.set(meta, gprofile);
|
||||
stack.setItemMeta(meta);
|
||||
} catch (IllegalArgumentException | IllegalAccessException ex) {
|
||||
Logger.getLogger(Head.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
src/de/anura/core/util/Tuple.java
Normal file
12
src/de/anura/core/util/Tuple.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package de.anura.core.util;
|
||||
|
||||
public class Tuple<X, Y> {
|
||||
|
||||
public final X x;
|
||||
public final Y y;
|
||||
|
||||
public Tuple(X x, Y y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
197
src/de/anura/core/util/UUIDManager.java
Normal file
197
src/de/anura/core/util/UUIDManager.java
Normal file
@@ -0,0 +1,197 @@
|
||||
package de.anura.core.util;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import de.anura.core.AnuraThread;
|
||||
import de.anura.core.database.DB;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
public abstract class UUIDManager {
|
||||
|
||||
private static final BiMap<String, UUID> cache = HashBiMap.create();
|
||||
private static final Set<UUID> inDB = new HashSet<>();
|
||||
|
||||
public static void getName(UUID uuid, Consumer<String> cb) {
|
||||
getName(uuid, false, cb);
|
||||
}
|
||||
|
||||
public static void getName(UUID uuid, boolean onlyDatabase, Consumer<String> cb) {
|
||||
if (uuid == null) {
|
||||
cb.accept(null);
|
||||
return;
|
||||
}
|
||||
boolean sync = Bukkit.isPrimaryThread();
|
||||
if (Bukkit.getPlayer(uuid) != null) {
|
||||
cb.accept(Bukkit.getPlayer(uuid).getName());
|
||||
} else if (cache.inverse().containsKey(uuid)) {
|
||||
if (!onlyDatabase || inDB.contains(uuid)) {
|
||||
cb.accept(cache.inverse().get(uuid));
|
||||
} else {
|
||||
cb.accept(null);
|
||||
}
|
||||
} else {
|
||||
Runnable requestUser = () -> {
|
||||
ResultSet rs = DB.querySelect("SELECT name FROM players WHERE uuid = ?", uuid.toString());
|
||||
try {
|
||||
if (rs != null && rs.next()) {
|
||||
String name = rs.getString("name");
|
||||
cache.put(name, uuid);
|
||||
inDB.add(uuid);
|
||||
if (sync) {
|
||||
AnuraThread.syncCB(cb, name);
|
||||
} else {
|
||||
cb.accept(name);
|
||||
}
|
||||
return;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.getLogger(UUIDManager.class.getName()).log(Level.SEVERE, null, e);
|
||||
}
|
||||
if (onlyDatabase) {
|
||||
if (sync) {
|
||||
AnuraThread.syncCB(cb, null);
|
||||
} else {
|
||||
cb.accept(null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
OfflinePlayer P = Bukkit.getOfflinePlayer(uuid);
|
||||
if (P != null) {
|
||||
cache.put(P.getName(), uuid);
|
||||
if (sync) {
|
||||
AnuraThread.syncCB(cb, P.getName());
|
||||
} else {
|
||||
cb.accept(P.getName());
|
||||
}
|
||||
}
|
||||
};
|
||||
if (sync) {
|
||||
AnuraThread.async(requestUser);
|
||||
} else {
|
||||
requestUser.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void getUUID(String name, Consumer<UUID> cb) {
|
||||
getUUID(name, false, cb);
|
||||
}
|
||||
|
||||
public static void getUUID(String name, boolean onlyDatabase, Consumer<UUID> cb) {
|
||||
if (name == null) {
|
||||
cb.accept(null);
|
||||
return;
|
||||
}
|
||||
boolean sync = Bukkit.isPrimaryThread();
|
||||
if (cache.containsKey(name)) {
|
||||
if (!onlyDatabase || inDB.contains(cache.get(name))) {
|
||||
cb.accept(cache.get(name));
|
||||
} else {
|
||||
cb.accept(null);
|
||||
}
|
||||
} else if (Bukkit.getPlayerExact(name) == null) {
|
||||
Runnable requestUser = () -> {
|
||||
ResultSet rs = DB.querySelect("SELECT uuid FROM players WHERE name = ?", name);
|
||||
try {
|
||||
if (rs != null && rs.next()) {
|
||||
UUID uuid = UUID.fromString(rs.getString("uuid"));
|
||||
cache.inverse().remove(uuid);
|
||||
cache.put(name, uuid);
|
||||
inDB.add(uuid);
|
||||
if (sync) {
|
||||
AnuraThread.syncCB(cb, uuid);
|
||||
} else {
|
||||
cb.accept(uuid);
|
||||
}
|
||||
return;
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
if (onlyDatabase) {
|
||||
if (sync) {
|
||||
AnuraThread.syncCB(cb, null);
|
||||
} else {
|
||||
cb.accept(null);
|
||||
}
|
||||
} else {
|
||||
requestUUID(name, cb, sync);
|
||||
}
|
||||
};
|
||||
if (sync) {
|
||||
AnuraThread.async(requestUser);
|
||||
} else {
|
||||
requestUser.run();
|
||||
}
|
||||
} else {
|
||||
UUID uuid = Bukkit.getPlayerExact(name).getUniqueId();
|
||||
cache.inverse().remove(uuid);
|
||||
cache.put(name, uuid);
|
||||
inDB.add(uuid);
|
||||
cb.accept(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void requestUUID(String name, Consumer<UUID> cb, boolean wasSync) {
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL("https://api.mojang.com/users/profiles/minecraft/" + name).openConnection();
|
||||
connection.setUseCaches(false);
|
||||
connection.setDoOutput(true);
|
||||
String answer;
|
||||
InputStream is = connection.getInputStream();
|
||||
if (is != null) {
|
||||
Writer writer = new StringWriter();
|
||||
char[] buffer = new char[1024];
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||
int n;
|
||||
while ((n = reader.read(buffer)) != -1) {
|
||||
writer.write(buffer, 0, n);
|
||||
}
|
||||
} finally {
|
||||
is.close();
|
||||
}
|
||||
answer = writer.toString();
|
||||
} else {
|
||||
answer = "";
|
||||
}
|
||||
JSONObject jsonObject = (JSONObject) JSONValue.parseWithException(answer);
|
||||
connection.disconnect();
|
||||
String id = (String) jsonObject.get("id");
|
||||
UUID uuid = UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32));
|
||||
cache.put(name, uuid);
|
||||
if (wasSync) {
|
||||
AnuraThread.syncCB(cb, uuid);
|
||||
} else {
|
||||
cb.accept(uuid);
|
||||
}
|
||||
} catch (IOException | ParseException ex) {
|
||||
if (wasSync) {
|
||||
AnuraThread.syncCB(cb, null);
|
||||
} else {
|
||||
cb.accept(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
38
src/de/anura/core/util/Util.java
Normal file
38
src/de/anura/core/util/Util.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package de.anura.core.util;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class Util {
|
||||
|
||||
public static boolean isInteger(String s) {
|
||||
return isInteger(s, 10);
|
||||
}
|
||||
|
||||
private static boolean isInteger(String s, int radix) {
|
||||
if (s.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
if (i == 0 && s.charAt(i) == '-') {
|
||||
if (s.length() == 1) {
|
||||
return false;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (Character.digit(s.charAt(i), radix) < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static <T, E> T getKeyByValue(Map<T, E> map, E value) {
|
||||
for (Map.Entry<T, E> entry : map.entrySet()) {
|
||||
if (value.equals(entry.getValue())) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
134
src/plugin.yml
134
src/plugin.yml
@@ -1,111 +1,23 @@
|
||||
name: Core
|
||||
main: de.anura.core.AnuraCore
|
||||
version: 0.9
|
||||
author: kaenganxt
|
||||
softdepend: [Multiverse-Core, Votifier]
|
||||
commands:
|
||||
setjumper:
|
||||
description: Admin Command
|
||||
usage: /<command> <height>
|
||||
setspawn:
|
||||
description: Sets the worlds spawn
|
||||
usage: /<command>
|
||||
spawn:
|
||||
description: Teleports you to spawn
|
||||
usage: /<command> <player>
|
||||
money:
|
||||
description: Money stuff
|
||||
usage: /<command> [pay <player> <money>]
|
||||
gm:
|
||||
description: GameMode!
|
||||
usage: /<command> <blabla>
|
||||
sun:
|
||||
description: I love sun!
|
||||
usage: /<command>
|
||||
core:
|
||||
description: Save/Reload the config
|
||||
usage: /<command> save|reload|debugclosemysql
|
||||
hilfe:
|
||||
description: Shows the help
|
||||
usage: /<command> [seite]
|
||||
none:
|
||||
description: This is a dummy command
|
||||
usage: /<command>
|
||||
flyspeed:
|
||||
description: Set the fly-speed
|
||||
usage: /<command> <speed>
|
||||
setwarp:
|
||||
description: Set a warp
|
||||
usage: /<command> <name> [allowUsers]
|
||||
warp:
|
||||
description: It's a warp
|
||||
usage: /<command> <warp> [player]
|
||||
remwarp:
|
||||
description: Remove warp
|
||||
usage: /<command> <warp>
|
||||
flowerpot:
|
||||
description: Set a flowerpot
|
||||
usage: /<command> <translateName>
|
||||
addmap:
|
||||
description: Adds an image-map
|
||||
usage: /<command> <imageName>
|
||||
rendermap:
|
||||
description: Renders an image for a map
|
||||
usage: /<command> <imageUrl> <name>
|
||||
cleararrows:
|
||||
description: Clears all arrows in the current world
|
||||
usage: /<command>
|
||||
stairmode:
|
||||
description: Toggles the stairmode
|
||||
usage: /<command>
|
||||
addcmd:
|
||||
description: Adds some text to a cmd block
|
||||
usage: /<command> <text>
|
||||
setcmd:
|
||||
description: Sets the command of a cmd block
|
||||
usage: /<command> <text>
|
||||
togglecommands:
|
||||
description: Only cmd block command!
|
||||
usage: /<command> <player> <enable|disable>
|
||||
toggledbljump:
|
||||
description: Toggles the double jump
|
||||
usage: /<command>
|
||||
joinminigame:
|
||||
description: Join a redstone minigame
|
||||
usage: /<command> (xpBattle|pool)
|
||||
leaveminigame:
|
||||
description: Leave a redstone minigame
|
||||
usage: /<command> (xpBattle|pool)
|
||||
toggleminigame:
|
||||
description: Join/Leave a redstone minigame
|
||||
usage: /<command> (xpBattle|pool)
|
||||
addAimTWWin:
|
||||
description: Adds an Aim the Water win to the statistics
|
||||
usage: /<command> <username>
|
||||
toggleBoatFlight:
|
||||
description: Toggles if you automatic flight when you escape a boat (only in gamemode 1)
|
||||
usage: /<command>
|
||||
toggleboat:
|
||||
description: Enables/Disables the boat feature
|
||||
usage: /<command>
|
||||
bug:
|
||||
description: Reports a bug and collects some server specific server data
|
||||
usage: /<command> <message>...
|
||||
warplist:
|
||||
description: Prints a list of warps
|
||||
usage: /<command>
|
||||
addInvItems:
|
||||
description: Add inv items
|
||||
usage: /<command> [player]
|
||||
villager:
|
||||
description: Anura-Villager commands
|
||||
usage: /<command> (remove)|(create double_jump|boat)
|
||||
i:
|
||||
description: Such i
|
||||
usage: /<command> <item> [damage]
|
||||
mute:
|
||||
description: Mute a player
|
||||
usage: /<command> <player>
|
||||
unmute:
|
||||
description: Unmute a player
|
||||
usage: /<command> <player>
|
||||
name: Core
|
||||
main: de.anura.core.AnuraCore
|
||||
version: 0.10
|
||||
author: kaenganxt
|
||||
api-version: 1.14
|
||||
commands:
|
||||
r:
|
||||
description: Antworte einem Spieler
|
||||
usage: /<command> <nachricht>
|
||||
spawn:
|
||||
description: Teleportiert dich zum Spawn
|
||||
usage: /<command> <player>
|
||||
money:
|
||||
description: Geld
|
||||
usage: /<command> [pay <player> <money>]
|
||||
aliases: [geld]
|
||||
gm:
|
||||
description: GameMode!
|
||||
usage: /<command> <gm>
|
||||
msg:
|
||||
description: Sende eine Nachricht
|
||||
usage: /<command> <spieler> <msg>
|
||||
aliases: [message, tell]
|
||||
|
||||
Reference in New Issue
Block a user