mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2024-11-05 09:00:18 +01:00
Implemented Commands and Random Wakeups
This commit is contained in:
parent
8e11062f56
commit
da0b1ddf54
13
config.yml
13
config.yml
@ -11,21 +11,24 @@ enableHome: true
|
||||
# SamplePlugin = installiertes home plugin. Unterstützt: ManagerXL. Wenn dies nicht geht:
|
||||
# 'cmd: home' = /home wird vom Spieler ausgelöst. Es sollte kein Verzögerungs, etc. plugin installiert sein!
|
||||
# 'cmd: spawn' = /spawn wird vom Spieler ausgelöst
|
||||
# 'cmd: exmpl' = /exmpl wird vom Spieler ausgelöst
|
||||
# 'cmd: whatever' = /whatever wird vom Spieler ausgelöst
|
||||
homeType: 'cmd: home'
|
||||
|
||||
# Ob der Spieler nach etwas kürzerem Ausloggen an einem zufälligen Ort "aufwacht" (diese müssen durch /setwake von einem Admin festgelegt werden)
|
||||
# Ob der Spieler nach etwas kürzerem Ausloggen an einem zufälligen Ort "aufwacht" (diese müssen durch '/br Wakeup add' von einem Admin festgelegt werden)
|
||||
# Der Spieler wacht nur an einem Ort auf, der sich in seiner jetzigen Welt befindet.
|
||||
# Work in Progress, noch nicht implementiert!
|
||||
enableWake: true
|
||||
|
||||
# Der Text, den der Spieler beim Aufwachen sieht
|
||||
wakeString: 'Ohh nein! Ich kann mich nicht erinnern, wie ich hier hergekommen bin...'
|
||||
|
||||
# Ob der Spieler sich bei großer Trunkenheit teilweise nicht einloggen kann und kurz warten muss, da sein Charakter nicht reagiert
|
||||
enableLoginDisallow: true
|
||||
|
||||
# Ob der Spieler sich übertrinken kann und dann in Ohnmacht fällt (gekickt wird) und sich für einige Stunden nicht einloggen kann
|
||||
# Ob der Spieler sich übertrinken kann und dann in Ohnmacht fällt (gekickt wird) und sich für einige Minuten nicht einloggen kann
|
||||
enableKickOnOverdrink: true
|
||||
|
||||
# Ob der Spieler sich bei großer Trunkenheit übergibt (unten definiertes Item aus dem Mund fallen lässt, dass nicht aufgesammelt werden kann und bis zum Despawnen liegen bleibt)
|
||||
# Ob der Spieler sich bei großer Trunkenheit übergibt (unten definiertes Item aus dem Mund fallen lässt)
|
||||
# Das Item kann nicht aufgesammelt werden und bleibt bis zum Despawnen liegen. (Achtung: Kann nach Serverrestart, oder durch Hopper aufgesammelt werden.)
|
||||
enablePuke: true
|
||||
|
||||
# Item das beim Erbrechen mehrfach unaufsammelbar fallen gelassen wird
|
||||
|
@ -135,6 +135,8 @@ public class BCauldron {
|
||||
}
|
||||
|
||||
public static void save(ConfigurationSection config, ConfigurationSection oldData) {
|
||||
P.p.createWorldSections(config);
|
||||
|
||||
if (!bcauldrons.isEmpty()) {
|
||||
int id = 0;
|
||||
for (BCauldron cauldron : bcauldrons) {
|
||||
|
@ -93,14 +93,7 @@ public class BPlayer {
|
||||
}
|
||||
|
||||
} else {
|
||||
if (P.p.getConfig().getBoolean("enableKickOnOverdrink", false)) {
|
||||
bPlayer.passOut(player);
|
||||
} else {
|
||||
bPlayer.quality = bPlayer.getQuality() * 100;
|
||||
bPlayer.drunkeness = 100;
|
||||
addPuke(player, 60 + (int) (Math.random() * 60));
|
||||
P.p.msg(player, "Du kannst nicht mehr trinken");
|
||||
}
|
||||
bPlayer.drinkCap(player);
|
||||
}
|
||||
P.p.msg(player, "Du bist nun " + bPlayer.drunkeness + "% betrunken, mit einer Qualität von " + bPlayer.getQuality());
|
||||
return true;
|
||||
@ -108,6 +101,18 @@ public class BPlayer {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Player has drunken too much
|
||||
public void drinkCap(Player player) {
|
||||
if (P.p.getConfig().getBoolean("enableKickOnOverdrink", false)) {
|
||||
passOut(player);
|
||||
} else {
|
||||
quality = getQuality() * 100;
|
||||
drunkeness = 100;
|
||||
addPuke(player, 60 + (int) (Math.random() * 60.0));
|
||||
P.p.msg(player, "Du kannst nicht mehr trinken");
|
||||
}
|
||||
}
|
||||
|
||||
// push the player around if he moves
|
||||
public static void playerMove(PlayerMoveEvent event) {
|
||||
BPlayer bPlayer = get(event.getPlayer().getName());
|
||||
@ -217,8 +222,12 @@ public class BPlayer {
|
||||
// wird der spieler noch gebraucht?
|
||||
players.remove(player.getName());
|
||||
|
||||
} else if (offlineDrunk - drunkeness >= 20) {
|
||||
// TODO some random teleport later
|
||||
} else if (offlineDrunk - drunkeness >= 30) {
|
||||
Location randomLoc = Wakeup.getRandom(player.getLocation());
|
||||
if (randomLoc != null) {
|
||||
player.teleport(randomLoc);
|
||||
P.p.msg(player, P.p.getConfig().getString("wakeString", "Ohh nein! Ich kann mich nicht erinnern, wie ich hier hergekommen bin..."));
|
||||
}
|
||||
}
|
||||
|
||||
offlineDrunk = 0;
|
||||
@ -421,6 +430,19 @@ public class BPlayer {
|
||||
return drunkeness;
|
||||
}
|
||||
|
||||
public void setData(int drunkeness, int quality) {
|
||||
if (quality > 0) {
|
||||
this.quality = quality * drunkeness;
|
||||
} else {
|
||||
if (this.quality == 0) {
|
||||
this.quality = 5 * drunkeness;
|
||||
} else {
|
||||
this.quality = getQuality() * drunkeness;
|
||||
}
|
||||
}
|
||||
this.drunkeness = drunkeness;
|
||||
}
|
||||
|
||||
public int getQuality() {
|
||||
if (drunkeness == 0) {
|
||||
P.p.errorLog("drunkeness should not be 0!");
|
||||
|
@ -156,6 +156,8 @@ public class Barrel {
|
||||
|
||||
// Saves all data
|
||||
public static void save(ConfigurationSection config, ConfigurationSection oldData) {
|
||||
P.p.createWorldSections(config);
|
||||
|
||||
if (!barrels.isEmpty()) {
|
||||
int id = 0;
|
||||
for (Barrel barrel : barrels) {
|
||||
|
@ -1,29 +1,31 @@
|
||||
package com.dre.brewery;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.ListIterator;
|
||||
import java.util.HashMap;
|
||||
import java.io.IOException;
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
import com.dre.brewery.listeners.BlockListener;
|
||||
import com.dre.brewery.listeners.PlayerListener;
|
||||
import com.dre.brewery.listeners.EntityListener;
|
||||
import com.dre.brewery.listeners.InventoryListener;
|
||||
import com.dre.brewery.listeners.WorldListener;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import com.dre.brewery.listeners.*;
|
||||
|
||||
public class P extends JavaPlugin {
|
||||
public static P p;
|
||||
public static int lastBackup = 0;
|
||||
@ -37,6 +39,8 @@ public class P extends JavaPlugin {
|
||||
public InventoryListener inventoryListener;
|
||||
public WorldListener worldListener;
|
||||
|
||||
public Permission permission = null;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
p = this;
|
||||
@ -44,12 +48,15 @@ public class P extends JavaPlugin {
|
||||
readConfig();
|
||||
readData();
|
||||
|
||||
initPermissions();
|
||||
|
||||
// Listeners
|
||||
blockListener = new BlockListener();
|
||||
playerListener = new PlayerListener();
|
||||
entityListener = new EntityListener();
|
||||
inventoryListener = new InventoryListener();
|
||||
worldListener = new WorldListener();
|
||||
getCommand("Brewery").setExecutor(new CommandListener());
|
||||
|
||||
p.getServer().getPluginManager().registerEvents(blockListener, p);
|
||||
p.getServer().getPluginManager().registerEvents(playerListener, p);
|
||||
@ -89,6 +96,13 @@ public class P extends JavaPlugin {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "[Brewery] " + ChatColor.DARK_RED + "ERROR: " + ChatColor.RED + msg);
|
||||
}
|
||||
|
||||
public void initPermissions() {
|
||||
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(Permission.class);
|
||||
if (permissionProvider != null) {
|
||||
permission = permissionProvider.getProvider();
|
||||
}
|
||||
}
|
||||
|
||||
public void readConfig() {
|
||||
|
||||
File file = new File(p.getDataFolder(), "config.yml");
|
||||
@ -253,6 +267,32 @@ public class P extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
// loading Wakeup
|
||||
if (data.contains("Wakeup." + uuid)) {
|
||||
ConfigurationSection section = data.getConfigurationSection("Wakeup." + uuid);
|
||||
for (String wakeup : section.getKeys(false)) {
|
||||
// loc of wakeup is splitted into x/y/z/pitch/yaw
|
||||
String loc = section.getString(wakeup);
|
||||
if (loc != null) {
|
||||
String[] splitted = loc.split("/");
|
||||
if (splitted.length == 5) {
|
||||
|
||||
double x = NumberUtils.toDouble(splitted[0]);
|
||||
double y = NumberUtils.toDouble(splitted[1]);
|
||||
double z = NumberUtils.toDouble(splitted[2]);
|
||||
float pitch = NumberUtils.toFloat(splitted[3]);
|
||||
float yaw = NumberUtils.toFloat(splitted[4]);
|
||||
Location location = new Location(world, x, y, z, yaw, pitch);
|
||||
|
||||
Wakeup.wakeups.add(new Wakeup(location));
|
||||
|
||||
} else {
|
||||
errorLog("Incomplete Location-Data in data.yml: " + section.getCurrentPath() + "." + wakeup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -288,6 +328,10 @@ public class P extends JavaPlugin {
|
||||
BPlayer.save(configFile.createSection("Player"));
|
||||
}
|
||||
|
||||
if (!Wakeup.wakeups.isEmpty() || oldData.contains("Wakeup")) {
|
||||
Wakeup.save(configFile.createSection("Wakeup"), oldData.getConfigurationSection("Wakeup"));
|
||||
}
|
||||
|
||||
try {
|
||||
configFile.save(datafile);
|
||||
} catch (IOException e) {
|
||||
@ -297,10 +341,16 @@ public class P extends JavaPlugin {
|
||||
lastSave = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Utility
|
||||
|
||||
|
||||
public int parseInt(String string) {
|
||||
return NumberUtils.toInt(string, 0);
|
||||
}
|
||||
|
||||
// gets the Name of a DXL World
|
||||
public String getDxlName(String worldName) {
|
||||
File dungeonFolder = new File(worldName);
|
||||
if (dungeonFolder.isDirectory()) {
|
||||
@ -315,10 +365,47 @@ public class P extends JavaPlugin {
|
||||
return null;
|
||||
}
|
||||
|
||||
// create empty World save Sections
|
||||
public void createWorldSections(ConfigurationSection section) {
|
||||
for (World world : p.getServer().getWorlds()) {
|
||||
String worldName = world.getName();
|
||||
if (worldName.startsWith("DXL_")) {
|
||||
worldName = getDxlName(worldName);
|
||||
} else {
|
||||
worldName = world.getUID().toString();
|
||||
}
|
||||
section.createSection(worldName);
|
||||
}
|
||||
}
|
||||
|
||||
// prints a list of Strings at the specified page
|
||||
public void list (CommandSender sender, ArrayList<String> strings, int page) {
|
||||
int pages = (int) Math.ceil(strings.size() / 7F);
|
||||
if (page > pages || page < 1) {
|
||||
page = 1;
|
||||
}
|
||||
|
||||
msg(sender, ChatColor.GRAY + "-------------- " + ChatColor.WHITE + "Seite " + ChatColor.GOLD + page + ChatColor.WHITE + "/" + ChatColor.GOLD + pages + ChatColor.GRAY + " --------------");
|
||||
|
||||
ListIterator<String> iter = strings.listIterator((page - 1) * 7);
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
if (iter.hasNext()) {
|
||||
msg(sender, iter.next());
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String white() {
|
||||
return ChatColor.WHITE + "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Runnables
|
||||
|
||||
public class DrunkRunnable implements Runnable {
|
||||
|
||||
public DrunkRunnable() {
|
||||
|
271
src/com/dre/brewery/Wakeup.java
Normal file
271
src/com/dre/brewery/Wakeup.java
Normal file
@ -0,0 +1,271 @@
|
||||
package com.dre.brewery;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Wakeup {
|
||||
|
||||
public static ArrayList<Wakeup> wakeups = new ArrayList<Wakeup>();
|
||||
public static P p = P.p;
|
||||
public static ChatColor g = ChatColor.GOLD;
|
||||
public static ChatColor w = ChatColor.WHITE;
|
||||
public static ChatColor r = ChatColor.RED;
|
||||
public static ChatColor gr = ChatColor.GREEN;
|
||||
public static int checkId = -1;
|
||||
public static Player checkPlayer = null;
|
||||
|
||||
private Location loc;
|
||||
private boolean active = true;
|
||||
|
||||
public Wakeup(Location loc) {
|
||||
this.loc = loc;
|
||||
}
|
||||
|
||||
// get the nearest of two random Wakeup-Locations
|
||||
public static Location getRandom(Location playerLoc) {
|
||||
if (wakeups.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrayList<Wakeup> worldWakes = new ArrayList<Wakeup>();
|
||||
|
||||
for (Wakeup wakeup : wakeups) {
|
||||
if (wakeup.active) {
|
||||
if (wakeup.loc.getWorld().equals(playerLoc.getWorld())) {
|
||||
worldWakes.add(wakeup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (worldWakes.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Wakeup w1 = calcRandom(worldWakes);
|
||||
worldWakes.remove(w1);
|
||||
|
||||
while (!w1.check()) {
|
||||
p.errorLog("Please Check Wakeup-Location with id: " + g + wakeups.indexOf(w1));
|
||||
|
||||
w1 = calcRandom(worldWakes);
|
||||
if (w1 == null) {
|
||||
return null;
|
||||
}
|
||||
worldWakes.remove(w1);
|
||||
}
|
||||
|
||||
Wakeup w2 = calcRandom(worldWakes);
|
||||
if (w2 != null) {
|
||||
worldWakes.remove(w2);
|
||||
|
||||
while (!w2.check()) {
|
||||
p.errorLog("Please Check Wakeup-Location with id: " + g + wakeups.indexOf(w2));
|
||||
|
||||
w2 = calcRandom(worldWakes);
|
||||
if (w2 == null) {
|
||||
return w1.loc;
|
||||
}
|
||||
worldWakes.remove(w2);
|
||||
}
|
||||
|
||||
|
||||
if (w1.loc.distance(playerLoc) > w2.loc.distance(playerLoc)) {
|
||||
return w2.loc;
|
||||
}
|
||||
}
|
||||
return w1.loc;
|
||||
}
|
||||
|
||||
public static Wakeup calcRandom(ArrayList<Wakeup> worldWakes) {
|
||||
if (worldWakes.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return worldWakes.get((int) Math.round(Math.random() * ((float) worldWakes.size() - 1.0)));
|
||||
}
|
||||
|
||||
public static void set(CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
|
||||
Player player = (Player) sender;
|
||||
wakeups.add(new Wakeup(player.getLocation()));
|
||||
p.msg(sender, gr + "Aufwachpunkt mit id: " + g + (wakeups.size() - 1) + gr + " wurde erfolgreich erstellt!");
|
||||
|
||||
} else {
|
||||
p.msg(sender, r + "Dieser Befehl kann nur als Spieler ausgeführt werden");
|
||||
}
|
||||
}
|
||||
|
||||
public static void remove(CommandSender sender, int id) {
|
||||
if (wakeups.isEmpty() || id < 0 || id >= wakeups.size()) {
|
||||
p.msg(sender, r +"Der Aufwachpunkt mit der id: " + g + id + r + " existiert nicht!");
|
||||
return;
|
||||
}
|
||||
|
||||
Wakeup wakeup = wakeups.get(id);
|
||||
|
||||
if (wakeup.active) {
|
||||
wakeup.active = false;
|
||||
p.msg(sender, gr + "Der Aufwachpunkt mit der id: " + g + id + gr + " wurde erfolgreich gelöscht!");
|
||||
|
||||
} else {
|
||||
p.msg(sender, r + "Der Aufwachpunkt mit der id: " + g + id + r + " wurde bereits gelöscht!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void list(CommandSender sender, int page, String worldOnly) {
|
||||
if (wakeups.isEmpty()) {
|
||||
p.msg(sender, r + "Es wurden noch keine Aufwachpunkte erstellt!");
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<String> locs = new ArrayList<String>();
|
||||
for (int id = 0; id < wakeups.size(); id++) {
|
||||
|
||||
Wakeup wakeup = wakeups.get(id);
|
||||
|
||||
String s = ChatColor.STRIKETHROUGH.toString();
|
||||
if (wakeup.active) {
|
||||
s = "";
|
||||
}
|
||||
|
||||
String world = wakeup.loc.getWorld().getName();
|
||||
|
||||
if (worldOnly == null || world.equalsIgnoreCase(worldOnly)) {
|
||||
int x = (int) wakeup.loc.getX();
|
||||
int y = (int) wakeup.loc.getY();
|
||||
int z = (int) wakeup.loc.getZ();
|
||||
|
||||
locs.add(g + s + id + w + s + ": " + world + " " + x + "," + y + "," + z);
|
||||
}
|
||||
}
|
||||
p.list(sender, locs, page);
|
||||
}
|
||||
|
||||
public static void check(CommandSender sender, int id, boolean all) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (!all) {
|
||||
if (wakeups.isEmpty() || id >= wakeups.size()) {
|
||||
p.msg(sender, r + "Der Aufwachpunkt mit der id: " + g + id + r + " existiert nicht!");
|
||||
return;
|
||||
}
|
||||
|
||||
Wakeup wakeup = wakeups.get(id);
|
||||
if (wakeup.check()) {
|
||||
player.teleport(wakeup.loc);
|
||||
} else {
|
||||
String world = wakeup.loc.getWorld().getName();
|
||||
int x = (int) wakeup.loc.getX();
|
||||
int y = (int) wakeup.loc.getY();
|
||||
int z = (int) wakeup.loc.getZ();
|
||||
p.msg(sender, r + "Der Aufwachpunkt mit der id: " + g + id + r + " An Position " + g + world + " " + x + "," + y + "," + z + r + " ist mit Blöcken gefüllt!");
|
||||
}
|
||||
|
||||
} else {
|
||||
if (wakeups.isEmpty()) {
|
||||
p.msg(sender, r + "Es wurden noch keine Aufwachpunkte erstellt!");
|
||||
return;
|
||||
}
|
||||
if (checkPlayer != null && checkPlayer != player) {
|
||||
checkId = -1;
|
||||
}
|
||||
checkPlayer = player;
|
||||
tpNext();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
p.msg(sender, r + "Dieser Befehl kann nur als Spieler ausgeführt werden");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean check() {
|
||||
return (!loc.getBlock().getType().isSolid() && !loc.getBlock().getRelative(0, 1, 0).getType().isSolid());
|
||||
}
|
||||
|
||||
public static void tpNext() {
|
||||
checkId++;
|
||||
if (checkId >= wakeups.size()) {
|
||||
p.msg(checkPlayer, gr + "Dies war der letzte Aufwachpunkt");
|
||||
checkId = -1;
|
||||
checkPlayer = null;
|
||||
return;
|
||||
}
|
||||
|
||||
Wakeup wakeup = wakeups.get(checkId);
|
||||
if (!wakeup.active) {
|
||||
tpNext();
|
||||
return;
|
||||
}
|
||||
|
||||
String world = wakeup.loc.getWorld().getName();
|
||||
int x = (int) wakeup.loc.getX();
|
||||
int y = (int) wakeup.loc.getY();
|
||||
int z = (int) wakeup.loc.getZ();
|
||||
|
||||
if (wakeup.check()) {
|
||||
p.msg(checkPlayer, "Teleport zu Aufwachpunkt mit der id: " + g + checkId + w + " An Position: " + g + world + " " + x + "," + y + "," + z);
|
||||
checkPlayer.teleport(wakeup.loc);
|
||||
} else {
|
||||
p.msg(checkPlayer, r + "Der Aufwachpunkt mit der id: " + g + checkId + r + " An Position " + g + world + " " + x + "," + y + "," + z + r + " ist mit Blöcken gefüllt!");
|
||||
}
|
||||
p.msg(checkPlayer, "Zum nächsten Aufwachpunkt: Mit Faust in die Luft schlagen");
|
||||
p.msg(checkPlayer, "Zum Abbrechen: " + ChatColor.BLUE + "/br Wakeup Cancel");
|
||||
}
|
||||
|
||||
public static void cancel(CommandSender sender) {
|
||||
if (checkPlayer != null) {
|
||||
checkPlayer = null;
|
||||
checkId = -1;
|
||||
p.msg(sender, g + "Aufwachpunkte-Check wurde abgebrochen");
|
||||
return;
|
||||
}
|
||||
p.msg(sender, r + "Es läuft kein Aufwachpunkte-Check");
|
||||
}
|
||||
|
||||
|
||||
public static void save(ConfigurationSection section, ConfigurationSection oldData) {
|
||||
p.createWorldSections(section);
|
||||
|
||||
// loc is saved as a String in world sections with format x/y/z/pitch/yaw
|
||||
if (!wakeups.isEmpty()) {
|
||||
|
||||
Iterator<Wakeup> iter = wakeups.iterator();
|
||||
for (int id = 0; iter.hasNext(); id++) {
|
||||
Wakeup wakeup = iter.next();
|
||||
|
||||
if (!wakeup.active) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String worldName = wakeup.loc.getWorld().getName();
|
||||
String prefix = null;
|
||||
|
||||
if (worldName.startsWith("DXL_")) {
|
||||
prefix = p.getDxlName(worldName) + "." + id;
|
||||
} else {
|
||||
prefix = wakeup.loc.getWorld().getUID().toString() + "." + id;
|
||||
}
|
||||
|
||||
section.set(prefix, wakeup.loc.getX() + "/" + wakeup.loc.getY() + "/" + wakeup.loc.getZ() + "/" + wakeup.loc.getPitch() + "/" + wakeup.loc.getYaw());
|
||||
}
|
||||
}
|
||||
|
||||
// copy Wakeups that are not loaded
|
||||
if (oldData != null){
|
||||
for (String uuid : oldData.getKeys(false)) {
|
||||
if (!section.contains(uuid)) {
|
||||
section.set(uuid, oldData.get(uuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
260
src/com/dre/brewery/listeners/CommandListener.java
Normal file
260
src/com/dre/brewery/listeners/CommandListener.java
Normal file
@ -0,0 +1,260 @@
|
||||
package com.dre.brewery.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.dre.brewery.P;
|
||||
import com.dre.brewery.Wakeup;
|
||||
import com.dre.brewery.BPlayer;
|
||||
|
||||
public class CommandListener implements CommandExecutor {
|
||||
|
||||
public P p = P.p;
|
||||
public ChatColor g = ChatColor.GOLD;
|
||||
public ChatColor b = ChatColor.BLUE;
|
||||
public ChatColor r = ChatColor.RED;
|
||||
public ChatColor gr = ChatColor.GREEN;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
String cmd = "help";
|
||||
if (args.length > 0) {
|
||||
cmd = args[0];
|
||||
}
|
||||
|
||||
if (cmd.equalsIgnoreCase("help")) {
|
||||
|
||||
cmdHelp(sender, args);
|
||||
|
||||
} else if (cmd.equalsIgnoreCase("reload")) {
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.reload")) {
|
||||
// TODO: reloading
|
||||
} else {
|
||||
p.msg(sender, r + "Du hast keine Rechte dies zu tun!");
|
||||
}
|
||||
|
||||
} else if (cmd.equalsIgnoreCase("wakeup")) {
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.wakeup")) {
|
||||
cmdWakeup(sender, args);
|
||||
} else {
|
||||
p.msg(sender, r + "Du hast keine Rechte dies zu tun!");
|
||||
}
|
||||
|
||||
} else if (cmd.equalsIgnoreCase("create")) {
|
||||
|
||||
//TODO: create command
|
||||
|
||||
} else if (cmd.equalsIgnoreCase("info")) {
|
||||
|
||||
if (args.length > 1) {
|
||||
if (p.permission.has(sender, "brewery.cmd.infoOther")) {
|
||||
cmdInfo(sender, args[1]);
|
||||
} else {
|
||||
p.msg(sender, r + "Du hast keine Rechte dies zu tun!");
|
||||
}
|
||||
} else {
|
||||
if (p.permission.has(sender, "brewery.cmd.info")) {
|
||||
cmdInfo(sender, null);
|
||||
} else {
|
||||
p.msg(sender, r + "Du hast keine Rechte dies zu tun!");
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (p.getServer().getPlayerExact(cmd) != null || BPlayer.players.containsKey(cmd)) {
|
||||
|
||||
if (args.length == 1) {
|
||||
if (p.permission.has(sender, "brewery.cmd.infoOther")) {
|
||||
cmdInfo(sender, cmd);
|
||||
}
|
||||
} else {
|
||||
if (p.permission.has(sender, "brewery.cmd.player")) {
|
||||
cmdPlayer(sender, args);
|
||||
} else {
|
||||
p.msg(sender, r + "Du hast keine Rechte dies zu tun!");
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
p.msg(sender, "Unbekannter Befehl.");
|
||||
p.msg(sender, "benutze " + g + "/br help " + ChatColor.WHITE + "um die Hilfe anzuzeigen");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void cmdHelp(CommandSender sender, String[] args) {
|
||||
|
||||
int page = 1;
|
||||
if (args.length > 1) {
|
||||
page = p.parseInt(args[1]);
|
||||
}
|
||||
|
||||
ArrayList<String> commands = getCommands(sender);
|
||||
|
||||
if (page == 1) {
|
||||
p.msg(sender, g + p.getDescription().getName() + " v" + p.getDescription().getVersion());
|
||||
}
|
||||
|
||||
p.list(sender, commands, page);
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<String> getCommands(CommandSender sender) {
|
||||
|
||||
ArrayList<String> cmds = new ArrayList<String>();
|
||||
cmds.add(g + "/br help <Seite> " + b + "Zeigt eine bestimmte Hilfeseite an");
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.reload")) {
|
||||
cmds.add(g + "/br reload " + b + " Plugin neuladen");
|
||||
}
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.wakeup")) {
|
||||
cmds.add(g + "/br Wakeup List <Seite>" + b + " Listet alle Aufwachpunkte auf");
|
||||
cmds.add(g + "/br Wakeup List <Seite> <Welt>" + b + " Listet die Aufwachpunkte einer Welt auf");
|
||||
cmds.add(g + "/br Wakeup Check " + b + " Teleportiert zu allen Aufwachpunkten");
|
||||
cmds.add(g + "/br Wakeup Check <id> " + b + " Teleportiert zu einem Aufwachpunkt");
|
||||
cmds.add(g + "/br Wakeup Add " + b + " Setzt einen Aufwachpunkt");
|
||||
cmds.add(g + "/br Wakeup Remove <id> " + b + " Entfernt einen Aufwachpunkt");
|
||||
}
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.player")) {
|
||||
cmds.add (g + "/br <Spieler> <%Trunkenheit> <Qualität>" + b + " Setzt Trunkenheit (und Qualität) eines Spielers");
|
||||
}
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.info")) {
|
||||
cmds.add (g + "/br Info" + b + " Zeigt deine aktuelle Trunkenheit und Qualität an");
|
||||
}
|
||||
|
||||
if (p.permission.has(sender, "brewery.cmd.infoOther")) {
|
||||
cmds.add (g + "/br Info <Spieler>" + b + " Zeigt die aktuelle Trunkenheit und Qualität von <Spieler> an");
|
||||
}
|
||||
|
||||
return cmds;
|
||||
}
|
||||
|
||||
public void cmdWakeup(CommandSender sender, String[] args) {
|
||||
|
||||
if (args.length == 1) {
|
||||
cmdHelp(sender, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("add")) {
|
||||
|
||||
Wakeup.set(sender);
|
||||
|
||||
} else if (args[1].equalsIgnoreCase("list")){
|
||||
|
||||
int page = 1;
|
||||
String world = null;
|
||||
if (args.length > 2) {
|
||||
page = p.parseInt(args[2]);
|
||||
}
|
||||
if (args.length > 3) {
|
||||
world = args[3];
|
||||
}
|
||||
Wakeup.list(sender, page, world);
|
||||
|
||||
} else if (args[1].equalsIgnoreCase("remove")){
|
||||
|
||||
if (args.length > 2) {
|
||||
int id = p.parseInt(args[2]);
|
||||
Wakeup.remove(sender, id);
|
||||
} else {
|
||||
p.msg(sender, "Benutzung:");
|
||||
p.msg(sender, g + "/br Wakeup Remove <id>");
|
||||
}
|
||||
|
||||
} else if (args[1].equalsIgnoreCase("check")){
|
||||
|
||||
int id = -1;
|
||||
if (args.length > 2) {
|
||||
id = p.parseInt(args[2]);
|
||||
if (id < 0) {
|
||||
id = 0;
|
||||
}
|
||||
}
|
||||
Wakeup.check(sender, id, id == -1);
|
||||
|
||||
} else if (args[1].equalsIgnoreCase("cancel")){
|
||||
|
||||
Wakeup.cancel(sender);
|
||||
|
||||
} else {
|
||||
|
||||
p.msg(sender, "Unbekannter Befehl.");
|
||||
p.msg(sender, "benutze " + g + "/br help " + ChatColor.WHITE + "um die Hilfe anzuzeigen");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void cmdPlayer(CommandSender sender, String[] args) {
|
||||
|
||||
int drunkeness = p.parseInt(args[1]);
|
||||
int quality = -1;
|
||||
if (args.length > 2) {
|
||||
quality = p.parseInt(args[2]);
|
||||
if (quality < 1 || quality > 10) {
|
||||
p.msg(sender, r + "Die Qualität muss zwischen 1 und 10 liegen!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String playerName = args[0];
|
||||
BPlayer bPlayer = BPlayer.get(playerName);
|
||||
if (bPlayer == null) {
|
||||
if (drunkeness == 0) {
|
||||
return;
|
||||
}
|
||||
bPlayer = new BPlayer();
|
||||
BPlayer.players.put(playerName, bPlayer);
|
||||
}
|
||||
|
||||
if (drunkeness == 0) {
|
||||
BPlayer.players.remove(playerName);
|
||||
} else {
|
||||
bPlayer.setData(drunkeness, quality);
|
||||
}
|
||||
|
||||
p.msg(sender, gr + playerName + " ist nun " + g + drunkeness + "% " + gr + "betrunken, mit einer Qualität von " + g + bPlayer.getQuality());
|
||||
if (drunkeness > 100) {
|
||||
bPlayer.drinkCap(p.getServer().getPlayer(playerName));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void cmdInfo(CommandSender sender, String playerName) {
|
||||
|
||||
if (playerName == null) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
playerName = player.getName();
|
||||
} else {
|
||||
p.msg(sender, r + "Dieser Befehl kann nur als Spieler ausgeführt werden");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
BPlayer bPlayer = BPlayer.get(playerName);
|
||||
if (bPlayer == null) {
|
||||
p.msg(sender, playerName + " ist nicht betrunken");
|
||||
} else {
|
||||
p.msg(sender, playerName + " ist " + g + bPlayer.getDrunkeness() + "% " + ChatColor.WHITE + "betrunken, mit einer Qualität von " + g + bPlayer.getQuality());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -21,6 +21,7 @@ import com.dre.brewery.Brew;
|
||||
import com.dre.brewery.Barrel;
|
||||
import com.dre.brewery.BPlayer;
|
||||
import com.dre.brewery.Words;
|
||||
import com.dre.brewery.Wakeup;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
@ -91,6 +92,16 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if (event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||
if (!event.hasItem()) {
|
||||
if (Wakeup.checkPlayer != null) {
|
||||
if (event.getPlayer() == Wakeup.checkPlayer) {
|
||||
Wakeup.tpNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// player drinks a custom potion
|
||||
@ -119,7 +130,7 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
|
||||
// player talks while drunk, but he cant speak very well
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
if (BPlayer.players.containsKey(event.getPlayer().getName())) {
|
||||
Words.playerChat(event);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.dre.brewery.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.bukkit.event.world.WorldUnloadEvent;
|
||||
@ -14,7 +15,6 @@ public class WorldListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onWorldLoad(WorldLoadEvent event) {
|
||||
P.p.log("loading world with uuid " + event.getWorld().getUID().toString());
|
||||
World world = event.getWorld();
|
||||
|
||||
if (world.getName().startsWith("DXL_")) {
|
||||
@ -24,10 +24,8 @@ public class WorldListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onWorldUnload(WorldUnloadEvent event) {
|
||||
P.p.log("Unloading world with uuid " + event.getWorld().getUID().toString());
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
P.p.saveData();
|
||||
Barrel.onUnload(event.getWorld().getName());
|
||||
|
Loading…
Reference in New Issue
Block a user