v0.94
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="MobArena.jar"/>
|
||||
<classpathentry kind="lib" path="D:/General/Java/Minecraft/lib/BOSEconomy7.jar"/>
|
||||
<classpathentry kind="lib" path="D:/General/Java/Minecraft/lib/Essentials.jar"/>
|
||||
<classpathentry kind="lib" path="D:/General/Java/Minecraft/lib/iCo4.jar"/>
|
||||
<classpathentry kind="lib" path="D:/General/Java/Minecraft/lib/iCo5.jar"/>
|
||||
<classpathentry kind="lib" path="D:/General/Java/Minecraft/lib/MeanAdmins.jar"/>
|
||||
<classpathentry kind="lib" path="D:/General/Java/Minecraft/lib/Permissions.jar"/>
|
||||
<classpathentry kind="lib" path="D:/General/Java/Minecraft/lib/Register.jar"/>
|
||||
<classpathentry kind="lib" path="D:/General/Java/Minecraft/lib/craftbukkit-0.0.1-SNAPSHOT.jar"/>
|
||||
<classpathentry kind="lib" path="D:/General/Java/Minecraft/lib/iCo6.jar"/>
|
||||
<classpathentry kind="lib" path="D:/General/Java/Minecraft/lib/MultiCurrency.jar"/>
|
||||
<classpathentry kind="lib" path="D:/General/Java/Minecraft/lib/jdom.jar"/>
|
||||
<classpathentry kind="lib" path="D:/General/Java/Minecraft/lib/Spout.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>MobArena</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
Go to the Wiki for more info: https://github.com/garbagemule/MobArena/wiki/dev-v0.94
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="MobArena" default="dist" basedir=".">
|
||||
<property name="pluginname" value="MobArena"/>
|
||||
<property name="server" location="D:\General\Java\Minecraft\Minecraft Server\plugins"/>
|
||||
|
||||
<property name="src" location="src"/>
|
||||
<property name="bin" location="bin"/>
|
||||
<property name="lib" location="../lib"/>
|
||||
<property name="res" location="resources"/>
|
||||
<path id="classpath">
|
||||
<fileset dir="${lib}" includes="**/*.jar"/>
|
||||
<fileset dir="${res}" includes="**/*.*"/>
|
||||
</path>
|
||||
|
||||
<target name="init">
|
||||
<mkdir dir="${bin}"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile the source and put in the bin-folder -->
|
||||
<target name="compile" depends="init">
|
||||
<javac srcdir="${src}" destdir="${bin}" includeantruntime="false" classpathref="classpath"/>
|
||||
</target>
|
||||
|
||||
<!-- Build a .jar and copy to server's plugins-folder -->
|
||||
<target name="dist" depends="compile">
|
||||
<delete file="${pluginname}.jar"/>
|
||||
<jar jarfile="${pluginname}.jar">
|
||||
<!-- Include the class-files (bin) and the resources (res) -->
|
||||
<fileset dir="${bin}"/>
|
||||
<fileset dir="${res}"/>
|
||||
<!-- Set up the classpath so MobArena can find JDOM if needed -->
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="com.garbagemule.MobArena.MobArena"/>
|
||||
<attribute name="Class-Path" value="plugins/MobArena/lib/jdom.jar MobArena/lib/jdom.jar"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
<!-- Copy to server and clean up -->
|
||||
<copy file="${pluginname}.jar" tofile="${server}/${pluginname}.jar"/>
|
||||
<delete dir="${bin}"/>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,124 @@
|
||||
name: MobArena
|
||||
main: com.garbagemule.MobArena.MobArena
|
||||
version: 0.94
|
||||
softdepend: [Spout,Permissions,MultiVerse,XcraftGate,Towny]
|
||||
commands:
|
||||
ma:
|
||||
description: Base command for MobArena
|
||||
usage: |
|
||||
/ma join - Join the arena.
|
||||
/ma leave - Leave the arena.
|
||||
/ma notready - List of players who aren't ready.
|
||||
/ma spectate - Warp to the spectator area.
|
||||
mobarena:
|
||||
description: Base command for MobArena
|
||||
usage: |
|
||||
/mobarena join - Join the arena.
|
||||
/mobarena leave - Leave the arena.
|
||||
/mobarena notready - List of players who aren't ready.
|
||||
/mobarena spectate - Warp to the spectator area.
|
||||
permissions:
|
||||
mobarena.use.*:
|
||||
description: Gives access to usage commands
|
||||
default: true
|
||||
children:
|
||||
mobarena.use.join: true
|
||||
mobarena.use.spec: true
|
||||
mobarena.use.leave: true
|
||||
mobarena.use.join:
|
||||
default: true
|
||||
mobarena.use.spec:
|
||||
default: true
|
||||
mobarena.use.leave:
|
||||
default: true
|
||||
|
||||
mobarena.admin.*:
|
||||
description: Gives access to admin commands
|
||||
default: op
|
||||
children:
|
||||
mobarena.admin.enable: true
|
||||
mobarena.admin.kick: true
|
||||
mobarena.admin.restore: true
|
||||
mobarena.admin.force.end: true
|
||||
mobarena.admin.force.start: true
|
||||
mobarena.admin.config.reload: true
|
||||
mobarena.admin.enable:
|
||||
default: false
|
||||
mobarena.admin.kick:
|
||||
default: false
|
||||
mobarena.admin.restore:
|
||||
default: false
|
||||
mobarena.admin.force.end:
|
||||
default: false
|
||||
mobarena.admin.force.start:
|
||||
default: false
|
||||
mobarena.admin.config.reload:
|
||||
default: false
|
||||
|
||||
mobarena.setup.*:
|
||||
description: Gives access to setup commands
|
||||
default: op
|
||||
children:
|
||||
mobarena.setup.arena: true
|
||||
mobarena.setup.setarena: true
|
||||
mobarena.setup.addarena: true
|
||||
mobarena.setup.delarena: true
|
||||
mobarena.setup.protect: true
|
||||
mobarena.setup.editarena: true
|
||||
mobarena.setup.setregion: true
|
||||
mobarena.setup.expandregion: true
|
||||
mobarena.setup.showregion: true
|
||||
mobarena.setup.setlobbyregion: true
|
||||
mobarena.setup.expandlobbyregion: true
|
||||
mobarena.setup.setwarp: true
|
||||
mobarena.setup.spawnpoints: true
|
||||
mobarena.setup.addspawn: true
|
||||
mobarena.setup.delspawn: true
|
||||
mobarena.setup.containers: true
|
||||
mobarena.setup.addcontainer: true
|
||||
mobarena.setup.delcontainer: true
|
||||
mobarena.setup.checkdata: true
|
||||
mobarena.setup.autogenerate: true
|
||||
mobarena.setup.autodegenerate: true
|
||||
mobarena.setup.arena:
|
||||
default: false
|
||||
mobarena.setup.setarena:
|
||||
default: false
|
||||
mobarena.setup.addarena:
|
||||
default: false
|
||||
mobarena.setup.delarena:
|
||||
default: false
|
||||
mobarena.setup.protect:
|
||||
default: false
|
||||
mobarena.setup.editarena:
|
||||
default: false
|
||||
mobarena.setup.setregion:
|
||||
default: false
|
||||
mobarena.setup.expandregion:
|
||||
default: false
|
||||
mobarena.setup.showregion:
|
||||
default: false
|
||||
mobarena.setup.setlobbyregion:
|
||||
default: false
|
||||
mobarena.setup.expandlobbyregion:
|
||||
default: false
|
||||
mobarena.setup.setwarp:
|
||||
default: false
|
||||
mobarena.setup.spawnpoints:
|
||||
default: false
|
||||
mobarena.setup.addspawn:
|
||||
default: false
|
||||
mobarena.setup.delspawn:
|
||||
default: false
|
||||
mobarena.setup.containers:
|
||||
default: false
|
||||
mobarena.setup.addcontainer:
|
||||
default: false
|
||||
mobarena.setup.delcontainer:
|
||||
default: false
|
||||
mobarena.setup.checkdata:
|
||||
default: false
|
||||
mobarena.setup.autogenerate:
|
||||
default: false
|
||||
mobarena.setup.autodegenerate:
|
||||
default: false
|
||||
@@ -0,0 +1,51 @@
|
||||
ARENA_START=Let the slaughter begin!
|
||||
ARENA_END=Arena finished.
|
||||
ARENA_DOES_NOT_EXIST=That arena does not exist. Type /ma arenas for a list.
|
||||
JOIN_PLAYER_JOINED=
|
||||
JOIN_NOT_ENABLED=MobArena is not enabled.
|
||||
JOIN_IN_OTHER_ARENA=You are already in an arena! Leave that one first.
|
||||
JOIN_ARENA_NOT_ENABLED=This arena is not enabled.
|
||||
JOIN_ARENA_NOT_SETUP=This arena has not been set up yet.
|
||||
JOIN_ARENA_PERMISSION=You don't have permission to join this arena.
|
||||
JOIN_FEE_REQUIRED=Insufficient funds. Price: %
|
||||
JOIN_FEE_PAID=Price to join was: %
|
||||
JOIN_ARENA_IS_RUNNING=This arena is in already progress.
|
||||
JOIN_ALREADY_PLAYING=You are already playing!
|
||||
JOIN_ARG_NEEDED=You must specify an arena. Type /ma arenas for a list.
|
||||
JOIN_TOO_FAR=You are too far away from the arena to join/spectate.
|
||||
JOIN_EMPTY_INV=You must empty your inventory to join the arena.
|
||||
JOIN_PLAYER_LIMIT_REACHED=The player limit of this arena has been reached.
|
||||
JOIN_STORE_INV_FAIL=Failed to store inventory. Try again.
|
||||
LEAVE_PLAYER_LEFT=You left the arena. Thanks for playing!
|
||||
LEAVE_NOT_PLAYING=You are not in the arena.
|
||||
PLAYER_DIED=% died!
|
||||
SPEC_PLAYER_SPECTATE=Enjoy the show!
|
||||
SPEC_NOT_RUNNING=This arena isn't running.
|
||||
SPEC_ARG_NEEDED=You must specify an arena. Type /ma arenas for a list.
|
||||
SPEC_EMPTY_INV=Empty your inventory first!
|
||||
SPEC_ALREADY_PLAYING=Can't spectate when in the arena!
|
||||
NOT_READY_PLAYERS=Not ready: %
|
||||
FORCE_START_STARTED=Forced arena start.
|
||||
FORCE_START_RUNNING=Arena has already started.
|
||||
FORCE_START_NOT_READY=Can't force start, no players are ready.
|
||||
FORCE_END_ENDED=Forced arena end.
|
||||
FORCE_END_EMPTY=No one is in the arena.
|
||||
FORCE_END_IDLE=You weren't quick enough!
|
||||
REWARDS_GIVE=Here are all of your rewards!
|
||||
LOBBY_CLASS_PICKED=You have chosen % as your class!
|
||||
LOBBY_CLASS_RANDOM=You will get a random class on arena start.
|
||||
LOBBY_CLASS_PERMISSION=You don't have permission to use this class!
|
||||
LOBBY_PLAYER_READY=You have been flagged as ready!
|
||||
LOBBY_DROP_ITEM=No sharing before the arena starts!
|
||||
LOBBY_PICK_CLASS=You must first pick a class!
|
||||
LOBBY_RIGHT_CLICK=Punch the sign. Don't right-click.
|
||||
WARP_TO_ARENA=Can't warp to the arena during battle!
|
||||
WARP_FROM_ARENA=Warping not allowed in the arena!
|
||||
WAVE_DEFAULT=Get ready for wave #%!
|
||||
WAVE_SPECIAL=Get ready for wave #%! [SPECIAL]
|
||||
WAVE_REWARD=You just earned a reward: %
|
||||
MISC_LIST_ARENAS=Available arenas: %
|
||||
MISC_LIST_PLAYERS=Live players: %
|
||||
MISC_COMMAND_NOT_ALLOWED=You can't use that command in the arena!
|
||||
MISC_NO_ACCESS=You don't have access to this command.
|
||||
MISC_NONE=<none>
|
||||
@@ -0,0 +1,113 @@
|
||||
### MobArena Configuration File
|
||||
### Please visit the MobArena Wiki here: http://goo.gl/F5TTc for more details
|
||||
### on how to set up this file.
|
||||
### Note that you CAN'T use tabs in this file! Always use spaces!
|
||||
|
||||
### GLOBAL SETTINGS
|
||||
# These settings are arena-independent and count in all arenas. Note that if
|
||||
# enabled: false in the global settings, MobArena is disabled globally, and
|
||||
# arena-specific enabled-values do not matter. If true, however, the per-arena
|
||||
# enabled-values count.
|
||||
global-settings:
|
||||
enabled: true
|
||||
allowed-commands: /list, /pl
|
||||
update-notification: true
|
||||
|
||||
### CLASS SETUP
|
||||
# Items can be written as either their data value (numbers) or their Material
|
||||
# type (names); check the Wiki for links to lists of both.
|
||||
# The notation is <item>:<amount>. If no amount is given, 1 is assumed. Sub-
|
||||
# types can be created
|
||||
# Item SUBTYPES (wool/dye colors) are written as <item>:<subtype>:<amount>,
|
||||
# but here, the amount is REQUIRED, even if it is just 1.
|
||||
# Note: If you want to specify only one item, but apostrophes around that one
|
||||
# item, e.g.: items: '278'
|
||||
# Note: For every bone a class has, one PET WOLF will spawn upon arena start,
|
||||
# which will assist the player in the arena session.
|
||||
classes:
|
||||
Knight:
|
||||
items: diamond_sword, grilled_pork:2
|
||||
armor: 306,307,308,309
|
||||
Tank:
|
||||
items: iron_sword, grilled_pork:3, apple
|
||||
armor: 310,311,312,313
|
||||
Archer:
|
||||
items: wood_sword, bow, arrow:256, grilled_pork, bone
|
||||
armor: 298,299,300,301
|
||||
Chef:
|
||||
items: stone_sword, bread:6, grilled_pork:4, mushroom_soup, cake:5
|
||||
armor: 314,315,316,317
|
||||
Oddjob:
|
||||
items: stone_sword, flint_and_steel, netherrack:2, tnt:4, pork:3
|
||||
armor: 298,299,300,301
|
||||
|
||||
### ARENA SETUP
|
||||
# The arena setup is split into 4 different sections per arena: settings,
|
||||
# waves, rewards and coords (not shown until coords are set up).
|
||||
# Please refer to the Wiki for descriptions of all these settings.
|
||||
# Note: The REWARDS use the same notation as the items in the CLASS SETUP
|
||||
# section. However, only -one- item from the list is picked (at random) when
|
||||
# the rewards are given.
|
||||
arenas:
|
||||
default:
|
||||
settings:
|
||||
world: ''
|
||||
enabled: true
|
||||
protect: true
|
||||
entry-fee: ''
|
||||
logging: true
|
||||
clear-wave-before-next: false
|
||||
detonate-creepers: false
|
||||
detonate-damage: false
|
||||
lightning: true
|
||||
auto-equip-armor: true
|
||||
force-restore: false
|
||||
soft-restore: false
|
||||
soft-restore-drops: false
|
||||
require-empty-inv-join: false
|
||||
require-empty-inv-spec: false
|
||||
hellhounds: false
|
||||
pvp-enabled: false
|
||||
monster-infight: false
|
||||
allow-teleporting: false
|
||||
spectate-on-death: true
|
||||
share-items-in-arena: true
|
||||
min-players: 0
|
||||
max-players: 0
|
||||
max-join-distance: 0
|
||||
repair-delay: 5
|
||||
first-wave-delay: 5
|
||||
wave-interval: 20
|
||||
special-modulo: 4
|
||||
max-idle-time: 0
|
||||
waves:
|
||||
recurrent:
|
||||
def1:
|
||||
type: default
|
||||
priority: 1
|
||||
frequency: 1
|
||||
monsters:
|
||||
zombies: 10
|
||||
skeletons: 10
|
||||
spiders: 10
|
||||
creepers: 10
|
||||
wolves: 10
|
||||
spec1:
|
||||
type: special
|
||||
priority: 2
|
||||
frequency: 4
|
||||
monsters:
|
||||
powered-creepers: 10
|
||||
zombie-pigmen: 10
|
||||
angry-wolves: 10
|
||||
humans: 10
|
||||
rewards:
|
||||
waves:
|
||||
every:
|
||||
'3': feather, bone, stick
|
||||
'5': dirt:4, gravel:4, stone:4
|
||||
'10': iron_ingot:10, gold_ingot:8
|
||||
after:
|
||||
'7': minecart, storage_minecart, powered_minecart
|
||||
'13': iron_sword, iron_pickaxe, iron_spade
|
||||
'16': diamond_sword
|
||||
@@ -0,0 +1,57 @@
|
||||
### General data
|
||||
### Statistics for overall information about the arena, such as
|
||||
### times played, durations, max players seen, total kills, etc.
|
||||
general-info:
|
||||
total-games-played: 0
|
||||
total-duration: 0:00:00
|
||||
longest-session-duration: 0:00:00
|
||||
most-players: 0
|
||||
highest-wave-reached: 0
|
||||
total-monsters-killed: 0
|
||||
|
||||
### Class specific data
|
||||
### How many times has each class been played, and how many kills, how
|
||||
### much damage, etc. does the class make/do/take.
|
||||
classes:
|
||||
overall-distribution:
|
||||
# Percentages can be calculated with <classname> / total-count * 100.
|
||||
total-count: 0
|
||||
|
||||
#classes:
|
||||
# overall-distribution:
|
||||
# total-count: 0
|
||||
# archer:
|
||||
# kills:
|
||||
# damage-done:
|
||||
# damage-taken:
|
||||
# accuracy:
|
||||
# knight:
|
||||
# kills:
|
||||
# damage-done:
|
||||
# damage-taken:
|
||||
# accuracy:
|
||||
# ...
|
||||
### Reward data
|
||||
### Totals for all rewards given, perhaps good for balancing?
|
||||
rewards:
|
||||
total-given:
|
||||
# This might be useless information, I don't know.
|
||||
# Might have to make it data values instead of Material names?
|
||||
money: 0
|
||||
|
||||
### Player data
|
||||
### Total games played, kills, damage, swings and hits (for accuracy), and how
|
||||
### many times the player has played as each class.
|
||||
players: {}
|
||||
# garbagemule:
|
||||
# games-played: 5
|
||||
# kills: 4
|
||||
# damage-done: 251
|
||||
# damage-taken: 102
|
||||
# swings: 1820
|
||||
# hits: 1214
|
||||
# classes-played:
|
||||
# archer: 2
|
||||
# ...
|
||||
# Agnate:
|
||||
# ...
|
||||
@@ -0,0 +1,57 @@
|
||||
### General data
|
||||
### Statistics for overall information about the arena, such as
|
||||
### times played, durations, max players seen, total kills, etc.
|
||||
general-info:
|
||||
total-games-played: 0
|
||||
total-duration: 0:00:00
|
||||
longest-session-duration: 0:00:00
|
||||
most-players: 0
|
||||
highest-wave-reached: 0
|
||||
total-monsters-killed: 0
|
||||
|
||||
### Class specific data
|
||||
### How many times has each class been played, and how many kills, how
|
||||
### much damage, etc. does the class make/do/take.
|
||||
classes:
|
||||
overall-distribution:
|
||||
# Percentages can be calculated with <classname> / total-count * 100.
|
||||
total-count: 0
|
||||
|
||||
#classes:
|
||||
# overall-distribution:
|
||||
# total-count: 0
|
||||
# archer:
|
||||
# kills:
|
||||
# damage-done:
|
||||
# damage-taken:
|
||||
# accuracy:
|
||||
# knight:
|
||||
# kills:
|
||||
# damage-done:
|
||||
# damage-taken:
|
||||
# accuracy:
|
||||
# ...
|
||||
### Reward data
|
||||
### Totals for all rewards given, perhaps good for balancing?
|
||||
rewards:
|
||||
total-given:
|
||||
# This might be useless information, I don't know.
|
||||
# Might have to make it data values instead of Material names?
|
||||
money: 0
|
||||
|
||||
### Player data
|
||||
### Total games played, kills, damage, swings and hits (for accuracy), and how
|
||||
### many times the player has played as each class.
|
||||
players: {}
|
||||
# garbagemule:
|
||||
# games-played: 5
|
||||
# kills: 4
|
||||
# damage-done: 251
|
||||
# damage-taken: 102
|
||||
# swings: 1820
|
||||
# hits: 1214
|
||||
# classes-played:
|
||||
# archer: 2
|
||||
# ...
|
||||
# Agnate:
|
||||
# ...
|
||||
@@ -1,107 +0,0 @@
|
||||
package com.garbagemule.MobArena;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class AbstractArena
|
||||
{
|
||||
/**
|
||||
* Start the arena session.
|
||||
* This method should warp all players to their respective warp points, start all
|
||||
* needed timers, clear/populate all sets and lists, and flag all booleans.
|
||||
*/
|
||||
public abstract void startArena();
|
||||
|
||||
/**
|
||||
* Force the arena to start.
|
||||
* If some players are ready, this method will force all non-ready players to leave,
|
||||
* and the arena will start with only the currently ready players.
|
||||
* @return true, if the arena was successfully started, false otherwise
|
||||
*/
|
||||
public abstract boolean forceStart();
|
||||
|
||||
/**
|
||||
* Stop the arena session.
|
||||
* Distribute rewards, clean up arena floor and reset everything to how it was before
|
||||
* the arena session was started, false otherwise
|
||||
*/
|
||||
public abstract void endArena();
|
||||
|
||||
/**
|
||||
* Force the arena to end.
|
||||
* Returns all players to their entry locations, distributes rewards, cleans the arena
|
||||
* floor, as well as all lists, sets and maps. Calling this method will return the
|
||||
* arena to the state it would be in right after MobArena has loaded.
|
||||
* @return true, if the session was successfully ended.
|
||||
*/
|
||||
public abstract boolean forceEnd();
|
||||
|
||||
/**
|
||||
* Player joins the arena/lobby.
|
||||
* @param p A player
|
||||
* @precondition Calling canJoin(p) for the given player must return true.
|
||||
*/
|
||||
public abstract void playerJoin(Player p);
|
||||
|
||||
/**
|
||||
* Player leaves the arena or lobby.
|
||||
* @param p A player
|
||||
* @precondition Calling canLeave(p) for the given player must return true.
|
||||
*/
|
||||
public abstract void playerLeave(Player p);
|
||||
|
||||
/**
|
||||
* Player joins the spectator area.
|
||||
* @param p A player
|
||||
* @precondition Calling canSpec(p) for the given player must return true.
|
||||
*/
|
||||
public abstract void playerSpec(Player p);
|
||||
|
||||
/**
|
||||
* Player dies in the arena.
|
||||
*/
|
||||
public abstract void playerDeath(Player p);
|
||||
|
||||
/**
|
||||
* Player signals that they are ready.
|
||||
*/
|
||||
public abstract void playerReady(Player p);
|
||||
|
||||
/**
|
||||
* Check if a player can join the arena.
|
||||
* @param p A player
|
||||
* @return true, if the player is eligible to join the arena.
|
||||
*/
|
||||
public abstract boolean canJoin(Player p);
|
||||
|
||||
/**
|
||||
* Check if a player can leave the arena.
|
||||
* @param p A player
|
||||
* @return true, if the player is eligible to leave the arena.
|
||||
*/
|
||||
public abstract boolean canLeave(Player p);
|
||||
|
||||
/**
|
||||
* Check if a player can spectate the arena.
|
||||
* @param p A player
|
||||
* @return true, if the player is eligible for spectating.
|
||||
*/
|
||||
public abstract boolean canSpec(Player p);
|
||||
|
||||
/**
|
||||
* Check if the arena is enabled.
|
||||
* @return true, if the arena is enabled.
|
||||
*/
|
||||
public abstract boolean isEnabled();
|
||||
|
||||
/**
|
||||
* Check if the arena is running.
|
||||
* @return true, if the arena is running.
|
||||
*/
|
||||
public abstract boolean isRunning();
|
||||
|
||||
/**
|
||||
* Check if the arena is set up and ready for use.
|
||||
* @return true, if the arena is ready for use.
|
||||
*/
|
||||
public abstract boolean isSetup();
|
||||
}
|
||||
@@ -5,7 +5,8 @@ import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
@@ -13,6 +14,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
|
||||
import net.minecraft.server.WorldServer;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -21,7 +26,11 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.ContainerBlock;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.CreatureType;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
@@ -34,6 +43,14 @@ import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
import com.garbagemule.MobArena.MAMessages.Msg;
|
||||
import com.garbagemule.MobArena.repairable.Repairable;
|
||||
import com.garbagemule.MobArena.repairable.RepairableComparator;
|
||||
import com.garbagemule.MobArena.repairable.RepairableContainer;
|
||||
import com.garbagemule.MobArena.util.InventoryItem;
|
||||
import com.garbagemule.MobArena.util.WaveUtils;
|
||||
import com.garbagemule.MobArena.waves.BossWave;
|
||||
import com.garbagemule.MobArena.waves.Wave;
|
||||
import com.garbagemule.MobArena.waves.Wave.WaveBranch;
|
||||
|
||||
public class Arena
|
||||
{
|
||||
@@ -42,29 +59,36 @@ public class Arena
|
||||
// Setup fields
|
||||
protected String name;
|
||||
protected World world;
|
||||
protected boolean enabled, protect, logging, running, setup, lobbySetup, autoEquip, forceRestore, softRestore, softRestoreDrops, emptyInvJoin, emptyInvSpec, pvp, monsterInfight, allowWarp;
|
||||
protected boolean enabled, protect, running, setup, lobbySetup, autoEquip, forceRestore, softRestore, softRestoreDrops, emptyInvJoin, emptyInvSpec, pvp, monsterInfight, allowWarp;
|
||||
|
||||
protected boolean edit, waveClear, detCreepers, detDamage, lightning, hellhounds, specOnDeath, shareInArena;
|
||||
protected Location p1, p2, l1, l2, arenaLoc, lobbyLoc, spectatorLoc;
|
||||
protected Map<String,Location> spawnpoints;
|
||||
protected Map<String,Location> spawnpoints, containers;
|
||||
protected String logging;
|
||||
|
||||
// Wave/reward/entryfee fields
|
||||
protected int spawnTaskId, waveDelay, waveInterval, specialModulo, spawnMonstersInt, maxIdleTime;
|
||||
protected int spawnTaskId, sheepTaskId, waveDelay, waveInterval, specialModulo, spawnMonstersInt, maxIdleTime;
|
||||
protected MASpawnThread spawnThread;
|
||||
protected Map<Integer,List<ItemStack>> everyWaveMap, afterWaveMap;
|
||||
protected Map<String,Integer> distDefault, distSpecial;
|
||||
protected Map<Player,String> classMap;
|
||||
protected Map<String,List<ItemStack>> classItems, classArmor;
|
||||
protected Map<Integer,Map<Player,List<ItemStack>>> classBonuses;
|
||||
protected Map<Player,List<ItemStack>> rewardMap;
|
||||
protected List<ItemStack> entryFee;
|
||||
|
||||
// Player sets
|
||||
protected Set<Player> arenaPlayers, lobbyPlayers, readyPlayers, specPlayers;
|
||||
|
||||
// Wave stuff
|
||||
protected TreeSet<Wave> singleWaves, singleWavesInstance;
|
||||
protected TreeSet<Wave> recurrentWaves;
|
||||
protected BossWave bossWave;
|
||||
|
||||
// Arena sets/maps
|
||||
protected Set<Player> arenaPlayers, lobbyPlayers, readyPlayers, specPlayers, hasPaid, rewardedPlayers, notifyPlayers, randoms;
|
||||
protected Set<LivingEntity> monsters;
|
||||
protected Set<Player> hasPaid, rewardedPlayers, notifyPlayers, randoms;
|
||||
protected Set<LivingEntity> monsters, explodingSheep, plaguedPigs, madCows;
|
||||
protected Set<Block> blocks;
|
||||
protected Set<Wolf> pets;
|
||||
protected Map<Player,Integer> petMap;
|
||||
protected List<int[]> repairList;
|
||||
protected LinkedList<Repairable> repairables, containables;
|
||||
|
||||
// Spawn overriding
|
||||
protected int spawnMonsters;
|
||||
@@ -78,14 +102,11 @@ public class Arena
|
||||
|
||||
// Logging
|
||||
protected ArenaLog log;
|
||||
protected List<String> classDistribution = new LinkedList<String>();
|
||||
protected Map<Player,Integer> waveMap = new HashMap<Player,Integer>();
|
||||
protected Map<Player,Integer> killMap = new HashMap<Player,Integer>();
|
||||
protected Timestamp startTime;
|
||||
protected Timestamp endTime;
|
||||
|
||||
protected MAListener eventListener;
|
||||
|
||||
protected PriorityBlockingQueue<Repairable> repairQueue;
|
||||
|
||||
/**
|
||||
* Primary constructor. Requires a name and a world.
|
||||
*/
|
||||
@@ -97,7 +118,6 @@ public class Arena
|
||||
this.name = name;
|
||||
this.world = world;
|
||||
plugin = (MobArena) Bukkit.getServer().getPluginManager().getPlugin("MobArena");
|
||||
log = new ArenaLog(plugin, this);
|
||||
|
||||
arenaPlayers = new HashSet<Player>();
|
||||
lobbyPlayers = new HashSet<Player>();
|
||||
@@ -107,13 +127,16 @@ public class Arena
|
||||
rewardedPlayers = new HashSet<Player>();
|
||||
hasPaid = new HashSet<Player>();
|
||||
monsters = new HashSet<LivingEntity>();
|
||||
explodingSheep = new HashSet<LivingEntity>();
|
||||
plaguedPigs = new HashSet<LivingEntity>();
|
||||
madCows = new HashSet<LivingEntity>();
|
||||
blocks = new HashSet<Block>();
|
||||
pets = new HashSet<Wolf>();
|
||||
petMap = new HashMap<Player,Integer>();
|
||||
classMap = new HashMap<Player,String>();
|
||||
randoms = new HashSet<Player>();
|
||||
rewardMap = new HashMap<Player,List<ItemStack>>();
|
||||
repairList = new LinkedList<int[]>();
|
||||
repairables = new LinkedList<Repairable>();
|
||||
containables = new LinkedList<Repairable>();
|
||||
|
||||
running = false;
|
||||
edit = false;
|
||||
@@ -123,6 +146,7 @@ public class Arena
|
||||
spawnMonsters = ((net.minecraft.server.World) ((CraftWorld) world).getHandle()).spawnMonsters;
|
||||
|
||||
eventListener = new MAListener(this, plugin);
|
||||
repairQueue = new PriorityBlockingQueue<Repairable>(100, new RepairableComparator());
|
||||
}
|
||||
|
||||
public boolean startArena()
|
||||
@@ -133,6 +157,9 @@ public class Arena
|
||||
if (!softRestore && forceRestore && !serializeRegion())
|
||||
return false;
|
||||
|
||||
// Store all chest contents.
|
||||
storeContainerContents();
|
||||
|
||||
// Populate arenaPlayers and clear the lobby.
|
||||
arenaPlayers.addAll(lobbyPlayers);
|
||||
lobbyPlayers.clear();
|
||||
@@ -149,28 +176,29 @@ public class Arena
|
||||
{
|
||||
p.teleport(arenaLoc);
|
||||
p.setHealth(20);
|
||||
rewardMap.put(p, new LinkedList<ItemStack>());
|
||||
waveMap.put(p, 0);
|
||||
killMap.put(p, 0);
|
||||
}
|
||||
|
||||
// Spawn pets.
|
||||
spawnPets();
|
||||
|
||||
// Start spawning monsters.
|
||||
startSpawning();
|
||||
|
||||
// Start logging
|
||||
if (logging)
|
||||
log.start();
|
||||
|
||||
// Set the boolean.
|
||||
running = true;
|
||||
|
||||
// Spawn pets (must happen after 'running = true;')
|
||||
spawnPets();
|
||||
|
||||
// Copy the singleWaves Set.
|
||||
singleWavesInstance = new TreeSet<Wave>(singleWaves);
|
||||
|
||||
// Start spawning monsters.
|
||||
startSpawning();
|
||||
startBouncingSheep();
|
||||
|
||||
// Start logging
|
||||
log = new ArenaLog(plugin, this);
|
||||
log.start();
|
||||
|
||||
// Announce and notify.
|
||||
MAUtils.tellAll(this, MAMessages.get(Msg.ARENA_START));
|
||||
MAUtils.tellAll(this, Msg.ARENA_START);
|
||||
for (MobArenaListener listener : plugin.getAM().listeners)
|
||||
listener.onArenaStart();
|
||||
listener.onArenaStart(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -184,13 +212,14 @@ public class Arena
|
||||
// Set the boolean.
|
||||
running = false;
|
||||
|
||||
// Stop logging.
|
||||
if (logging)
|
||||
{
|
||||
// Finish logging
|
||||
log.end();
|
||||
log.serialize();
|
||||
log.clear();
|
||||
if (logging != null)
|
||||
{
|
||||
log.saveSessionData();
|
||||
log.updateArenaTotals();
|
||||
}
|
||||
log.clearSessionData();
|
||||
|
||||
// Stop spawning.
|
||||
stopSpawning();
|
||||
@@ -200,25 +229,24 @@ public class Arena
|
||||
|
||||
// Restore region.
|
||||
if (softRestore)
|
||||
for (int[] buffer : repairList)
|
||||
world.getBlockAt(buffer[0], buffer[1], buffer[2]).setTypeIdAndData(buffer[3], (byte) buffer[4], false);
|
||||
restoreRegion();
|
||||
else if (forceRestore)
|
||||
deserializeRegion();
|
||||
|
||||
// Restore chests
|
||||
restoreContainerContents();
|
||||
|
||||
// Announce and clear sets.
|
||||
MAUtils.tellAll(this, MAMessages.get(Msg.ARENA_END), true);
|
||||
MAUtils.tellAll(this, Msg.ARENA_END, true);
|
||||
arenaPlayers.clear();
|
||||
notifyPlayers.clear();
|
||||
rewardedPlayers.clear();
|
||||
classMap.clear();
|
||||
rewardMap.clear();
|
||||
waveMap.clear();
|
||||
killMap.clear();
|
||||
spawnThread = null;
|
||||
|
||||
// Notify listeners.
|
||||
for (MobArenaListener listener : plugin.getAM().listeners)
|
||||
listener.onArenaEnd();
|
||||
listener.onArenaEnd(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -243,49 +271,38 @@ public class Arena
|
||||
|
||||
public void forceEnd()
|
||||
{
|
||||
if (!running)
|
||||
return;
|
||||
Bukkit.getServer().getScheduler().cancelTask(spawnTaskId);
|
||||
Bukkit.getServer().getScheduler().cancelTask(sheepTaskId);
|
||||
|
||||
for (Player p : getAllPlayers())
|
||||
{
|
||||
plugin.getAM().arenaMap.remove(p);
|
||||
playerLeave(p);
|
||||
}
|
||||
|
||||
for (Entity e : monsters)
|
||||
e.remove();
|
||||
|
||||
if (bossWave != null)
|
||||
bossWave.clear();
|
||||
|
||||
arenaPlayers.clear();
|
||||
lobbyPlayers.clear();
|
||||
readyPlayers.clear();
|
||||
|
||||
rewardMap.clear();
|
||||
waveMap.clear();
|
||||
killMap.clear();
|
||||
monsters.clear();
|
||||
cleanup();
|
||||
|
||||
spawnTaskId = -1;
|
||||
sheepTaskId = -1;
|
||||
}
|
||||
|
||||
public void playerJoin(Player p, Location loc)
|
||||
{
|
||||
// Store location and health.
|
||||
if (!locations.containsKey(p))
|
||||
locations.put(p,loc);
|
||||
if (!healthMap.containsKey(p))
|
||||
healthMap.put(p,p.getHealth());
|
||||
p.setHealth(20);
|
||||
|
||||
// Update chunk.
|
||||
updateChunk(lobbyLoc);
|
||||
|
||||
storePlayerData(p, loc);
|
||||
MAUtils.sitPets(p);
|
||||
lobbyPlayers.add(p);
|
||||
p.teleport(lobbyLoc);
|
||||
p.setHealth(20);
|
||||
movePlayerToLobby(p);
|
||||
|
||||
// Notify listeners.
|
||||
for (MobArenaListener listener : plugin.getAM().listeners)
|
||||
listener.onPlayerJoin(p);
|
||||
listener.onPlayerJoin(this, p);
|
||||
}
|
||||
|
||||
public void playerReady(Player p)
|
||||
@@ -294,7 +311,7 @@ public class Arena
|
||||
|
||||
if (minPlayers > 0 && lobbyPlayers.size() < minPlayers)
|
||||
{
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_NOT_ENOUGH_PLAYERS, "" + minPlayers));
|
||||
MAUtils.tellPlayer(p, Msg.LOBBY_NOT_ENOUGH_PLAYERS, "" + minPlayers);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -303,84 +320,56 @@ public class Arena
|
||||
|
||||
public void playerLeave(Player p)
|
||||
{
|
||||
// Clear class inventory, restore old inventory and fork over rewards.
|
||||
restoreInvAndGiveRewards(p, (arenaPlayers.contains(p) || lobbyPlayers.contains(p)));
|
||||
finishArenaPlayer(p);
|
||||
movePlayerToEntry(p);
|
||||
discardPlayer(p);
|
||||
|
||||
// Grab the player's entry location, and warp them there.
|
||||
Location entry = locations.get(p);
|
||||
if (entry != null)
|
||||
{
|
||||
updateChunk(entry);
|
||||
p.teleport(entry);
|
||||
}
|
||||
locations.remove(p);
|
||||
if (healthMap.containsKey(p)) p.setHealth(healthMap.remove(p));
|
||||
// Notify listeners.
|
||||
for (MobArenaListener listener : plugin.getAM().listeners)
|
||||
listener.onPlayerLeave(this, p);
|
||||
|
||||
// Remove from the arenaMap and all the sets.
|
||||
plugin.getAM().arenaMap.remove(p);
|
||||
removePlayer(p);
|
||||
|
||||
// End the arena if conditions are met.
|
||||
// End arena if possible.
|
||||
endArena();
|
||||
}
|
||||
|
||||
public void playerDeath(Player p)
|
||||
{
|
||||
// If spectate-on-death: false, pass on to playerLeave.
|
||||
if (!specOnDeath)
|
||||
finishArenaPlayer(p);
|
||||
|
||||
if (specOnDeath)
|
||||
{
|
||||
playerLeave(p);
|
||||
return;
|
||||
clearPlayer(p);
|
||||
movePlayerToSpec(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
movePlayerToEntry(p);
|
||||
discardPlayer(p);
|
||||
}
|
||||
|
||||
// Clear class inventory, restore old inventory and fork over rewards.
|
||||
restoreInvAndGiveRewards(p, true);
|
||||
|
||||
// Remove player from sets, warp to spectator area, then add to specPlayers.
|
||||
p.teleport(spectatorLoc);
|
||||
if (healthMap.containsKey(p)) p.setHealth(healthMap.remove(p));
|
||||
removePlayer(p);
|
||||
specPlayers.add(p);
|
||||
|
||||
// Update the monster targets.
|
||||
if (running && spawnThread != null)
|
||||
spawnThread.updateTargets();
|
||||
|
||||
// Announce and notify
|
||||
MAUtils.tellAll(this, MAMessages.get(Msg.PLAYER_DIED, p.getName()));
|
||||
for (MobArenaListener listener : plugin.getAM().listeners)
|
||||
listener.onPlayerDeath(p);
|
||||
|
||||
// End the arena if conditions are met.
|
||||
MAUtils.tellAll(this, Msg.PLAYER_DIED, p.getName());
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
endArena();
|
||||
}
|
||||
});
|
||||
|
||||
// Notify listeners.
|
||||
for (MobArenaListener listener : plugin.getAM().listeners)
|
||||
listener.onPlayerDeath(this, p);
|
||||
}
|
||||
|
||||
public void playerSpec(Player p, Location loc)
|
||||
{
|
||||
if (!locations.containsKey(p))
|
||||
locations.put(p,loc);
|
||||
if (!healthMap.containsKey(p))
|
||||
healthMap.put(p,p.getHealth());
|
||||
|
||||
storePlayerData(p, loc);
|
||||
MAUtils.sitPets(p);
|
||||
specPlayers.add(p);
|
||||
p.teleport(spectatorLoc);
|
||||
}
|
||||
|
||||
public void removePlayer(Player p)
|
||||
{
|
||||
// Heal and put out fire.
|
||||
p.setFireTicks(0);
|
||||
p.setHealth(20);
|
||||
|
||||
// Remove pets.
|
||||
removePets(p);
|
||||
|
||||
// readyPlayers before lobbyPlayers because of startArena sanity-checks
|
||||
readyPlayers.remove(p);
|
||||
specPlayers.remove(p);
|
||||
arenaPlayers.remove(p);
|
||||
lobbyPlayers.remove(p);
|
||||
movePlayerToSpec(p);
|
||||
}
|
||||
|
||||
private void spawnPets()
|
||||
@@ -420,9 +409,11 @@ public class Arena
|
||||
// Stop the spawn thread.
|
||||
if (spawnThread != null)
|
||||
{
|
||||
Bukkit.getServer().getScheduler().cancelTask(spawnThread.taskId);
|
||||
Bukkit.getServer().getScheduler().cancelTask(spawnThread.getTaskId());
|
||||
Bukkit.getServer().getScheduler().cancelTask(spawnTaskId);
|
||||
Bukkit.getServer().getScheduler().cancelTask(sheepTaskId);
|
||||
spawnTaskId = -1;
|
||||
sheepTaskId = -1;
|
||||
spawnThread = null;
|
||||
}
|
||||
|
||||
@@ -430,6 +421,40 @@ public class Arena
|
||||
MAUtils.setSpawnFlags(plugin, world, spawnMonsters, allowMonsters, allowAnimals);
|
||||
}
|
||||
|
||||
private void startBouncingSheep()
|
||||
{
|
||||
sheepTaskId = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin,
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
if (explodingSheep.isEmpty()) return;
|
||||
|
||||
for (LivingEntity e : new LinkedList<LivingEntity>(explodingSheep))
|
||||
{
|
||||
Creature c = (Creature) e;
|
||||
if (c.getTarget() != null && e.getLocation().distanceSquared(c.getTarget().getLocation()) < 8)
|
||||
{
|
||||
CraftEntity ce = (CraftEntity) e;
|
||||
CraftWorld cw = (CraftWorld) e.getWorld();
|
||||
WorldServer ws = cw.getHandle();
|
||||
ws.createExplosion(ce.getHandle(), e.getLocation().getX(), e.getLocation().getY() + 1, e.getLocation().getZ(), 2f, false);
|
||||
e.remove();
|
||||
}
|
||||
|
||||
if (e.isDead())
|
||||
{
|
||||
explodingSheep.remove(e);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Math.abs(e.getVelocity().getY()) < 1)
|
||||
e.setVelocity(e.getVelocity().setY(0.5));
|
||||
}
|
||||
}
|
||||
}, waveDelay, 20);
|
||||
}
|
||||
|
||||
private void updateChunk(Location loc)
|
||||
{
|
||||
if (!arenaPlayers.isEmpty() || !world.getName().equals(loc.getWorld().getName()))
|
||||
@@ -444,19 +469,17 @@ public class Arena
|
||||
|
||||
public void playerKill(Player p)
|
||||
{
|
||||
if (p == null || killMap.get(p) == null)
|
||||
if (p == null || log.players.get(p) == null)
|
||||
return;
|
||||
|
||||
killMap.put(p, killMap.get(p) + 1);
|
||||
log.players.get(p).kills++;
|
||||
}
|
||||
|
||||
public void restoreInvAndGiveRewards(final Player p, final boolean clear)
|
||||
public void restoreInvAndGiveRewards(final Player p)
|
||||
{
|
||||
final List<ItemStack> rewards = rewardMap.get(p);
|
||||
final List<ItemStack> rewards = log != null && log.players.get(p) != null ? log.players.get(p).rewards : new LinkedList<ItemStack>();
|
||||
final boolean hadRewards = rewardedPlayers.contains(p);
|
||||
|
||||
if (clear) MAUtils.clearInventory(p);
|
||||
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
|
||||
new Runnable()
|
||||
{
|
||||
@@ -475,6 +498,147 @@ public class Arena
|
||||
});
|
||||
}
|
||||
|
||||
public void restoreInvAndGiveRewardz(final Player p, List<ItemStack> rewards, boolean hadRewards)
|
||||
{
|
||||
if (!p.isOnline())
|
||||
return;
|
||||
|
||||
if (!emptyInvJoin)
|
||||
MAUtils.restoreInventory(p);
|
||||
|
||||
if (hadRewards)
|
||||
return;
|
||||
|
||||
MAUtils.giveRewards(p, rewards, plugin);
|
||||
if (running)
|
||||
rewardedPlayers.add(p);}
|
||||
|
||||
public void storePlayerData(Player p, Location loc)
|
||||
{
|
||||
plugin.getAM().arenaMap.put(p, this);
|
||||
|
||||
if (!locations.containsKey(p))
|
||||
locations.put(p, loc);
|
||||
|
||||
if (!healthMap.containsKey(p))
|
||||
healthMap.put(p, p.getHealth());
|
||||
}
|
||||
|
||||
public void storeContainerContents()
|
||||
{
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
for (Location loc : containers.values())
|
||||
{
|
||||
BlockState state = world.getBlockAt(loc).getState();
|
||||
if (state instanceof ContainerBlock)
|
||||
containables.add(new RepairableContainer(state, false));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void restoreContainerContents()
|
||||
{
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
for (Repairable r : containables)
|
||||
r.repair();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void movePlayerToLobby(Player p)
|
||||
{
|
||||
updateChunk(lobbyLoc);
|
||||
lobbyPlayers.add(p);
|
||||
p.teleport(lobbyLoc);
|
||||
}
|
||||
|
||||
public void movePlayerToSpec(Player p)
|
||||
{
|
||||
updateChunk(spectatorLoc);
|
||||
specPlayers.add(p);
|
||||
p.teleport(spectatorLoc);
|
||||
}
|
||||
|
||||
public void movePlayerToEntry(Player p)
|
||||
{
|
||||
Location entry = locations.get(p);
|
||||
if (entry == null) return;
|
||||
|
||||
updateChunk(entry);
|
||||
p.teleport(entry);
|
||||
}
|
||||
|
||||
private void clearPlayer(Player p)
|
||||
{
|
||||
if (healthMap.containsKey(p))
|
||||
p.setHealth(healthMap.remove(p));
|
||||
|
||||
// Put out fire.
|
||||
p.setFireTicks(0);
|
||||
|
||||
// Remove pets.
|
||||
removePets(p);
|
||||
|
||||
// readyPlayers before lobbyPlayers because of startArena sanity-checks
|
||||
readyPlayers.remove(p);
|
||||
specPlayers.remove(p);
|
||||
arenaPlayers.remove(p);
|
||||
lobbyPlayers.remove(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Completely remove a player from the arena collections.
|
||||
* @param p A player
|
||||
*/
|
||||
private void discardPlayer(Player p)
|
||||
{
|
||||
locations.remove(p);
|
||||
plugin.getAM().arenaMap.remove(p);
|
||||
clearPlayer(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the player back his inventory and record his last wave.
|
||||
* Called when a player dies or leaves prematurely.
|
||||
* @param p
|
||||
*/
|
||||
private void finishArenaPlayer(Player p)
|
||||
{
|
||||
if (!arenaPlayers.contains(p) && !lobbyPlayers.contains(p))
|
||||
return;
|
||||
|
||||
MAUtils.clearInventory(p);
|
||||
restoreInvAndGiveRewards(p);
|
||||
|
||||
if (log != null && spawnThread != null)
|
||||
log.players.get(p).lastWave = spawnThread.getWave() - 1;
|
||||
}
|
||||
|
||||
public void repairBlocks()
|
||||
{
|
||||
//long start = System.nanoTime();
|
||||
//System.out.println(start + " - Attempting to repair things...");
|
||||
while (!repairQueue.isEmpty())
|
||||
{
|
||||
repairQueue.poll().repair();
|
||||
}
|
||||
//System.out.println(start + " - Repair finished!");
|
||||
}
|
||||
|
||||
public void queueRepairable(Repairable r)
|
||||
{
|
||||
repairQueue.add(r);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*////////////////////////////////////////////////////////////////////
|
||||
@@ -515,7 +679,7 @@ public class Arena
|
||||
{
|
||||
if (classes.isEmpty())
|
||||
{
|
||||
System.out.println("[MobArena] ERROR! Player '" + p.getName() + "' has no class permissions!");
|
||||
MobArena.info("Player '" + p.getName() + "' has no class permissions!");
|
||||
playerLeave(p);
|
||||
return;
|
||||
}
|
||||
@@ -523,7 +687,7 @@ public class Arena
|
||||
}
|
||||
|
||||
assignClass(p, className);
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_CLASS_PICKED, className));
|
||||
MAUtils.tellPlayer(p, Msg.LOBBY_CLASS_PICKED, className);
|
||||
}
|
||||
|
||||
private void cleanup()
|
||||
@@ -533,14 +697,25 @@ public class Arena
|
||||
removePets();
|
||||
removeEntities();
|
||||
monsters.clear();
|
||||
explodingSheep.clear();
|
||||
plaguedPigs.clear();
|
||||
madCows.clear();
|
||||
blocks.clear();
|
||||
pets.clear();
|
||||
}
|
||||
|
||||
private void removeMonsters()
|
||||
{
|
||||
if (bossWave != null)
|
||||
bossWave.clear();
|
||||
for (LivingEntity e : monsters)
|
||||
e.remove();
|
||||
for (LivingEntity e : explodingSheep)
|
||||
e.remove();
|
||||
for (LivingEntity e : plaguedPigs)
|
||||
e.remove();
|
||||
for (LivingEntity e : madCows)
|
||||
e.remove();
|
||||
}
|
||||
|
||||
private void removeBlocks()
|
||||
@@ -573,6 +748,7 @@ public class Arena
|
||||
|
||||
private void removeEntities()
|
||||
{
|
||||
if (p1 == null || p2 == null) return;
|
||||
Chunk c1 = world.getChunkAt(p1);
|
||||
Chunk c2 = world.getChunkAt(p2);
|
||||
|
||||
@@ -600,7 +776,7 @@ public class Arena
|
||||
|
||||
enabled = config.getBoolean(arenaPath + "enabled", true);
|
||||
protect = config.getBoolean(arenaPath + "protect", true);
|
||||
logging = config.getBoolean(arenaPath + "logging", false);
|
||||
logging = config.getString(arenaPath + "logging", null);
|
||||
autoEquip = config.getBoolean(arenaPath + "auto-equip-armor", true);
|
||||
waveClear = config.getBoolean(arenaPath + "clear-wave-before-next", false);
|
||||
detCreepers = config.getBoolean(arenaPath + "detonate-creepers", false);
|
||||
@@ -626,8 +802,6 @@ public class Arena
|
||||
specialModulo = config.getInt(arenaPath + "special-modulo", 4);
|
||||
maxIdleTime = config.getInt(arenaPath + "max-idle-time", 0) * 20;
|
||||
|
||||
distDefault = MAUtils.getArenaDistributions(config, configName, "default");
|
||||
distSpecial = MAUtils.getArenaDistributions(config, configName, "special");
|
||||
everyWaveMap = MAUtils.getArenaRewardMap(config, configName, "every");
|
||||
afterWaveMap = MAUtils.getArenaRewardMap(config, configName, "after");
|
||||
entryFee = MAUtils.getEntryFee(config, configName);
|
||||
@@ -640,6 +814,11 @@ public class Arena
|
||||
lobbyLoc = MAUtils.getArenaCoord(config, world, configName, "lobby");
|
||||
spectatorLoc = MAUtils.getArenaCoord(config, world, configName, "spectator");
|
||||
spawnpoints = MAUtils.getArenaSpawnpoints(config, world, configName);
|
||||
containers = MAUtils.getArenaContainers(config, world, configName);
|
||||
|
||||
// NEW WAVES
|
||||
singleWaves = WaveUtils.getWaves(this, config, WaveBranch.SINGLE);
|
||||
recurrentWaves = WaveUtils.getWaves(this, config, WaveBranch.RECURRENT);
|
||||
|
||||
classes = plugin.getAM().classes;
|
||||
classItems = plugin.getAM().classItems;
|
||||
@@ -650,6 +829,14 @@ public class Arena
|
||||
lobbySetup = MAUtils.verifyLobby(this);
|
||||
}
|
||||
|
||||
public void restoreRegion()
|
||||
{
|
||||
Collections.sort(repairables, new RepairableComparator());
|
||||
|
||||
for (Repairable r : repairables)
|
||||
r.repair();
|
||||
}
|
||||
|
||||
public void serializeConfig()
|
||||
{
|
||||
String coords = "arenas." + configName() + ".coords.";
|
||||
@@ -718,7 +905,7 @@ public class Arena
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("[MobArena] ERROR! Could not create region file. The arena will not be started!");
|
||||
MobArena.warning("Could not create region file. The arena will not be started!");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
@@ -742,7 +929,7 @@ public class Arena
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("[MobArena] ERROR! Could not find region file. The arena cannot be restored!");
|
||||
MobArena.warning("Could not find region file. The arena cannot be restored!");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
@@ -826,6 +1013,75 @@ public class Arena
|
||||
return name;
|
||||
}
|
||||
|
||||
public MobArena getPlugin()
|
||||
{
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public World getWorld()
|
||||
{
|
||||
return world;
|
||||
}
|
||||
|
||||
public void setBossWave(BossWave bossWave)
|
||||
{
|
||||
this.bossWave = bossWave;
|
||||
}
|
||||
|
||||
public List<String> getClasses()
|
||||
{
|
||||
return classes;
|
||||
}
|
||||
|
||||
public List<Location> getAllSpawnpoints()
|
||||
{
|
||||
return new ArrayList<Location>(spawnpoints.values());
|
||||
}
|
||||
|
||||
public List<Location> getSpawnpoints()
|
||||
{
|
||||
List<Location> result = new ArrayList<Location>(spawnpoints.size());
|
||||
|
||||
for (Map.Entry<String,Location> entry : spawnpoints.entrySet())
|
||||
if (!entry.getKey().matches("^*boss*$"))
|
||||
result.add(entry.getValue());
|
||||
|
||||
return !result.isEmpty() ? result : new ArrayList<Location>(spawnpoints.values());
|
||||
}
|
||||
|
||||
public Location getBossSpawnpoint()
|
||||
{
|
||||
Location result = null;
|
||||
|
||||
for (Map.Entry<String,Location> entry : spawnpoints.entrySet())
|
||||
{
|
||||
if (!entry.getKey().matches("^*boss*$")) continue;
|
||||
|
||||
result = entry.getValue();
|
||||
break;
|
||||
}
|
||||
|
||||
if (result != null)
|
||||
return result;
|
||||
|
||||
return WaveUtils.getValidSpawnpoints(this, arenaPlayers).iterator().next();
|
||||
}
|
||||
|
||||
public int getPlayerCount()
|
||||
{
|
||||
return spawnThread.getPlayerCount();
|
||||
}
|
||||
|
||||
public void addMonster(LivingEntity e)
|
||||
{
|
||||
monsters.add(e);
|
||||
}
|
||||
|
||||
public void addExplodingSheep(LivingEntity e)
|
||||
{
|
||||
explodingSheep.add(e);
|
||||
}
|
||||
|
||||
public List<Player> getAllPlayers()
|
||||
{
|
||||
List<Player> result = new LinkedList<Player>();
|
||||
@@ -850,41 +1106,55 @@ public class Arena
|
||||
return result;
|
||||
}
|
||||
|
||||
public Set<LivingEntity> getMonsters()
|
||||
{
|
||||
Set<LivingEntity> tmp = new HashSet<LivingEntity>(monsters);
|
||||
tmp.addAll(explodingSheep);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public Set<Wolf> getPets()
|
||||
{
|
||||
return pets;
|
||||
}
|
||||
|
||||
public void resetIdleTimer()
|
||||
{
|
||||
if (maxIdleTime <= 0 || !running)
|
||||
return;
|
||||
|
||||
// Reset the previousSize, cancel the previous timer, and start the new timer.
|
||||
spawnThread.previousSize = monsters.size();
|
||||
Bukkit.getServer().getScheduler().cancelTask(spawnThread.taskId);
|
||||
spawnThread.taskId = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
|
||||
spawnThread.setPreviousSize(getMonsters().size());
|
||||
Bukkit.getServer().getScheduler().cancelTask(spawnThread.getTaskId());
|
||||
int id = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
// Make sure to remove any dead/removed entities first.
|
||||
List<Entity> tmp = new LinkedList<Entity>(monsters);
|
||||
for (Entity e : tmp)
|
||||
List<Entity> ms = new LinkedList<Entity>(monsters);
|
||||
for (Entity e : ms)
|
||||
if (e.isDead())
|
||||
monsters.remove(e);
|
||||
|
||||
// Compare the current size with the previous size.
|
||||
if (monsters.size() < spawnThread.previousSize || spawnThread.previousSize == 0)
|
||||
if (monsters.size() < spawnThread.getPreviousSize() || spawnThread.getPreviousSize() == 0 || bossWave != null)
|
||||
{
|
||||
resetIdleTimer();
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear all player inventories, and "kill" all players.
|
||||
for (Player p : arenaPlayers)
|
||||
List<Player> ps = new LinkedList<Player>(arenaPlayers);
|
||||
for (Player p : ps)
|
||||
{
|
||||
MAUtils.clearInventory(p);
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.FORCE_END_IDLE));
|
||||
MAUtils.tellPlayer(p, Msg.FORCE_END_IDLE);
|
||||
playerDeath(p);
|
||||
}
|
||||
}
|
||||
}, maxIdleTime);
|
||||
spawnThread.setTaskId(id);
|
||||
}
|
||||
|
||||
public void addTrunkAndLeaves(Block b)
|
||||
@@ -941,52 +1211,73 @@ public class Arena
|
||||
return true;
|
||||
|
||||
PlayerInventory inv = p.getInventory();
|
||||
for (ItemStack stack : entryFee)
|
||||
{
|
||||
// Economy money
|
||||
if (stack.getTypeId() == MobArena.ECONOMY_MONEY_ID)
|
||||
{
|
||||
if (plugin.Methods.hasMethod() && !plugin.Method.getAccount(p.getName()).subtract(stack.getAmount()))
|
||||
return false;
|
||||
}
|
||||
InventoryItem[] items = InventoryItem.parseItemStacks(inv.getContents());
|
||||
InventoryItem[] fee = InventoryItem.parseItemStacks(entryFee);
|
||||
|
||||
// Normal stack
|
||||
else
|
||||
{
|
||||
int id = stack.getTypeId();
|
||||
int amount = stack.getAmount();
|
||||
// Take some economy money
|
||||
for (InventoryItem item : InventoryItem.extractAllFromArray(MobArena.ECONOMY_MONEY_ID, fee))
|
||||
if (plugin.Methods.hasMethod())
|
||||
plugin.Method.getAccount(p.getName()).subtract(item.getAmount());
|
||||
|
||||
while (amount > 0)
|
||||
{
|
||||
int pos = inv.first(id);
|
||||
if (pos == -1) return false;
|
||||
// Take any other items
|
||||
for (InventoryItem item : fee)
|
||||
InventoryItem.removeItemFromArray(item, items);
|
||||
|
||||
ItemStack is = inv.getItem(pos);
|
||||
if (is.getAmount() > amount)
|
||||
{
|
||||
is.setAmount(is.getAmount() - amount);
|
||||
amount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
amount -= is.getAmount();
|
||||
inv.setItem(pos, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Turn everything back into ItemStacks
|
||||
for (int i = 0; i < items.length; i++)
|
||||
inv.setItem(i, items[i].toItemStack());
|
||||
|
||||
hasPaid.add(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void refund(Player p)
|
||||
public boolean canJoin(Player p)
|
||||
{
|
||||
if (!hasPaid.contains(p))
|
||||
return;
|
||||
if (!enabled)
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_ARENA_NOT_ENABLED);
|
||||
else if (!setup || recurrentWaves.isEmpty())
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_ARENA_NOT_SETUP);
|
||||
else if (edit)
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_ARENA_EDIT_MODE);
|
||||
else if (running && (notifyPlayers.contains(p) || notifyPlayers.add(p)))
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_ARENA_IS_RUNNING);
|
||||
else if (arenaPlayers.contains(p) || lobbyPlayers.contains(p))
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_ALREADY_PLAYING);
|
||||
else if (!plugin.has(p, "mobarena.arenas." + configName()))
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_ARENA_PERMISSION);
|
||||
else if (maxPlayers > 0 && lobbyPlayers.size() >= maxPlayers)
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_PLAYER_LIMIT_REACHED);
|
||||
else if (joinDistance > 0 && !inRegionRadius(p.getLocation(), joinDistance))
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_TOO_FAR);
|
||||
else if (emptyInvJoin && !MAUtils.hasEmptyInventory(p))
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_EMPTY_INV);
|
||||
/*else if (!canAfford(p) || !takeFee(p))
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_FEE_REQUIRED, MAUtils.listToString(entryFee, plugin));
|
||||
else if (emptyInvJoin && !MAUtils.hasEmptyInventory(p))
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_EMPTY_INV);
|
||||
else if (!emptyInvJoin && !MAUtils.storeInventory(p))
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_STORE_INV_FAIL);*/
|
||||
else return true;
|
||||
|
||||
MAUtils.giveItems(p, entryFee, false, plugin);
|
||||
hasPaid.remove(p);
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canSpec(Player p)
|
||||
{
|
||||
if (!enabled)
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_ARENA_NOT_ENABLED);
|
||||
else if (!setup)
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_ARENA_NOT_SETUP);
|
||||
else if (edit)
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_ARENA_EDIT_MODE);
|
||||
else if (arenaPlayers.contains(p) || lobbyPlayers.contains(p))
|
||||
MAUtils.tellPlayer(p, Msg.SPEC_ALREADY_PLAYING);
|
||||
else if (emptyInvSpec && !MAUtils.hasEmptyInventory(p))
|
||||
MAUtils.tellPlayer(p, Msg.SPEC_EMPTY_INV);
|
||||
else if (joinDistance > 0 && !inRegionRadius(p.getLocation(), joinDistance))
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_TOO_FAR);
|
||||
else return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.garbagemule.MobArena;
|
||||
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
@@ -21,6 +22,7 @@ public interface ArenaListener
|
||||
{
|
||||
public void onBlockBreak(BlockBreakEvent event);
|
||||
public void onBlockPlace(BlockPlaceEvent event);
|
||||
public void onBlockIgnite(BlockIgniteEvent event);
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event);
|
||||
public void onEntityExplode(EntityExplodeEvent event);
|
||||
public void onEntityCombust(EntityCombustEvent event);
|
||||
@@ -35,23 +37,4 @@ public interface ArenaListener
|
||||
public void onPlayerKick(PlayerKickEvent event);
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event);
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event);
|
||||
|
||||
/*
|
||||
public abstract void onBlockBreak(BlockBreakEvent event);
|
||||
public abstract void onBlockPlace(BlockPlaceEvent event);
|
||||
public abstract void onCreatureSpawn(CreatureSpawnEvent event);
|
||||
public abstract void onEntityExplode(EntityExplodeEvent event);
|
||||
public abstract void onEntityCombust(EntityCombustEvent event);
|
||||
public abstract void onEntityTarget(EntityTargetEvent event);
|
||||
public abstract void onEntityRegainHealth(EntityRegainHealthEvent event);
|
||||
public abstract void onEntityDeath(EntityDeathEvent event);
|
||||
public abstract void onEntityDamage(EntityDamageEvent event);
|
||||
public abstract void onPlayerDropItem(PlayerDropItemEvent event);
|
||||
public abstract void onPlayerBucketEmpty(PlayerBucketEmptyEvent event);
|
||||
public abstract void onPlayerInteract(PlayerInteractEvent event);
|
||||
public abstract void onPlayerQuit(PlayerQuitEvent event);
|
||||
public abstract void onPlayerKick(PlayerKickEvent event);
|
||||
public abstract void onPlayerTeleport(PlayerTeleportEvent event);
|
||||
public abstract void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event);
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -1,134 +1,141 @@
|
||||
package com.garbagemule.MobArena;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.garbagemule.MobArena.util.data.PlainText;
|
||||
import com.garbagemule.MobArena.util.data.Totals;
|
||||
import com.garbagemule.MobArena.util.data.XML;
|
||||
import com.garbagemule.MobArena.util.data.YAML;
|
||||
|
||||
public class ArenaLog
|
||||
{
|
||||
protected MobArena plugin;
|
||||
protected Arena arena;
|
||||
protected List<String> log, classDistribution;
|
||||
protected Timestamp startTime, endTime;
|
||||
public MobArena plugin;
|
||||
public Arena arena;
|
||||
public Timestamp startTime, endTime;
|
||||
public int lastWave;
|
||||
|
||||
public Map<Player,ArenaPlayer> players;
|
||||
public Map<String,Integer> distribution;
|
||||
|
||||
/**
|
||||
* Create a new ArenaLog.
|
||||
* @param plugin MobArena instance
|
||||
* @param arena The arena
|
||||
*/
|
||||
public ArenaLog(MobArena plugin, Arena arena)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.arena = arena;
|
||||
log = new LinkedList<String>();
|
||||
classDistribution = new LinkedList<String>();
|
||||
this.players = new HashMap<Player,ArenaPlayer>(arena.arenaPlayers.size());
|
||||
this.distribution = new HashMap<String,Integer>(arena.classes.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Start logging by creating ArenaPlayer objects and recording
|
||||
* the class distributions and the start time.
|
||||
*/
|
||||
public void start()
|
||||
{
|
||||
// Populate the data maps
|
||||
populatePlayerMap();
|
||||
populateDistributionMap();
|
||||
|
||||
// Grab the current timestamp
|
||||
startTime = new Timestamp((new Date()).getTime());
|
||||
|
||||
// Class distribution
|
||||
int length = 0;
|
||||
for (String c : plugin.getAM().classes)
|
||||
if (c.length() > length)
|
||||
length = c.length();
|
||||
|
||||
List<String> classList = new LinkedList<String>(arena.classMap.values());
|
||||
for (String c : plugin.getAM().classes)
|
||||
{
|
||||
int count = 0;
|
||||
int id = classList.indexOf(c);
|
||||
while (id != -1)
|
||||
{
|
||||
classList.remove(id);
|
||||
count++;
|
||||
id = classList.indexOf(c);
|
||||
}
|
||||
//int percentage = (int) (((double) count) / ((double) arena.livePlayers.size())) * 100;
|
||||
int percentage = (int) (((double) count) / ((double) arena.arenaPlayers.size())) * 100;
|
||||
classDistribution.add(MAUtils.padRight(c + ": ", length + 2) + MAUtils.padLeft("" + count, 2) + " (" + percentage + "%)");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* End logging by recording the last wave and the end time.
|
||||
*/
|
||||
public void end()
|
||||
{
|
||||
lastWave = arena.spawnThread.getWave() - 1;
|
||||
endTime = new Timestamp((new Date()).getTime());
|
||||
}
|
||||
|
||||
// General stuff
|
||||
log.add("--------------------------------------------------- ENTRY ---");
|
||||
log.add("Start: " + startTime);
|
||||
log.add("End: " + endTime);
|
||||
log.add("Duration: " + MAUtils.getDuration(endTime.getTime() - startTime.getTime()));
|
||||
log.add("Last wave: " + (arena.spawnThread.wave - 1));
|
||||
log.add(" ");
|
||||
|
||||
// Class distribution
|
||||
log.add("Class Distribution: " + plugin.getAM().classes.size() + " classes");
|
||||
for (String c : classDistribution)
|
||||
log.add("- " + c);
|
||||
classDistribution.clear();
|
||||
log.add(" ");
|
||||
|
||||
// Player data
|
||||
int NAME = 12; int CLASS = 0; int WAVE = 4; int KILLS = 5;
|
||||
for (String c : plugin.getAM().classes)
|
||||
if (c.length() > CLASS)
|
||||
CLASS = c.length();
|
||||
|
||||
log.add("Player Data: " + arena.classMap.keySet().size() + " players");
|
||||
log.add("- " + MAUtils.padRight("Name", NAME + 2, ' ') + MAUtils.padRight("Class", CLASS + 2, ' ') + MAUtils.padRight("Wave", WAVE + 2, ' ') + MAUtils.padRight("Kills", KILLS + 2, ' ') + "Rewards");
|
||||
for (Map.Entry<Player,String> entry : arena.classMap.entrySet())
|
||||
/**
|
||||
* Map players to ArenaPlayer objects.
|
||||
*/
|
||||
private void populatePlayerMap()
|
||||
{
|
||||
Player p = entry.getKey();
|
||||
StringBuffer buffy = new StringBuffer();
|
||||
buffy.append(" ");
|
||||
// Name
|
||||
String name = (p.getName().length() <= NAME) ? p.getName() : p.getName().substring(0, NAME+1);
|
||||
buffy.append(MAUtils.padRight(name, NAME + 2, ' '));
|
||||
// Class
|
||||
buffy.append(MAUtils.padRight(entry.getValue(), CLASS + 2, ' '));
|
||||
// Wave
|
||||
buffy.append(MAUtils.padLeft(arena.waveMap.remove(p).toString(), WAVE, ' ') + " ");
|
||||
// Kills
|
||||
buffy.append(MAUtils.padLeft(arena.killMap.remove(p).toString(), KILLS, ' ') + " ");
|
||||
// Rewards
|
||||
buffy.append(MAUtils.listToString(arena.rewardMap.get(p), plugin));
|
||||
log.add(buffy.toString());
|
||||
for (Player p : arena.arenaPlayers)
|
||||
players.put(p, new ArenaPlayer(p, arena, plugin));
|
||||
}
|
||||
|
||||
log.add(" ");
|
||||
}
|
||||
|
||||
public void serialize()
|
||||
/**
|
||||
* Map classes to amounts of players playing as the classes.
|
||||
*/
|
||||
private void populateDistributionMap()
|
||||
{
|
||||
try
|
||||
{
|
||||
new File(plugin.getDataFolder() + File.separator + "logs").mkdir();
|
||||
File logFile = new File(plugin.getDataFolder() + File.separator + "logs" + File.separator + arena.configName() + ".log");
|
||||
if (logFile.exists())
|
||||
logFile.createNewFile();
|
||||
// Initialize the map
|
||||
for (String c : arena.classes)
|
||||
distribution.put(c,0);
|
||||
|
||||
FileWriter fw = new FileWriter(logFile, true);
|
||||
BufferedWriter bw = new BufferedWriter(fw);
|
||||
for (String l : log)
|
||||
{
|
||||
bw.write(l);
|
||||
bw.write(System.getProperty("line.separator"));
|
||||
// Count occurrences
|
||||
for (String c : arena.classMap.values())
|
||||
distribution.put(c,distribution.get(c) + 1);
|
||||
}
|
||||
|
||||
bw.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
/**
|
||||
* Save the data of the current session according to the logging type.
|
||||
*/
|
||||
public void saveSessionData()
|
||||
{
|
||||
e.printStackTrace();
|
||||
System.out.println("[MobArena] ERROR! Could not create log file!");
|
||||
return;
|
||||
}
|
||||
if (arena.logging.equals("xml"))
|
||||
XML.saveSessionData(this);
|
||||
else if (arena.logging.equals("yml") || arena.logging.equals("yaml"))
|
||||
YAML.saveSessionData(this);
|
||||
else
|
||||
PlainText.saveSessionData(this);
|
||||
//CSV.saveSessionData(this, plugin);
|
||||
//YAML.saveSessionData(this);
|
||||
}
|
||||
|
||||
public void add(String s) { log.add(s); }
|
||||
public void clear() { log.clear(); }
|
||||
/**
|
||||
* Update the totals-file
|
||||
*/
|
||||
public void updateArenaTotals()
|
||||
{
|
||||
Totals.updateArenaTotals(this);
|
||||
|
||||
if (arena.logging.equals("xml"))
|
||||
XML.updateArenaTotals(this);
|
||||
//PlainText.updateArenaTotals(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear maps.
|
||||
*/
|
||||
public void clearSessionData()
|
||||
{
|
||||
players.clear();
|
||||
distribution.clear();
|
||||
}
|
||||
|
||||
public Arena getArena() { return arena; }
|
||||
public Timestamp getStartTime() { return startTime; }
|
||||
public Timestamp getEndTime() { return endTime; }
|
||||
public String getDuration() { return MAUtils.getDuration(endTime.getTime() - startTime.getTime()); }
|
||||
public long getDurationLong() { return endTime.getTime() - startTime.getTime(); }
|
||||
public int getLastWave() { return lastWave; }
|
||||
|
||||
public void playerKill(Player p)
|
||||
{
|
||||
players.get(p).kills++;
|
||||
}
|
||||
|
||||
public void playerDamager(Player p, int damage)
|
||||
{
|
||||
players.get(p).dmgDone += damage;
|
||||
}
|
||||
|
||||
public void playerDamagee(Player p, int damage)
|
||||
{
|
||||
players.get(p).dmgTaken += damage;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
public class ArenaMaster
|
||||
//import com.garbagemule.ArenaPlugin.Master;
|
||||
|
||||
public class ArenaMaster //implements Master
|
||||
{
|
||||
private MobArena plugin;
|
||||
private Configuration config;
|
||||
@@ -49,6 +51,7 @@ public class ArenaMaster
|
||||
{
|
||||
plugin = instance;
|
||||
config = plugin.getConfig();
|
||||
arenas = new LinkedList<Arena>();
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +71,15 @@ public class ArenaMaster
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Arena> getPermittedArenas(Player p)
|
||||
{
|
||||
List<Arena> result = new LinkedList<Arena>();
|
||||
for (Arena arena : arenas)
|
||||
if (plugin.has(p, "mobarena.arenas." + arena.configName()))
|
||||
result.add(arena);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Arena getArenaAtLocation(Location loc)
|
||||
{
|
||||
for (Arena arena : arenas)
|
||||
@@ -225,17 +237,14 @@ public class ArenaMaster
|
||||
for (String configName : config.getKeys("arenas"))
|
||||
{
|
||||
String arenaPath = "arenas." + configName + ".";
|
||||
String worldName = config.getString(arenaPath + "settings.world");
|
||||
String worldName = config.getString(arenaPath + "settings.world", null);
|
||||
World world;
|
||||
if (worldName == null)
|
||||
if (worldName == null || worldName.equals(""))
|
||||
{
|
||||
System.out.println("[MobArena] ERROR! Could not find the world for arena '" + configName + "'. Using default world! Check the config-file!");
|
||||
MobArena.warning("Could not find the world for arena '" + configName + "'. Using default world! Check the config-file!");
|
||||
world = Bukkit.getServer().getWorlds().get(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
world = Bukkit.getServer().getWorld(worldName);
|
||||
}
|
||||
else world = Bukkit.getServer().getWorld(worldName);
|
||||
|
||||
Arena arena = new Arena(MAUtils.nameConfigToArena(configName), world);
|
||||
arena.load(config);
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.garbagemule.MobArena;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ArenaPlayer
|
||||
{
|
||||
public MobArena plugin;
|
||||
public Player player;
|
||||
public String className;
|
||||
public Arena arena;
|
||||
public List<ItemStack> rewards;
|
||||
public List<Block> blocks;
|
||||
|
||||
protected boolean inArena, inLobby, inSpec, isReady;
|
||||
|
||||
// Session fields.
|
||||
public int kills, dmgDone, dmgTaken, swings, hits, deaths, lastWave;
|
||||
public int flagCaps, flagAttempts, flagReturns; // BG: Capture the Pumpkin
|
||||
public int baseCaps; // BG: Domination
|
||||
|
||||
// All-time fields.
|
||||
protected int totalKills, totalDmgDone, totalDmgTaken, totalSwings, totalHits, totalDeaths;
|
||||
protected int totalFlagCaps, totalFlagAttempts, totalFlagReturns; // BG: Capture the Pumpkin
|
||||
protected int totalBaseCaps; // BG: Domination
|
||||
|
||||
public ArenaPlayer(Player player, Arena arena, MobArena plugin)
|
||||
{
|
||||
this.player = player;
|
||||
this.arena = arena;
|
||||
this.plugin = plugin;
|
||||
|
||||
className = arena.classMap.get(player);
|
||||
rewards = new LinkedList<ItemStack>();
|
||||
blocks = new LinkedList<Block>();
|
||||
}
|
||||
|
||||
public Player getPlayer() { return player; }
|
||||
public Arena getArena() { return arena; }
|
||||
public String getClassName() { return className; }
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.garbagemule.MobArena;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Lobby
|
||||
{
|
||||
protected Arena arena;
|
||||
protected ArenaMaster am;
|
||||
protected Location warp, l1, l2;
|
||||
|
||||
public Lobby(Arena arena)
|
||||
{
|
||||
this.arena = arena;
|
||||
}
|
||||
public Lobby()
|
||||
{
|
||||
this(null);
|
||||
}
|
||||
|
||||
public void playerJoin(Player p)
|
||||
{
|
||||
p.teleport(warp);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.garbagemule.MobArena;
|
||||
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockListener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
public class MABlockListener extends BlockListener
|
||||
@@ -19,9 +22,27 @@ public class MABlockListener extends BlockListener
|
||||
arena.eventListener.onBlockBreak(event);
|
||||
}
|
||||
|
||||
public void onBlockBurn(BlockBurnEvent event)
|
||||
{
|
||||
for (Arena arena : am.arenas)
|
||||
arena.eventListener.onBlockBurn(event);
|
||||
}
|
||||
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
for (Arena arena : am.arenas)
|
||||
arena.eventListener.onBlockPlace(event);
|
||||
}
|
||||
|
||||
public void onBlockIgnite(BlockIgniteEvent event)
|
||||
{
|
||||
for (Arena arena : am.arenas)
|
||||
arena.eventListener.onBlockIgnite(event);
|
||||
}
|
||||
|
||||
public void onBlockPhysics(BlockPhysicsEvent event)
|
||||
{
|
||||
for (Arena arena : am.arenas)
|
||||
arena.eventListener.onBlockPhysics(event);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.block.ContainerBlock;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@@ -56,9 +57,13 @@ public class MACommands implements CommandExecutor
|
||||
COMMANDS.add("spawnpoints"); // List spawnpoints
|
||||
COMMANDS.add("addspawn"); // Add a spawnpoint
|
||||
COMMANDS.add("delspawn"); // Delete a spawnpoint
|
||||
COMMANDS.add("containers"); // List containers
|
||||
COMMANDS.add("addcontainer"); // Add a container block
|
||||
COMMANDS.add("delcontainer"); // Delete a container block
|
||||
COMMANDS.add("reset"); // Reset arena coordinates
|
||||
COMMANDS.add("addclass"); // Add a new class
|
||||
COMMANDS.add("delclass"); // Delete a class
|
||||
COMMANDS.add("checkdata"); // Check arena well formedness
|
||||
COMMANDS.add("auto-generate"); // Auto-generate arena
|
||||
COMMANDS.add("auto-degenerate"); // Restore cuboid
|
||||
}
|
||||
@@ -115,6 +120,11 @@ public class MACommands implements CommandExecutor
|
||||
//
|
||||
////////////////////////////////////////////////////////////////*/
|
||||
|
||||
if (base.equals("spawn"))
|
||||
{
|
||||
p.getWorld().setSpawnLocation(p.getLocation().getBlockX(), p.getLocation().getBlockY() + 1, p.getLocation().getBlockZ());
|
||||
}
|
||||
|
||||
/*
|
||||
* Player join
|
||||
*/
|
||||
@@ -122,61 +132,113 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!player || !plugin.has(p, "mobarena.use.join"))
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
List<Arena> arenas = am.getEnabledArenas();
|
||||
if (!am.enabled || arenas.size() < 1)
|
||||
{
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_NOT_ENABLED);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Grab the arena to join
|
||||
Arena arena = arenas.size() == 1 ? arenas.get(0) : am.getArenaWithName(arg1);
|
||||
|
||||
// Run a couple of basic sanity checks
|
||||
if (!sanityChecks(p, arena, arg1, arenas))
|
||||
return true;
|
||||
|
||||
// Run a bunch of per-arena sanity checks
|
||||
if (!arena.canJoin(p))
|
||||
return true;
|
||||
|
||||
// If player is in a boat/minecart, eject!
|
||||
if (p.isInsideVehicle())
|
||||
p.leaveVehicle();
|
||||
|
||||
// Take entry fee and store inventory
|
||||
arena.takeFee(p);
|
||||
if (!arena.emptyInvJoin) MAUtils.storeInventory(p);
|
||||
|
||||
// If player is in a bed, unbed!
|
||||
if (p.isSleeping())
|
||||
{
|
||||
p.kickPlayer("Banned for life... Nah, just don't join from a bed ;)");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Join the arena!
|
||||
arena.playerJoin(p, p.getLocation());
|
||||
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_PLAYER_JOINED);
|
||||
if (!arena.entryFee.isEmpty())
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_FEE_PAID.get(MAUtils.listToString(arena.entryFee, plugin)));
|
||||
if (arena.hasPaid.contains(p))
|
||||
arena.hasPaid.remove(p);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Player leave
|
||||
*/
|
||||
if (base.equals("leave") || base.equals("l"))
|
||||
{
|
||||
if (!player || !plugin.has(p, "mobarena.use.leave"))
|
||||
{
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!am.arenaMap.containsKey(p))
|
||||
{
|
||||
Arena arena = am.getArenaWithSpectator(p);
|
||||
if (arena != null)
|
||||
{
|
||||
arena.playerLeave(p);
|
||||
MAUtils.tellPlayer(p, Msg.LEAVE_PLAYER_LEFT);
|
||||
return true;
|
||||
}
|
||||
|
||||
MAUtils.tellPlayer(p, Msg.LEAVE_NOT_PLAYING);
|
||||
return true;
|
||||
}
|
||||
|
||||
Arena arena = am.arenaMap.get(p);
|
||||
arena.playerLeave(p);
|
||||
MAUtils.tellPlayer(p, Msg.LEAVE_PLAYER_LEFT);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Player spectate
|
||||
*/
|
||||
if (base.equals("spectate") || base.equals("spec"))
|
||||
{
|
||||
if (!player || !plugin.has(p, "mobarena.use.spectate"))
|
||||
{
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
List<Arena> arenas = am.getEnabledArenas();
|
||||
if (!am.enabled || arenas.size() < 1)
|
||||
{
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_NOT_ENABLED));
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_NOT_ENABLED);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean error;
|
||||
Arena arena;
|
||||
// Grab the arena to join
|
||||
Arena arena = arenas.size() == 1 ? arenas.get(0) : am.getArenaWithName(arg1);
|
||||
|
||||
if (!arg1.isEmpty())
|
||||
arena = am.getArenaWithName(arg1);
|
||||
else if (arenas.size() == 1)
|
||||
arena = arenas.get(0);
|
||||
else
|
||||
arena = null;
|
||||
// Run a couple of basic sanity checks
|
||||
if (!sanityChecks(p, arena, arg1, arenas))
|
||||
return true;
|
||||
|
||||
if (arenas.size() > 1 && arg1.isEmpty())
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARG_NEEDED));
|
||||
else if (arena == null)
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
|
||||
else if (am.arenaMap.containsKey(p) && (am.arenaMap.get(p).arenaPlayers.contains(p) || am.arenaMap.get(p).lobbyPlayers.contains(p)))
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_IN_OTHER_ARENA));
|
||||
else if (!arena.enabled)
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARENA_NOT_ENABLED));
|
||||
else if (!arena.setup || arena.edit)
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARENA_NOT_SETUP));
|
||||
else if (arena.running && (arena.notifyPlayers.contains(p) || arena.notifyPlayers.add(p)))
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARENA_IS_RUNNING));
|
||||
else if (arena.arenaPlayers.contains(p))
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ALREADY_PLAYING));
|
||||
else if (!plugin.has(p, "mobarena.arenas." + arena.configName()))
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARENA_PERMISSION));
|
||||
else if (arena.maxPlayers > 0 && arena.lobbyPlayers.size() >= arena.maxPlayers)
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_PLAYER_LIMIT_REACHED));
|
||||
else if (arena.joinDistance > 0 && !arena.inRegionRadius(p.getLocation(), arena.joinDistance))
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_TOO_FAR));
|
||||
else if (!arena.canAfford(p) || !arena.takeFee(p))
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_FEE_REQUIRED, MAUtils.listToString(arena.entryFee, plugin)));
|
||||
else if (arena.emptyInvJoin && !MAUtils.hasEmptyInventory(p))
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_EMPTY_INV));
|
||||
else if (!arena.emptyInvJoin && !MAUtils.storeInventory(p))
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_STORE_INV_FAIL));
|
||||
else error = false;
|
||||
|
||||
// If there was an error, don't join.
|
||||
if (error)
|
||||
{
|
||||
if (arena != null)
|
||||
arena.refund(p);
|
||||
// Run a bunch of arena-specific sanity-checks
|
||||
if (!arena.canSpec(p))
|
||||
return true;
|
||||
}
|
||||
|
||||
// If player is in a boat/minecart, eject!
|
||||
if (p.isInsideVehicle())
|
||||
@@ -189,106 +251,10 @@ public class MACommands implements CommandExecutor
|
||||
return true;
|
||||
}
|
||||
|
||||
am.arenaMap.put(p,arena);
|
||||
arena.playerJoin(p, p.getLocation());
|
||||
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_PLAYER_JOINED));
|
||||
if (!arena.entryFee.isEmpty())
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_FEE_PAID, MAUtils.listToString(arena.entryFee, plugin)));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Player leave
|
||||
*/
|
||||
if (base.equals("leave") || base.equals("l"))
|
||||
{
|
||||
if (!player || !plugin.has(p, "mobarena.use.leave"))
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!am.arenaMap.containsKey(p))
|
||||
{
|
||||
Arena arena = am.getArenaWithSpectator(p);
|
||||
if (arena != null)
|
||||
{
|
||||
arena.playerLeave(p);
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.LEAVE_PLAYER_LEFT));
|
||||
return true;
|
||||
}
|
||||
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.LEAVE_NOT_PLAYING));
|
||||
return true;
|
||||
}
|
||||
|
||||
Arena arena = am.arenaMap.remove(p);
|
||||
arena.playerLeave(p);
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.LEAVE_PLAYER_LEFT));
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Player spectate
|
||||
*/
|
||||
if (base.equals("spectate") || base.equals("spec"))
|
||||
{
|
||||
if (!player || !plugin.has(p, "mobarena.use.spectate"))
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
return true;
|
||||
}
|
||||
List<Arena> arenas = am.getEnabledArenas();
|
||||
if (!am.enabled || arenas.size() < 1)
|
||||
{
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_NOT_ENABLED));
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean error;
|
||||
Arena arena;
|
||||
|
||||
if (!arg1.isEmpty())
|
||||
arena = am.getArenaWithName(arg1);
|
||||
else if (arenas.size() == 1)
|
||||
arena = arenas.get(0);
|
||||
else
|
||||
arena = null;
|
||||
|
||||
if (arenas.size() > 1 && arg1.isEmpty())
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARG_NEEDED));
|
||||
else if (arena == null)
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
|
||||
//else if (am.arenaMap.containsKey(p) && am.arenaMap.get(p).livePlayers.contains(p))
|
||||
else if (am.arenaMap.containsKey(p) && (am.arenaMap.get(p).arenaPlayers.contains(p) || am.arenaMap.get(p).lobbyPlayers.contains(p)))
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_IN_OTHER_ARENA));
|
||||
else if (!arena.enabled)
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARENA_NOT_ENABLED));
|
||||
else if (!arena.setup || arena.edit)
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARENA_NOT_SETUP));
|
||||
//else if (arena.livePlayers.contains(p))
|
||||
else if (arena.arenaPlayers.contains(p))
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.SPEC_ALREADY_PLAYING));
|
||||
else if (arena.emptyInvSpec && !MAUtils.hasEmptyInventory(p))
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.SPEC_EMPTY_INV));
|
||||
else if (arena.joinDistance > 0 && !arena.inRegionRadius(p.getLocation(), arena.joinDistance))
|
||||
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_TOO_FAR));
|
||||
else error = false;
|
||||
|
||||
// If there was an error, don't spec.
|
||||
if (error)
|
||||
return true;
|
||||
|
||||
// If player is in a boat/minecart, eject!
|
||||
if (p.isInsideVehicle())
|
||||
p.leaveVehicle();
|
||||
|
||||
am.arenaMap.put(p,arena);
|
||||
// Spectate the arena!
|
||||
arena.playerSpec(p, p.getLocation());
|
||||
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.SPEC_PLAYER_SPECTATE));
|
||||
MAUtils.tellPlayer(p, Msg.SPEC_PLAYER_SPECTATE);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -297,8 +263,8 @@ public class MACommands implements CommandExecutor
|
||||
*/
|
||||
if (base.equals("arenas"))
|
||||
{
|
||||
String list = MAUtils.listToString(am.arenas, plugin);
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_LIST_ARENAS, list));
|
||||
String list = MAUtils.listToString(player ? am.getPermittedArenas(p) : am.arenas, plugin);
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_LIST_ARENAS.get(list));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -312,12 +278,12 @@ public class MACommands implements CommandExecutor
|
||||
Arena arena = am.getArenaWithName(arg1);
|
||||
if (arena == null)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
|
||||
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
|
||||
return true;
|
||||
}
|
||||
|
||||
String list = MAUtils.listToString(arena.getLivingPlayers(), plugin);
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_LIST_PLAYERS, list));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_LIST_PLAYERS.get(list));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -326,7 +292,7 @@ public class MACommands implements CommandExecutor
|
||||
for (Arena arena : am.arenas)
|
||||
players.addAll(arena.getLivingPlayers());
|
||||
buffy.append(MAUtils.listToString(players, plugin));
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_LIST_PLAYERS, buffy.toString()));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_LIST_PLAYERS.get(buffy.toString()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -342,7 +308,7 @@ public class MACommands implements CommandExecutor
|
||||
arena = am.getArenaWithName(arg1);
|
||||
if (arena == null)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
|
||||
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -351,7 +317,7 @@ public class MACommands implements CommandExecutor
|
||||
arena = am.getArenaWithPlayer(p);
|
||||
if (arena == null)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.LEAVE_NOT_PLAYING));
|
||||
MAUtils.tellPlayer(sender, Msg.LEAVE_NOT_PLAYING);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -362,7 +328,7 @@ public class MACommands implements CommandExecutor
|
||||
}
|
||||
|
||||
String list = MAUtils.listToString(arena.getNonreadyPlayers(), plugin);
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_LIST_PLAYERS, list));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_LIST_PLAYERS.get(list));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -381,7 +347,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.admin.enable")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -396,7 +362,7 @@ public class MACommands implements CommandExecutor
|
||||
}
|
||||
else
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
|
||||
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -415,7 +381,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.admin.kick")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -449,7 +415,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.admin.restore")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -476,7 +442,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.admin.force.end")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -492,26 +458,25 @@ public class MACommands implements CommandExecutor
|
||||
Arena arena = am.getArenaWithName(arg2);
|
||||
if (arena == null)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
|
||||
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
|
||||
return true;
|
||||
}
|
||||
|
||||
//if (arena.livePlayers.isEmpty())
|
||||
if (arena.arenaPlayers.isEmpty())
|
||||
if (arena.getAllPlayers().isEmpty())
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.FORCE_END_EMPTY));
|
||||
MAUtils.tellPlayer(sender, Msg.FORCE_END_EMPTY);
|
||||
return true;
|
||||
}
|
||||
|
||||
arena.forceEnd();
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.FORCE_END_ENDED));
|
||||
MAUtils.tellPlayer(sender, Msg.FORCE_END_ENDED);
|
||||
return true;
|
||||
}
|
||||
else if (arg1.equals("start"))
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.admin.force.start")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -524,23 +489,23 @@ public class MACommands implements CommandExecutor
|
||||
Arena arena = am.getArenaWithName(arg2);
|
||||
if (arena == null)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
|
||||
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (arena.running)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.FORCE_START_RUNNING));
|
||||
MAUtils.tellPlayer(sender, Msg.FORCE_START_RUNNING);
|
||||
return true;
|
||||
}
|
||||
if (arena.readyPlayers.isEmpty())
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.FORCE_START_NOT_READY));
|
||||
MAUtils.tellPlayer(sender, Msg.FORCE_START_NOT_READY);
|
||||
return true;
|
||||
}
|
||||
|
||||
arena.forceStart();
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.FORCE_START_STARTED));
|
||||
MAUtils.tellPlayer(sender, Msg.FORCE_START_STARTED);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -557,7 +522,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.admin.config.reload")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -579,7 +544,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.setup.arena")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -592,7 +557,7 @@ public class MACommands implements CommandExecutor
|
||||
if (!arena.equals(am.selectedArena))
|
||||
buffy.append(arena.configName() + " ");
|
||||
}
|
||||
else buffy.append(MAMessages.get(Msg.MISC_NONE));
|
||||
else buffy.append(Msg.MISC_NONE);
|
||||
|
||||
MAUtils.tellPlayer(sender, "Other arenas: " + buffy.toString());
|
||||
return true;
|
||||
@@ -605,7 +570,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.setup.setarena")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
if (arg1.isEmpty())
|
||||
@@ -622,7 +587,7 @@ public class MACommands implements CommandExecutor
|
||||
}
|
||||
else
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
|
||||
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -634,7 +599,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!(player && plugin.has(p, "mobarena.setup.addarena")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
if (arg1.isEmpty())
|
||||
@@ -662,7 +627,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.setup.delarena")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
if (arg1.isEmpty())
|
||||
@@ -698,7 +663,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.setup.protect")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -764,7 +729,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.setup.editarena")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -833,7 +798,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!(player && plugin.has(p, "mobarena.setup.setregion")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -855,7 +820,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.setup.expandregion")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
if (args.length != 3 || !arg1.matches("(-)?[0-9]+"))
|
||||
@@ -903,7 +868,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!(player && plugin.has(p, "mobarena.setup.showregion")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
if (am.selectedArena.p1 == null || am.selectedArena.p2 == null)
|
||||
@@ -955,7 +920,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!(player && plugin.has(p, "mobarena.setup.setlobbyregion")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -974,7 +939,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.setup.expandlobbyregion")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
if (args.length != 3 || !arg1.matches("[0-9]+"))
|
||||
@@ -1022,7 +987,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!(player && plugin.has(p, "mobarena.setup.setwarp")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
if (!(arg1.equals("arena") || arg1.equals("lobby") || arg1.equals("spectator")))
|
||||
@@ -1032,7 +997,8 @@ public class MACommands implements CommandExecutor
|
||||
}
|
||||
|
||||
MAUtils.setArenaCoord(plugin.getConfig(), am.selectedArena, arg1, p.getLocation());
|
||||
MAUtils.tellPlayer(sender, "Set warp point " + arg1 + " for arena '" + am.selectedArena.configName() + "'");
|
||||
MAUtils.tellPlayer(sender, "Warp point " + arg1 + " was set for arena '" + am.selectedArena.configName() + "'");
|
||||
MAUtils.tellPlayer(sender, "Type /ma checkdata to see if you're missing anything...");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1043,7 +1009,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.setup.spawnpoints")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1060,7 +1026,7 @@ public class MACommands implements CommandExecutor
|
||||
}
|
||||
else
|
||||
{
|
||||
buffy.append(MAMessages.get(Msg.MISC_NONE));
|
||||
buffy.append(Msg.MISC_NONE);
|
||||
}
|
||||
|
||||
MAUtils.tellPlayer(sender, "Spawnpoints for arena '" + am.selectedArena.configName() + "': " + buffy.toString());
|
||||
@@ -1074,7 +1040,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!(player && plugin.has(p, "mobarena.setup.addspawn")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
if (arg1 == null || !arg1.matches("^[a-zA-Z][a-zA-Z0-9]*$"))
|
||||
@@ -1084,7 +1050,7 @@ public class MACommands implements CommandExecutor
|
||||
}
|
||||
|
||||
MAUtils.setArenaCoord(plugin.getConfig(), am.selectedArena, "spawnpoints." + arg1, p.getLocation());
|
||||
MAUtils.tellPlayer(sender, "Added spawnpoint " + arg1 + " for arena \"" + am.selectedArena.configName() + "\"");
|
||||
MAUtils.tellPlayer(sender, "Spawnpoint " + arg1 + " added for arena \"" + am.selectedArena.configName() + "\"");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1095,7 +1061,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.setup.delspawn")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
if (arg1 == null || !arg1.matches("^[a-zA-Z][a-zA-Z0-9]*$"))
|
||||
@@ -1105,22 +1071,112 @@ public class MACommands implements CommandExecutor
|
||||
}
|
||||
|
||||
if (MAUtils.delArenaCoord(plugin.getConfig(), am.selectedArena, "spawnpoints." + arg1))
|
||||
MAUtils.tellPlayer(sender, "Deleted spawnpoint " + arg1 + " for arena '" + am.selectedArena.configName() + "'");
|
||||
MAUtils.tellPlayer(sender, "Spawnpoint " + arg1 + " deleted for arena '" + am.selectedArena.configName() + "'");
|
||||
else
|
||||
MAUtils.tellPlayer(sender, "Could not find the spawnpoint " + arg1 + "for the arena '" + am.selectedArena.configName() + "'");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (base.equals("auto-generate"))
|
||||
if (base.equals("containers"))
|
||||
{
|
||||
if (!(player && plugin.has(p, "mobarena.setup.autogenerate")) && !op)
|
||||
if (!console && !(player && plugin.has(p, "mobarena.setup.containers")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
StringBuffer buffy = new StringBuffer();
|
||||
List<String> containers = plugin.getConfig().getKeys("arenas." + am.selectedArena.configName() + ".coords.containers");
|
||||
|
||||
if (containers != null)
|
||||
{
|
||||
for (String s : containers)
|
||||
{
|
||||
buffy.append(s);
|
||||
buffy.append(" ");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
buffy.append(Msg.MISC_NONE);
|
||||
}
|
||||
|
||||
MAUtils.tellPlayer(sender, "Containers for arena '" + am.selectedArena.configName() + "': " + buffy.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (base.equals("addcontainer"))
|
||||
{
|
||||
if (!(player && plugin.has(p, "mobarena.setup.addchest")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
if (arg1 == null || !arg1.matches("^[a-zA-Z][a-zA-Z0-9]*$"))
|
||||
{
|
||||
MAUtils.tellPlayer(sender, "Usage: /ma autogenerate <arena name>");
|
||||
MAUtils.tellPlayer(sender, "Usage: /ma addcontainer <container name>");
|
||||
return true;
|
||||
}
|
||||
if (!(p.getTargetBlock(null, 50).getState() instanceof ContainerBlock))
|
||||
{
|
||||
MAUtils.tellPlayer(sender, "You must look at container.");
|
||||
return true;
|
||||
}
|
||||
|
||||
MAUtils.setArenaCoord(plugin.getConfig(), am.selectedArena, "containers." + arg1, p.getTargetBlock(null, 50).getLocation());
|
||||
MAUtils.tellPlayer(sender, "Container '" + arg1 + "' added for arena \"" + am.selectedArena.configName() + "\"");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (base.equals("delcontainer"))
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.setup.delcontainer")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
if (arg1 == null || !arg1.matches("^[a-zA-Z][a-zA-Z0-9]*$"))
|
||||
{
|
||||
MAUtils.tellPlayer(sender, "Usage: /ma delcontainer <container name>");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (MAUtils.delArenaCoord(plugin.getConfig(), am.selectedArena, "containers." + arg1))
|
||||
MAUtils.tellPlayer(sender, "Container '" + arg1 + "' deleted for arena '" + am.selectedArena.configName() + "'");
|
||||
else
|
||||
MAUtils.tellPlayer(sender, "Could not find the container '" + arg1 + "' for arena '" + am.selectedArena.configName() + "'");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (base.equals("checkdata"))
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.setup.checkdata")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
Arena arena = arg1.isEmpty() ? am.selectedArena : am.getArenaWithName(arg1);
|
||||
if (arena == null)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
|
||||
return true;
|
||||
}
|
||||
|
||||
MAUtils.checkData(arena, sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (base.equals("auto-generate") || base.equals("autogenerate"))
|
||||
{
|
||||
if (!(player && plugin.has(p, "mobarena.setup.autogenerate")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
if (arg1 == null || !arg1.matches("^[a-zA-Z][a-zA-Z0-9]*$"))
|
||||
{
|
||||
MAUtils.tellPlayer(sender, "Usage: /ma auto-generate <arena name>");
|
||||
return true;
|
||||
}
|
||||
if (am.getArenaWithName(arg1) != null)
|
||||
@@ -1136,11 +1192,11 @@ public class MACommands implements CommandExecutor
|
||||
return true;
|
||||
}
|
||||
|
||||
if (base.equals("auto-degenerate"))
|
||||
if (base.equals("auto-degenerate") || base.equals("autodegenerate"))
|
||||
{
|
||||
if (!console && !(player && plugin.has(p, "mobarena.setup.autodegenerate")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
if (arg1.isEmpty())
|
||||
@@ -1155,7 +1211,7 @@ public class MACommands implements CommandExecutor
|
||||
}
|
||||
if (am.getArenaWithName(arg1) == null)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
|
||||
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1170,7 +1226,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!(player && plugin.has(p, "mobarena.setup.autogenerate")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1189,7 +1245,7 @@ public class MACommands implements CommandExecutor
|
||||
{
|
||||
if (!(player && plugin.has(p, "mobarena.setup.autodegenerate")) && !op)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
|
||||
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
|
||||
return true;
|
||||
}
|
||||
if (am.arenas.size() < 2)
|
||||
@@ -1199,7 +1255,7 @@ public class MACommands implements CommandExecutor
|
||||
}
|
||||
if (am.getArenaWithName("a1") == null)
|
||||
{
|
||||
MAUtils.tellPlayer(sender, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
|
||||
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1218,4 +1274,18 @@ public class MACommands implements CommandExecutor
|
||||
MAUtils.tellPlayer(sender, "Command not found.");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean sanityChecks(Player p, Arena arena, String arg1, List<Arena> arenas)
|
||||
{
|
||||
if (arenas.size() > 1 && arg1.isEmpty())
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_ARG_NEEDED);
|
||||
else if (arena == null)
|
||||
MAUtils.tellPlayer(p, Msg.ARENA_DOES_NOT_EXIST);
|
||||
else if (am.arenaMap.containsKey(p) && (am.arenaMap.get(p).arenaPlayers.contains(p) || am.arenaMap.get(p).lobbyPlayers.contains(p)))
|
||||
MAUtils.tellPlayer(p, Msg.JOIN_IN_OTHER_ARENA);
|
||||
else
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.garbagemule.MobArena;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class MAInventoryItem implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 739709220350581510L;
|
||||
private int typeId;
|
||||
private int amount;
|
||||
private short durability;
|
||||
|
||||
public MAInventoryItem(int typeId, int amount, short durability)
|
||||
{
|
||||
this.typeId = typeId;
|
||||
this.amount = amount;
|
||||
this.durability = durability;
|
||||
}
|
||||
|
||||
public int getTypeId() { return typeId; }
|
||||
public int getAmount() { return amount; }
|
||||
public short getDurability() { return durability; }
|
||||
}
|
||||
@@ -1,22 +1,27 @@
|
||||
package com.garbagemule.MobArena;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.ContainerBlock;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
@@ -27,6 +32,7 @@ import org.bukkit.event.entity.EntityTargetEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
|
||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
@@ -35,8 +41,14 @@ import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.Attachable;
|
||||
import org.bukkit.material.Bed;
|
||||
import org.bukkit.material.Door;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.material.Redstone;
|
||||
|
||||
import com.garbagemule.MobArena.MAMessages.Msg;
|
||||
import com.garbagemule.MobArena.repairable.*;
|
||||
|
||||
public class MAListener implements ArenaListener
|
||||
{
|
||||
@@ -49,29 +61,64 @@ public class MAListener implements ArenaListener
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void onBlockPhysics(BlockPhysicsEvent event)
|
||||
{
|
||||
if (!arena.inRegion(event.getBlock().getLocation()) || arena.softRestore)
|
||||
return;
|
||||
|
||||
MaterialData data = event.getBlock().getState().getData();
|
||||
if (data instanceof Attachable || data instanceof Bed || data instanceof Door || data instanceof Redstone)
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public void onBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
if (!arena.inRegion(event.getBlock().getLocation()) || arena.edit || (!arena.protect && arena.running))
|
||||
if (onBlockDestroy(event))
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public void onBlockBurn(BlockBurnEvent event)
|
||||
{
|
||||
if (onBlockDestroy(event))
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
private boolean onBlockDestroy(BlockEvent event)
|
||||
{
|
||||
if (!arena.inRegion(event.getBlock().getLocation()) || arena.edit || (!arena.protect && arena.running))
|
||||
return true;
|
||||
|
||||
Block b = event.getBlock();
|
||||
if (arena.blocks.remove(b) || b.getType() == Material.TNT)
|
||||
return;
|
||||
return true;
|
||||
|
||||
if (arena.softRestore && arena.running)
|
||||
{
|
||||
int[] buffer = new int[5];
|
||||
buffer[0] = b.getX();
|
||||
buffer[1] = b.getY();
|
||||
buffer[2] = b.getZ();
|
||||
buffer[3] = b.getTypeId();
|
||||
buffer[4] = (int) b.getData();
|
||||
arena.repairList.add(buffer);
|
||||
if (!arena.softRestoreDrops) event.getBlock().setTypeId(0);
|
||||
return;
|
||||
BlockState state = b.getState();
|
||||
|
||||
Repairable r = null;
|
||||
if (state instanceof ContainerBlock)
|
||||
r = new RepairableContainer(state);
|
||||
else if (state instanceof Sign)
|
||||
r = new RepairableSign(state);
|
||||
else if (state.getData() instanceof Attachable)
|
||||
r = new RepairableAttachable(state);
|
||||
else
|
||||
r = new RepairableBlock(state);
|
||||
|
||||
arena.repairables.add(r);
|
||||
|
||||
if (!arena.softRestoreDrops)
|
||||
b.setTypeId(0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
@@ -87,6 +134,7 @@ public class MAListener implements ArenaListener
|
||||
|
||||
if (mat == Material.WOODEN_DOOR || mat == Material.IRON_DOOR_BLOCK)
|
||||
arena.blocks.add(b.getRelative(0,1,0));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -94,11 +142,37 @@ public class MAListener implements ArenaListener
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event)
|
||||
public void onBlockIgnite(BlockIgniteEvent event)
|
||||
{
|
||||
if (!arena.inRegion(event.getLocation()) || event.getSpawnReason() == SpawnReason.CUSTOM)
|
||||
if (!arena.inRegion(event.getBlock().getLocation()))
|
||||
return;
|
||||
|
||||
switch (event.getCause())
|
||||
{
|
||||
case LIGHTNING:
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
case SPREAD:
|
||||
case FLINT_AND_STEEL:
|
||||
if (arena.running)
|
||||
arena.blocks.add(event.getBlock());
|
||||
else
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event)
|
||||
{
|
||||
if (!arena.inRegion(event.getLocation())) // || event.getSpawnReason() == SpawnReason.CUSTOM)
|
||||
return;
|
||||
|
||||
LivingEntity entity = (LivingEntity) event.getEntity();
|
||||
if (arena.running && entity instanceof Slime)
|
||||
arena.monsters.add(entity);
|
||||
else
|
||||
// If running == true, setCancelled(false), and vice versa.
|
||||
event.setCancelled(!arena.running);
|
||||
}
|
||||
@@ -111,82 +185,196 @@ public class MAListener implements ArenaListener
|
||||
event.setYield(0);
|
||||
arena.monsters.remove(event.getEntity());
|
||||
|
||||
// If the arena isn't running
|
||||
// Cancel if the arena isn't running or if the repair delay is 0
|
||||
if (!arena.running || arena.repairDelay == 0)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// If there is a sign in the blocklist, cancel
|
||||
for (Block b : event.blockList())
|
||||
{
|
||||
if (!(b.getType() == Material.SIGN_POST || b.getType() == Material.WALL_SIGN))
|
||||
continue;
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Uncancel, just in case.
|
||||
event.setCancelled(false);
|
||||
|
||||
int[] buffer;
|
||||
final HashMap<Block,Integer> blockMap = new HashMap<Block,Integer>();
|
||||
// Handle all the blocks in the block list.
|
||||
for (Block b : event.blockList())
|
||||
{
|
||||
Material mat = b.getType();
|
||||
BlockState state = b.getState();
|
||||
|
||||
if (mat == Material.LAVA) b.setType(Material.STATIONARY_LAVA);
|
||||
else if (mat == Material.WATER) b.setType(Material.STATIONARY_WATER);
|
||||
if (state.getData() instanceof Door && ((Door) state.getData()).isTopHalf())
|
||||
state = b.getRelative(BlockFace.DOWN).getState();
|
||||
else if (state.getData() instanceof Bed && ((Bed) state.getData()).isHeadOfBed())
|
||||
state = b.getRelative(((Bed) state.getData()).getFacing().getOppositeFace()).getState();
|
||||
|
||||
if (mat == Material.WOODEN_DOOR || mat == Material.IRON_DOOR_BLOCK || mat == Material.FIRE || mat == Material.CAKE_BLOCK || mat == Material.WATER || mat == Material.LAVA)
|
||||
{
|
||||
arena.blocks.remove(b);
|
||||
}
|
||||
else if (arena.blocks.remove(b))
|
||||
{
|
||||
arena.world.dropItemNaturally(b.getLocation(), new ItemStack(b.getTypeId(), 1));
|
||||
}
|
||||
else if (arena.softRestore)
|
||||
{
|
||||
buffer = new int[5];
|
||||
buffer[0] = b.getX();
|
||||
buffer[1] = b.getY();
|
||||
buffer[2] = b.getZ();
|
||||
buffer[3] = b.getTypeId();
|
||||
buffer[4] = (int) b.getData();
|
||||
arena.repairList.add(buffer);
|
||||
blockMap.put(b, b.getTypeId() + (b.getData() * 1000));
|
||||
}
|
||||
// Create a Repairable from the block.
|
||||
Repairable r = null;
|
||||
if (state instanceof ContainerBlock)
|
||||
r = new RepairableContainer(state);
|
||||
else if (state instanceof Sign)
|
||||
r = new RepairableSign(state);
|
||||
else if (state.getData() instanceof Bed)
|
||||
r = new RepairableBed(state);
|
||||
else if (state.getData() instanceof Door)
|
||||
r = new RepairableDoor(state);
|
||||
else if (state.getData() instanceof Attachable || state.getData() instanceof Redstone)
|
||||
r = new RepairableAttachable(state);
|
||||
else
|
||||
{
|
||||
blockMap.put(b, b.getTypeId() + (b.getData() * 1000));
|
||||
}
|
||||
r = new RepairableBlock(state);
|
||||
|
||||
// Cakes and liquids should just get removed. If player-placed block, drop as item.
|
||||
Material mat = state.getType();
|
||||
if (mat == Material.CAKE_BLOCK || mat == Material.WATER || mat == Material.LAVA)
|
||||
arena.blocks.remove(b);
|
||||
else if (arena.blocks.remove(b))
|
||||
arena.world.dropItemNaturally(b.getLocation(), new ItemStack(state.getTypeId(), 1));
|
||||
else if (arena.softRestore)
|
||||
arena.repairables.add(r);
|
||||
else
|
||||
arena.queueRepairable(r);
|
||||
}
|
||||
|
||||
// If the arena isn't protected, or soft-restore is on, return.
|
||||
if (!arena.protect || arena.softRestore)
|
||||
return;
|
||||
|
||||
// Otherwise, schedule repairs!
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
for (Map.Entry<Block,Integer> entry : blockMap.entrySet())
|
||||
{
|
||||
Block b = entry.getKey();
|
||||
int type = entry.getValue();
|
||||
|
||||
b.getLocation().getBlock().setTypeId(type % 1000);
|
||||
|
||||
if (type > 1000)
|
||||
b.getLocation().getBlock().setData((byte) (type / 1000));
|
||||
}
|
||||
arena.repairBlocks();
|
||||
}
|
||||
}, arena.repairDelay);
|
||||
}
|
||||
|
||||
public void onEntityDeath(EntityDeathEvent event)
|
||||
{
|
||||
if (event.getEntity() instanceof Player)
|
||||
{
|
||||
Player p = (Player) event.getEntity();
|
||||
|
||||
if (!arena.arenaPlayers.contains(p))
|
||||
return;
|
||||
|
||||
event.getDrops().clear();
|
||||
arena.playerDeath(p);
|
||||
return;
|
||||
}
|
||||
|
||||
if (arena.monsters.remove(event.getEntity()))
|
||||
{
|
||||
EntityDamageEvent e1 = event.getEntity().getLastDamageCause();
|
||||
EntityDamageByEntityEvent e2 = (e1 instanceof EntityDamageByEntityEvent) ? (EntityDamageByEntityEvent) e1 : null;
|
||||
Entity damager = (e2 != null) ? e2.getDamager() : null;
|
||||
|
||||
if (damager instanceof Player)
|
||||
arena.playerKill((Player) damager);
|
||||
|
||||
event.getDrops().clear();
|
||||
arena.resetIdleTimer();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void onEntityDamage(EntityDamageEvent event)
|
||||
{
|
||||
if (!arena.running) return;
|
||||
|
||||
EntityDamageByEntityEvent e = (event instanceof EntityDamageByEntityEvent) ? (EntityDamageByEntityEvent) event : null;
|
||||
Entity damager = (e != null) ? e.getDamager() : null;
|
||||
Entity damagee = event.getEntity();
|
||||
|
||||
// Pet wolf
|
||||
if (damagee instanceof Wolf && arena.pets.contains(damagee))
|
||||
{
|
||||
if (damager == null)
|
||||
{
|
||||
damagee.setFireTicks(32768);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
else if (damager instanceof Player)
|
||||
event.setCancelled(true);
|
||||
else
|
||||
event.setDamage(0);
|
||||
|
||||
return;
|
||||
}
|
||||
// Arena player
|
||||
else if (damagee instanceof Player)
|
||||
{
|
||||
if (arena.lobbyPlayers.contains(damagee))
|
||||
event.setCancelled(true);
|
||||
else if (!arena.arenaPlayers.contains(damagee))
|
||||
return;
|
||||
else if (!arena.detDamage && event.getCause() == DamageCause.BLOCK_EXPLOSION)
|
||||
event.setCancelled(true);
|
||||
else if (damager instanceof Player && !arena.pvp)
|
||||
{
|
||||
// if 'inLobby' fails, and 'not inArena' fails, 'inArena' is true
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.isCancelled())
|
||||
arena.log.players.get((Player) damagee).dmgTaken += event.getDamage();
|
||||
}
|
||||
// Other LivingEntity
|
||||
else if (arena.monsters.contains(damagee))
|
||||
{
|
||||
if (damager instanceof Player)
|
||||
{
|
||||
if (!arena.arenaPlayers.contains(damager))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
arena.log.players.get((Player) damager).dmgDone += event.getDamage();
|
||||
arena.log.players.get((Player) damager).hits++;
|
||||
}
|
||||
else if (damager instanceof Wolf && arena.pets.contains(damager))
|
||||
{
|
||||
event.setDamage(1);
|
||||
arena.log.players.get((Player) ((Wolf) damager).getOwner()).dmgDone += event.getDamage();
|
||||
}
|
||||
else if (damager instanceof LivingEntity)
|
||||
{
|
||||
if (!arena.monsterInfight)
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// Boss
|
||||
if (arena.bossWave != null && damagee.equals(arena.bossWave.getEntity()))
|
||||
{
|
||||
if (event.getCause() == DamageCause.LIGHTNING)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Subtract boss health, and reset actual entity health
|
||||
arena.bossWave.subtractHealth(event.getDamage());
|
||||
arena.bossWave.getEntity().setHealth(200);
|
||||
|
||||
// Set damage to 1 for knockback and feedback
|
||||
event.setDamage(1);
|
||||
|
||||
// If the boss is dead, remove the entity and create an explosion!
|
||||
if (arena.bossWave.getHealth() <= 0)
|
||||
{
|
||||
arena.bossWave.clear();
|
||||
arena.bossWave = null;
|
||||
}
|
||||
else if (arena.bossWave.getHealth() <= 100 && !arena.bossWave.isLowHealthAnnounced())
|
||||
{
|
||||
MAUtils.tellAll(arena, Msg.WAVE_BOSS_LOW_HEALTH);
|
||||
arena.bossWave.setLowHealthAnnounced(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEntityCombust(EntityCombustEvent event)
|
||||
{
|
||||
if (arena.monsters.contains(event.getEntity()))
|
||||
@@ -208,27 +396,23 @@ public class MAListener implements ArenaListener
|
||||
|
||||
// If the target is a player, cancel.
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (arena.monsters.contains(event.getEntity()))
|
||||
else if (arena.monsters.contains(event.getEntity()))
|
||||
{
|
||||
if (event.getReason() == TargetReason.FORGOT_TARGET)
|
||||
{
|
||||
event.setTarget(MAUtils.getClosestPlayer(event.getEntity(), arena));
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getReason() == TargetReason.TARGET_DIED)
|
||||
{
|
||||
else if (event.getReason() == TargetReason.TARGET_DIED)
|
||||
event.setTarget(MAUtils.getClosestPlayer(event.getEntity(), arena));
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getReason() == TargetReason.CLOSEST_PLAYER)
|
||||
else if (event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY)
|
||||
if (arena.pets.contains(event.getTarget()))
|
||||
event.setCancelled(true);
|
||||
|
||||
else if (event.getReason() == TargetReason.CLOSEST_PLAYER)
|
||||
if (!arena.arenaPlayers.contains(event.getTarget()))
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,109 +427,50 @@ public class MAListener implements ArenaListener
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public void onEntityDeath(EntityDeathEvent event)
|
||||
public void onPlayerAnimation(PlayerAnimationEvent event)
|
||||
{
|
||||
if (event.getEntity() instanceof Player)
|
||||
{
|
||||
Player p = (Player) event.getEntity();
|
||||
|
||||
if (!arena.arenaPlayers.contains(p))
|
||||
if (!arena.running || !arena.arenaPlayers.contains(event.getPlayer()))
|
||||
return;
|
||||
|
||||
event.getDrops().clear();
|
||||
arena.waveMap.put(p, arena.spawnThread.wave - 1);
|
||||
arena.playerDeath(p);
|
||||
return;
|
||||
}
|
||||
|
||||
if (arena.monsters.remove(event.getEntity()))
|
||||
{
|
||||
EntityDamageEvent e1 = event.getEntity().getLastDamageCause();
|
||||
EntityDamageByEntityEvent e2 = (e1 instanceof EntityDamageByEntityEvent) ? (EntityDamageByEntityEvent) e1 : null;
|
||||
Entity damager = (e2 != null) ? e2.getDamager() : null;
|
||||
|
||||
if (e2 != null && damager instanceof Player)
|
||||
arena.playerKill((Player) damager);
|
||||
|
||||
event.getDrops().clear();
|
||||
arena.resetIdleTimer();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void onEntityDamage(EntityDamageEvent event)
|
||||
{
|
||||
if (!arena.running) return;
|
||||
|
||||
EntityDamageByEntityEvent e = (event instanceof EntityDamageByEntityEvent) ? (EntityDamageByEntityEvent) event : null;
|
||||
Entity damager = (e != null) ? e.getDamager() : null;
|
||||
Entity damagee = event.getEntity();
|
||||
|
||||
// Damagee - Pet Wolf - cancel all damage.
|
||||
if (damagee instanceof Wolf && arena.pets.contains(damagee))
|
||||
{
|
||||
if (event.getCause() == DamageCause.FIRE_TICK)
|
||||
{
|
||||
damagee.setFireTicks(32768); // For mcMMO
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (e != null && damager instanceof Player)
|
||||
event.setCancelled(true);
|
||||
|
||||
event.setDamage(0);
|
||||
return;
|
||||
}
|
||||
|
||||
// Damager - Pet Wolf - lower damage
|
||||
if (e != null && damager instanceof Wolf && arena.pets.contains(damager))
|
||||
{
|
||||
event.setDamage(1);
|
||||
return;
|
||||
}
|
||||
|
||||
// Damagee & Damager - Player - cancel if pvp disabled
|
||||
if (damagee instanceof Player && damager instanceof Player)
|
||||
{
|
||||
if (arena.arenaPlayers.contains(damagee) && !arena.pvp)
|
||||
event.setCancelled(true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Damagee & Damager - Monsters - cancel if no monsterInfight
|
||||
if (e != null && arena.monsters.contains(damagee) && arena.monsters.contains(damager))
|
||||
{
|
||||
if (!arena.monsterInfight)
|
||||
event.setCancelled(true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Creeper detonations
|
||||
if (arena.inRegion(damagee.getLocation()))
|
||||
{
|
||||
if (!arena.detDamage || !(damagee instanceof Player) || !arena.arenaPlayers.contains((Player) damagee))
|
||||
return;
|
||||
|
||||
if (event.getCause() == DamageCause.BLOCK_EXPLOSION)
|
||||
event.setCancelled(true);
|
||||
|
||||
return;
|
||||
}
|
||||
arena.log.players.get(event.getPlayer()).swings++;
|
||||
}
|
||||
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event)
|
||||
{
|
||||
if (arena.running && arena.shareInArena) return;
|
||||
|
||||
Player p = event.getPlayer();
|
||||
if (!arena.arenaPlayers.contains(p) && !arena.lobbyPlayers.contains(p))
|
||||
return;
|
||||
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_DROP_ITEM));
|
||||
// Player is in the lobby
|
||||
if (arena.lobbyPlayers.contains(p))
|
||||
{
|
||||
MAUtils.tellPlayer(p, Msg.LOBBY_DROP_ITEM);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// Player is in the arena
|
||||
else if (arena.arenaPlayers.contains(p))
|
||||
{
|
||||
if (!arena.shareInArena)
|
||||
{
|
||||
MAUtils.tellPlayer(p, Msg.LOBBY_DROP_ITEM);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Player died/left
|
||||
else if (p.getLocation().equals(arena.spectatorLoc) || p.getLocation().equals(arena.locations.get(p)))
|
||||
{
|
||||
MobArena.warning("Player '" + p.getName() + "' tried to steal item " + event.getItemDrop().getItemStack().getType());
|
||||
event.getItemDrop().remove();
|
||||
}
|
||||
|
||||
// Player is in the spectator area
|
||||
else if (arena.specPlayers.contains(p))
|
||||
{
|
||||
MAUtils.tellPlayer(p, Msg.LOBBY_DROP_ITEM);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event)
|
||||
{
|
||||
if (!arena.readyPlayers.contains(event.getPlayer()) && !arena.arenaPlayers.contains(event.getPlayer()))
|
||||
@@ -387,12 +512,12 @@ public class MAListener implements ArenaListener
|
||||
{
|
||||
if (arena.classMap.containsKey(p))
|
||||
{
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_PLAYER_READY));
|
||||
MAUtils.tellPlayer(p, Msg.LOBBY_PLAYER_READY);
|
||||
arena.playerReady(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_PICK_CLASS));
|
||||
MAUtils.tellPlayer(p, Msg.LOBBY_PICK_CLASS);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -402,7 +527,7 @@ public class MAListener implements ArenaListener
|
||||
{
|
||||
if (a == Action.RIGHT_CLICK_BLOCK)
|
||||
{
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_RIGHT_CLICK));
|
||||
MAUtils.tellPlayer(p, Msg.LOBBY_RIGHT_CLICK);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -414,18 +539,18 @@ public class MAListener implements ArenaListener
|
||||
if (!arena.classes.contains(className) && !className.equalsIgnoreCase("random"))
|
||||
return;
|
||||
|
||||
if (!plugin.hasDefTrue(p, "mobarena.classes." + className) && !className.equalsIgnoreCase("random"))
|
||||
if (!plugin.has(p, "mobarena.classes." + className) && !className.equalsIgnoreCase("random"))
|
||||
{
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_CLASS_PERMISSION));
|
||||
MAUtils.tellPlayer(p, Msg.LOBBY_CLASS_PERMISSION);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the player's class.
|
||||
arena.assignClass(p, className);
|
||||
if (!className.equalsIgnoreCase("random"))
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_CLASS_PICKED, className));
|
||||
MAUtils.tellPlayer(p, Msg.LOBBY_CLASS_PICKED, className, arena.classItems.get(className).get(0).getType());
|
||||
else
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_CLASS_RANDOM));
|
||||
MAUtils.tellPlayer(p, Msg.LOBBY_CLASS_RANDOM);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -437,7 +562,6 @@ public class MAListener implements ArenaListener
|
||||
if (!arena.enabled || (!arena.arenaPlayers.contains(p) && !arena.lobbyPlayers.contains(p)))
|
||||
return;
|
||||
|
||||
plugin.getAM().arenaMap.remove(p);
|
||||
arena.playerLeave(p);
|
||||
}
|
||||
|
||||
@@ -447,13 +571,12 @@ public class MAListener implements ArenaListener
|
||||
if (!arena.enabled || (!arena.arenaPlayers.contains(p) && !arena.lobbyPlayers.contains(p)))
|
||||
return;
|
||||
|
||||
plugin.getAM().arenaMap.remove(p);
|
||||
arena.playerLeave(p);
|
||||
}
|
||||
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event)
|
||||
{
|
||||
if (arena.edit || !arena.enabled || !arena.setup || arena.allowWarp)
|
||||
if (!arena.running || arena.edit || !arena.enabled || !arena.setup || arena.allowWarp)
|
||||
return;
|
||||
|
||||
if (!arena.inRegion(event.getTo()) && !arena.inRegion(event.getFrom()))
|
||||
@@ -468,10 +591,10 @@ public class MAListener implements ArenaListener
|
||||
{
|
||||
if (arena.inRegion(from))
|
||||
{
|
||||
if (to.equals(arena.arenaLoc) || to.equals(arena.lobbyLoc) || to.equals(arena.spectatorLoc) || to.equals(old))
|
||||
if (arena.inRegion(to) || to.equals(arena.arenaLoc) || to.equals(arena.lobbyLoc) || to.equals(arena.spectatorLoc) || to.equals(old))
|
||||
return;
|
||||
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.WARP_FROM_ARENA));
|
||||
MAUtils.tellPlayer(p, Msg.WARP_FROM_ARENA);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -481,7 +604,7 @@ public class MAListener implements ArenaListener
|
||||
if (to.equals(arena.arenaLoc) || to.equals(arena.lobbyLoc) || to.equals(arena.spectatorLoc) || to.equals(old))
|
||||
return;
|
||||
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.WARP_TO_ARENA));
|
||||
MAUtils.tellPlayer(p, Msg.WARP_TO_ARENA);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -511,6 +634,6 @@ public class MAListener implements ArenaListener
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.MISC_COMMAND_NOT_ALLOWED));
|
||||
MAUtils.tellPlayer(p, Msg.MISC_COMMAND_NOT_ALLOWED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,164 +6,192 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class MAMessages
|
||||
{
|
||||
protected static Map<Msg,String> msgMap;
|
||||
private static Map<Msg,String> defaults = new HashMap<Msg,String>();
|
||||
protected static enum Msg
|
||||
public static enum Msg
|
||||
{
|
||||
ARENA_START,
|
||||
ARENA_END,
|
||||
ARENA_DOES_NOT_EXIST,
|
||||
JOIN_PLAYER_JOINED,
|
||||
JOIN_NOT_ENABLED,
|
||||
JOIN_IN_OTHER_ARENA,
|
||||
JOIN_ARENA_NOT_ENABLED,
|
||||
JOIN_ARENA_NOT_SETUP,
|
||||
JOIN_ARENA_PERMISSION,
|
||||
JOIN_FEE_REQUIRED,
|
||||
JOIN_FEE_PAID,
|
||||
JOIN_ARENA_IS_RUNNING,
|
||||
JOIN_ALREADY_PLAYING,
|
||||
JOIN_ARG_NEEDED,
|
||||
JOIN_TOO_FAR,
|
||||
JOIN_EMPTY_INV,
|
||||
JOIN_PLAYER_LIMIT_REACHED,
|
||||
JOIN_STORE_INV_FAIL,
|
||||
LEAVE_PLAYER_LEFT,
|
||||
LEAVE_NOT_PLAYING,
|
||||
PLAYER_DIED,
|
||||
SPEC_PLAYER_SPECTATE,
|
||||
SPEC_NOT_RUNNING,
|
||||
SPEC_ARG_NEEDED,
|
||||
SPEC_EMPTY_INV,
|
||||
SPEC_ALREADY_PLAYING,
|
||||
NOT_READY_PLAYERS,
|
||||
FORCE_START_STARTED,
|
||||
FORCE_START_RUNNING,
|
||||
FORCE_START_NOT_READY,
|
||||
FORCE_END_ENDED,
|
||||
FORCE_END_EMPTY,
|
||||
FORCE_END_IDLE,
|
||||
REWARDS_GIVE,
|
||||
LOBBY_CLASS_PICKED,
|
||||
LOBBY_CLASS_RANDOM,
|
||||
LOBBY_CLASS_PERMISSION,
|
||||
LOBBY_NOT_ENOUGH_PLAYERS,
|
||||
LOBBY_PLAYER_READY,
|
||||
LOBBY_DROP_ITEM,
|
||||
LOBBY_PICK_CLASS,
|
||||
LOBBY_RIGHT_CLICK,
|
||||
WARP_TO_ARENA,
|
||||
WARP_FROM_ARENA,
|
||||
WAVE_DEFAULT,
|
||||
WAVE_SPECIAL,
|
||||
WAVE_REWARD,
|
||||
MISC_LIST_ARENAS,
|
||||
MISC_LIST_PLAYERS,
|
||||
MISC_COMMAND_NOT_ALLOWED,
|
||||
MISC_NO_ACCESS,
|
||||
MISC_NONE
|
||||
ARENA_START("Let the slaughter begin!", "Arena started!", Material.REDSTONE_TORCH_ON),
|
||||
ARENA_END("Arena finished.", "Arena finished.", Material.REDSTONE_TORCH_OFF),
|
||||
ARENA_DOES_NOT_EXIST("That arena does not exist. Type /ma arenas for a list.", "Can't find arena."),
|
||||
JOIN_NOT_ENABLED("MobArena is not enabled.", "MobArena disabled.", Material.REDSTONE_TORCH_OFF),
|
||||
JOIN_IN_OTHER_ARENA("You are already in an arena! Leave that one first.", "In another arena."),
|
||||
JOIN_ARENA_NOT_ENABLED("This arena is not enabled.", "Arena disabled.", Material.REDSTONE_TORCH_OFF),
|
||||
JOIN_ARENA_NOT_SETUP("This arena has not been set up yet.", "Arena not set up.", Material.REDSTONE_TORCH_OFF),
|
||||
JOIN_ARENA_EDIT_MODE("This arena is in edit mode.", "Arena in edit mode.", Material.IRON_SPADE),
|
||||
JOIN_ARENA_PERMISSION("You don't have permission to join this arena.", "No permission!", Material.FENCE),
|
||||
JOIN_FEE_REQUIRED("Insufficient funds. Price: %", "Price: %", Material.DIAMOND),
|
||||
JOIN_FEE_PAID("Price to join was: %", "Paid: %", Material.DIAMOND),
|
||||
JOIN_ARENA_IS_RUNNING("This arena is in already progress.", "Already running!", Material.GOLD_RECORD),
|
||||
JOIN_ALREADY_PLAYING("You are already playing!", "Already playing!", Material.GOLD_RECORD),
|
||||
JOIN_ARG_NEEDED("You must specify an arena. Type /ma arenas for a list."),
|
||||
JOIN_TOO_FAR("You are too far away from the arena to join/spectate.", "Too far from arena.", Material.COMPASS),
|
||||
JOIN_EMPTY_INV("You must empty your inventory to join the arena.", "Empty your inventory.", Material.CHEST),
|
||||
JOIN_PLAYER_LIMIT_REACHED("The player limit of this arena has been reached.", "No spots left.", Material.MILK_BUCKET),
|
||||
JOIN_STORE_INV_FAIL("Failed to store inventory. Try again."),
|
||||
JOIN_EXISTING_INV_RESTORED("Your old inventory items have been restored."),
|
||||
JOIN_PLAYER_JOINED("You joined the arena. Have fun!", "Joined arena.", Material.IRON_SWORD),
|
||||
LEAVE_NOT_PLAYING("You are not in the arena.", "Not in arena."),
|
||||
LEAVE_PLAYER_LEFT("You left the arena. Thanks for playing!", "Left arena.", Material.WOOD_DOOR),
|
||||
PLAYER_DIED("% died!", "% died!", Material.BONE),
|
||||
SPEC_PLAYER_SPECTATE("Enjoy the show!", "Enjoy the show!"),
|
||||
SPEC_NOT_RUNNING("This arena isn't running.", "Arena not running.", Material.REDSTONE_TORCH_OFF),
|
||||
SPEC_ARG_NEEDED("You must specify an arena. Type /ma arenas for a list.", "Arena name required."),
|
||||
SPEC_EMPTY_INV("Empty your inventory first!", "Empty your inventory.", Material.CHEST),
|
||||
SPEC_ALREADY_PLAYING("Can't spectate when in the arena!", "Already playing!"),
|
||||
NOT_READY_PLAYERS("Not ready: %"),
|
||||
FORCE_START_RUNNING("Arena has already started."),
|
||||
FORCE_START_NOT_READY("Can't force start, no players are ready."),
|
||||
FORCE_START_STARTED("Forced arena start."),
|
||||
FORCE_END_EMPTY("No one is in the arena."),
|
||||
FORCE_END_ENDED("Forced arena end."),
|
||||
FORCE_END_IDLE("You weren't quick enough!"),
|
||||
REWARDS_GIVE("Here are all of your rewards!"),
|
||||
LOBBY_DROP_ITEM("No sharing allowed at this time!", "Can't drop items here."),
|
||||
LOBBY_PLAYER_READY("You have been flagged as ready!", "Flagged as ready!"),
|
||||
LOBBY_PICK_CLASS("You must first pick a class!", "Pick a class first!"),
|
||||
LOBBY_NOT_ENOUGH_PLAYERS("Not enough players to start. Need at least % players.", "Need more players."),
|
||||
LOBBY_RIGHT_CLICK("Punch the sign. Don't right-click.", "Punch the sign."),
|
||||
LOBBY_CLASS_PICKED("You have chosen % as your class!", "%"),
|
||||
LOBBY_CLASS_RANDOM("You will get a random class on arena start."),
|
||||
LOBBY_CLASS_PERMISSION("You don't have permission to use this class!", "No permission!", Material.FENCE),
|
||||
WARP_TO_ARENA("Can't warp to the arena during battle!"),
|
||||
WARP_FROM_ARENA("Warping not allowed in the arena!"),
|
||||
WAVE_DEFAULT("Wave #%!", "Wave #%!", Material.YELLOW_FLOWER),
|
||||
WAVE_SPECIAL("Wave #%! [SPECIAL]", "Wave #%! [SPECIAL]", Material.RED_ROSE),
|
||||
WAVE_SWARM("Wave #%! [SWARM]", "Wave #%! [SWARM]", Material.LONG_GRASS),
|
||||
WAVE_BOSS("Wave #%! [BOSS]", "Wave #%! [BOSS]", Material.FIRE),
|
||||
WAVE_BOSS_ABILITY("Boss used ability: %!", "Boss: %", Material.FIRE),
|
||||
WAVE_BOSS_LOW_HEALTH("Boss is almost dead!", "Boss almost dead!", Material.FIRE),
|
||||
WAVE_REWARD("You just earned a reward: %", "Reward: %"),
|
||||
MISC_LIST_PLAYERS("Live players: %"),
|
||||
MISC_LIST_ARENAS("Available arenas: %"),
|
||||
MISC_COMMAND_NOT_ALLOWED("You can't use that command in the arena!"),
|
||||
MISC_NO_ACCESS("You don't have access to this command."),
|
||||
MISC_NONE("<none>");
|
||||
|
||||
private String msg, spoutMsg;
|
||||
private Material logo;
|
||||
|
||||
private Msg(String msg)
|
||||
{
|
||||
this(msg, null);
|
||||
}
|
||||
|
||||
// Populate the defaults map.
|
||||
static
|
||||
private Msg(String msg, String spoutMsg)
|
||||
{
|
||||
defaults.put(Msg.ARENA_START, "Let the slaughter begin!");
|
||||
defaults.put(Msg.ARENA_END, "Arena finished.");
|
||||
defaults.put(Msg.ARENA_DOES_NOT_EXIST, "That arena does not exist. Type /ma arenas for a list.");
|
||||
defaults.put(Msg.JOIN_NOT_ENABLED, "MobArena is not enabled.");
|
||||
defaults.put(Msg.JOIN_IN_OTHER_ARENA, "You are already in an arena! Leave that one first.");
|
||||
defaults.put(Msg.JOIN_ARENA_NOT_ENABLED, "This arena is not enabled.");
|
||||
defaults.put(Msg.JOIN_ARENA_NOT_SETUP, "This arena has not been set up yet.");
|
||||
defaults.put(Msg.JOIN_ARENA_PERMISSION, "You don't have permission to join this arena.");
|
||||
defaults.put(Msg.JOIN_FEE_REQUIRED, "Insufficient funds. Price: %");
|
||||
defaults.put(Msg.JOIN_FEE_PAID, "Price to join was: %");
|
||||
defaults.put(Msg.JOIN_ARENA_IS_RUNNING, "This arena is in already progress.");
|
||||
defaults.put(Msg.JOIN_ALREADY_PLAYING, "You are already playing!");
|
||||
defaults.put(Msg.JOIN_ARG_NEEDED, "You must specify an arena. Type /ma arenas for a list.");
|
||||
defaults.put(Msg.JOIN_TOO_FAR, "You are too far away from the arena to join/spectate.");
|
||||
defaults.put(Msg.JOIN_EMPTY_INV, "You must empty your inventory to join the arena.");
|
||||
defaults.put(Msg.JOIN_PLAYER_LIMIT_REACHED, "The player limit of this arena has been reached.");
|
||||
defaults.put(Msg.JOIN_STORE_INV_FAIL, "Failed to store inventory. Try again.");
|
||||
defaults.put(Msg.JOIN_PLAYER_JOINED, "You joined the arena. Have fun!");
|
||||
defaults.put(Msg.LEAVE_NOT_PLAYING, "You are not in the arena.");
|
||||
defaults.put(Msg.LEAVE_PLAYER_LEFT, "You left the arena. Thanks for playing!");
|
||||
defaults.put(Msg.PLAYER_DIED, "% died!");
|
||||
defaults.put(Msg.SPEC_PLAYER_SPECTATE, "Enjoy the show!");
|
||||
defaults.put(Msg.SPEC_NOT_RUNNING, "This arena isn't running.");
|
||||
defaults.put(Msg.SPEC_ARG_NEEDED, "You must specify an arena. Type /ma arenas for a list.");
|
||||
defaults.put(Msg.SPEC_EMPTY_INV, "Empty your inventory first!");
|
||||
defaults.put(Msg.SPEC_ALREADY_PLAYING, "Can't spectate when in the arena!");
|
||||
defaults.put(Msg.NOT_READY_PLAYERS, "Not ready: %");
|
||||
defaults.put(Msg.FORCE_START_RUNNING, "Arena has already started.");
|
||||
defaults.put(Msg.FORCE_START_NOT_READY, "Can't force start, no players are ready.");
|
||||
defaults.put(Msg.FORCE_START_STARTED, "Forced arena start.");
|
||||
defaults.put(Msg.FORCE_END_EMPTY, "No one is in the arena.");
|
||||
defaults.put(Msg.FORCE_END_ENDED, "Forced arena end.");
|
||||
defaults.put(Msg.FORCE_END_IDLE, "You weren't quick enough!");
|
||||
defaults.put(Msg.REWARDS_GIVE, "Here are all of your rewards!");
|
||||
defaults.put(Msg.LOBBY_DROP_ITEM, "No sharing allowed at this time!");
|
||||
defaults.put(Msg.LOBBY_PLAYER_READY, "You have been flagged as ready!");
|
||||
defaults.put(Msg.LOBBY_PICK_CLASS, "You must first pick a class!");
|
||||
defaults.put(Msg.LOBBY_NOT_ENOUGH_PLAYERS, "Not enough players to start. Need at least % players.");
|
||||
defaults.put(Msg.LOBBY_RIGHT_CLICK, "Punch the sign. Don't right-click.");
|
||||
defaults.put(Msg.LOBBY_CLASS_PICKED, "You have chosen % as your class!");
|
||||
defaults.put(Msg.LOBBY_CLASS_RANDOM, "You will get a random class on arena start.");
|
||||
defaults.put(Msg.LOBBY_CLASS_PERMISSION, "You don't have permission to use this class!");
|
||||
defaults.put(Msg.WARP_TO_ARENA, "Can't warp to the arena during battle!");
|
||||
defaults.put(Msg.WARP_FROM_ARENA, "Warping not allowed in the arena!");
|
||||
defaults.put(Msg.WAVE_DEFAULT, "Get ready for wave #%!");
|
||||
defaults.put(Msg.WAVE_SPECIAL, "Get ready for wave #%! [SPECIAL]");
|
||||
defaults.put(Msg.WAVE_REWARD, "You just earned a reward: %");
|
||||
defaults.put(Msg.MISC_LIST_PLAYERS, "Live players: %");
|
||||
defaults.put(Msg.MISC_LIST_ARENAS, "Available arenas: %");
|
||||
defaults.put(Msg.MISC_COMMAND_NOT_ALLOWED, "You can't use that command in the arena!");
|
||||
defaults.put(Msg.MISC_NO_ACCESS, "You don't have access to this command.");
|
||||
defaults.put(Msg.MISC_NONE, "<none>");
|
||||
this(msg, spoutMsg, null);
|
||||
}
|
||||
|
||||
private Msg(String msg, String spoutMsg, Material logo)
|
||||
{
|
||||
this.msg = msg;
|
||||
this.spoutMsg = spoutMsg;
|
||||
this.logo = logo;
|
||||
}
|
||||
|
||||
public String get()
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
|
||||
public String get(String s)
|
||||
{
|
||||
return (s != null) ? msg.replace("%", s) : msg;
|
||||
}
|
||||
|
||||
public String getSpout(String s)
|
||||
{
|
||||
if (spoutMsg == null)
|
||||
return get(s);
|
||||
|
||||
return (s != null) ? spoutMsg.replace("%", s) : spoutMsg;
|
||||
}
|
||||
|
||||
public void set(String msg)
|
||||
{
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public void setSpout(String spoutMsg)
|
||||
{
|
||||
this.spoutMsg = spoutMsg;
|
||||
|
||||
if (spoutMsg == null)
|
||||
logo = null;
|
||||
}
|
||||
|
||||
public boolean hasSpoutMsg()
|
||||
{
|
||||
return spoutMsg != null;
|
||||
}
|
||||
|
||||
public Material getLogo()
|
||||
{
|
||||
return logo == null ? Material.SLIME_BALL : logo;
|
||||
}
|
||||
|
||||
public static String get(Msg m)
|
||||
{
|
||||
return m.msg;
|
||||
}
|
||||
|
||||
public static String get(Msg m, String s)
|
||||
{
|
||||
return m.msg.replace("%", s);
|
||||
}
|
||||
|
||||
public static void set(Msg m, String msg)
|
||||
{
|
||||
m.msg = msg;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the msgMap by reading from the announcements-file.
|
||||
*/
|
||||
public static void init(MobArena plugin, boolean update)
|
||||
public static void init(MobArena plugin)
|
||||
{
|
||||
// Use defaults in case of any errors.
|
||||
msgMap = defaults;
|
||||
|
||||
// Grab the announcements-file.
|
||||
File msgFile;
|
||||
try
|
||||
{
|
||||
msgFile = new File(plugin.getDataFolder(), "announcements.properties");
|
||||
File msgFile = new File(MobArena.dir, "announcements.properties");
|
||||
|
||||
// If it doesn't exist, create it.
|
||||
// If the file doesn't exist, create it and use defaults.
|
||||
if (!msgFile.exists())
|
||||
{
|
||||
System.out.println("[MobArena] Announcements-file not found. Creating one...");
|
||||
try
|
||||
{
|
||||
msgFile.createNewFile();
|
||||
|
||||
BufferedWriter bw = new BufferedWriter(new FileWriter(msgFile));
|
||||
|
||||
for (Msg m : Msg.values())
|
||||
{
|
||||
bw.write(m.toString() + "=" + defaults.get(m));
|
||||
if (m.hasSpoutMsg())
|
||||
bw.write(m.name() + "=" + m.msg + "|" + m.spoutMsg);
|
||||
else
|
||||
bw.write(m.name() + "=" + m.msg);
|
||||
|
||||
bw.newLine();
|
||||
}
|
||||
bw.close();
|
||||
|
||||
bw.close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("[MobArena] ERROR! Couldn't initialize announcements-file. Using defaults.");
|
||||
MobArena.warning("Couldn't initialize announcements-file. Using defaults.");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If the file was found, populate the msgMap.
|
||||
// Otherwise, read the file's contents.
|
||||
try
|
||||
{
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(msgFile), "UTF-8"));
|
||||
@@ -181,65 +209,45 @@ public class MAMessages
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
System.out.println("[MobArena] ERROR! Problem with announcements-file. Using defaults.");
|
||||
MobArena.warning("Problem with announcements-file. Using defaults.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void init(MobArena plugin)
|
||||
{
|
||||
init(plugin, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the announcement from the msgMap, and in case of
|
||||
* s not being null, replaces the % with s.
|
||||
*/
|
||||
public static String get(Msg msg, String s)
|
||||
{
|
||||
// If p is null, just return the announcement as is.
|
||||
if (s == null)
|
||||
return msgMap.get(msg);
|
||||
|
||||
// Otherwise, replace the % with the input string.
|
||||
return msgMap.get(msg).replace("%", s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the announcement from the msgMap.
|
||||
*/
|
||||
public static String get(Msg msg)
|
||||
{
|
||||
return get(msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper-method for parsing the strings from the
|
||||
* announcements-file.
|
||||
*/
|
||||
private static void process(String s)
|
||||
{
|
||||
// If the line ends with =, just add a space
|
||||
if (s.endsWith("=") || s.endsWith("|")) s += " ";
|
||||
|
||||
// Split the string by the equals-sign.
|
||||
String[] split = s.split("=");
|
||||
if (split.length != 2)
|
||||
{
|
||||
System.out.println("[MobArena] ERROR! Couldn't parse \"" + s + "\". Check announcements-file.");
|
||||
MobArena.warning("Couldn't parse \"" + s + "\". Check announcements-file.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Split the value by the pipe-sign.
|
||||
String[] vals = split[1].split("\\|");
|
||||
|
||||
// For simplicity...
|
||||
String key = split[0];
|
||||
String val = split[1];
|
||||
Msg msg;
|
||||
String val = vals.length == 2 ? vals[0] : split[1];
|
||||
String spoutVal = vals.length == 2 ? vals[1] : null;
|
||||
|
||||
try
|
||||
{
|
||||
msg = Msg.valueOf(key);
|
||||
msgMap.put(msg, val);
|
||||
Msg msg = Msg.valueOf(key);
|
||||
msg.set(val);
|
||||
msg.setSpout(spoutVal);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("[MobArena] ERROR! " + key + " is not a valid key. Check announcements-file.");
|
||||
MobArena.warning(key + " is not a valid key. Check announcements-file.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.garbagemule.MobArena;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
@@ -12,6 +13,7 @@ import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
|
||||
public class MAPlayerListener extends PlayerListener
|
||||
{
|
||||
private MobArena plugin;
|
||||
@@ -23,6 +25,13 @@ public class MAPlayerListener extends PlayerListener
|
||||
this.am = am;
|
||||
}
|
||||
|
||||
public void onPlayerAnimation(PlayerAnimationEvent event)
|
||||
{
|
||||
if (!am.enabled) return;
|
||||
for (Arena arena : am.arenas)
|
||||
arena.eventListener.onPlayerAnimation(event);
|
||||
}
|
||||
|
||||
public void onPlayerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if (!am.enabled) return;
|
||||
@@ -82,6 +91,6 @@ public class MAPlayerListener extends PlayerListener
|
||||
{
|
||||
MAUtils.checkForUpdates(plugin, p, false);
|
||||
}
|
||||
}, 100);
|
||||
}, 60);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,23 @@
|
||||
package com.garbagemule.MobArena;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.entity.Ghast;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.CreatureType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.garbagemule.MobArena.MAMessages.Msg;
|
||||
import com.garbagemule.MobArena.util.WaveUtils;
|
||||
import com.garbagemule.MobArena.waves.Wave;
|
||||
|
||||
/**
|
||||
* Core class for handling wave spawning.
|
||||
@@ -30,100 +27,155 @@ import com.garbagemule.MobArena.MAMessages.Msg;
|
||||
* host chooses. It is possible to create default waves that consist of
|
||||
* only one type of monster, or ones that have no creepers, for example.
|
||||
*/
|
||||
// TODO: Allow custom special wave monsters.
|
||||
// TODO: Allow additional "default" waves.
|
||||
public class MASpawnThread implements Runnable
|
||||
{
|
||||
protected int wave, previousSize, taskId;
|
||||
private int ran, noOfPlayers, modulo;
|
||||
private int dZombies, dSkeletons, dSpiders, dCreepers, dWolves;
|
||||
private int dPoweredCreepers, dPigZombies, dSlimes, dMonsters, dAngryWolves, dGiants, dGhasts;
|
||||
private Random random;
|
||||
private MobArena plugin;
|
||||
private Arena arena;
|
||||
private int wave, taskId, previousSize, playerCount;
|
||||
|
||||
// NEW WAVES
|
||||
private Wave defaultWave;
|
||||
private TreeSet<Wave> recurrentWaves;
|
||||
private TreeSet<Wave> singleWaves;
|
||||
|
||||
public MASpawnThread(MobArena plugin, Arena arena)
|
||||
{
|
||||
// WAVES
|
||||
defaultWave = arena.recurrentWaves.first();
|
||||
recurrentWaves = arena.recurrentWaves;
|
||||
singleWaves = new TreeSet<Wave>(arena.singleWaves);
|
||||
|
||||
this.plugin = plugin;
|
||||
this.arena = arena;
|
||||
modulo = arena.specialModulo;
|
||||
if (modulo <= 0) modulo = -32768;
|
||||
|
||||
taskId = -32768;
|
||||
|
||||
noOfPlayers = arena.arenaPlayers.size();
|
||||
wave = 1;
|
||||
random = new Random();
|
||||
|
||||
// Set up the distribution variables for the random spawner.
|
||||
// Note: Updating these means MAUtils.getArenaDistributions() must also be updated!
|
||||
dZombies = arena.distDefault.get("zombies");
|
||||
dSkeletons = dZombies + arena.distDefault.get("skeletons");
|
||||
dSpiders = dSkeletons + arena.distDefault.get("spiders");
|
||||
dCreepers = dSpiders + arena.distDefault.get("creepers");
|
||||
dWolves = dCreepers + arena.distDefault.get("wolves");
|
||||
if (dWolves < 1) { dZombies = 1; dSkeletons = 2; dSpiders = 3; dCreepers = 4; dWolves = 5; }
|
||||
|
||||
dPoweredCreepers = arena.distSpecial.get("powered-creepers");
|
||||
dPigZombies = dPoweredCreepers + arena.distSpecial.get("zombie-pigmen");
|
||||
dSlimes = dPigZombies + arena.distSpecial.get("slimes");
|
||||
dMonsters = dSlimes + arena.distSpecial.get("humans");
|
||||
dAngryWolves = dMonsters + arena.distSpecial.get("angry-wolves");
|
||||
dGiants = dAngryWolves + arena.distSpecial.get("giants");
|
||||
dGhasts = dGiants + arena.distSpecial.get("ghasts");
|
||||
if (dGhasts < 1) { dPoweredCreepers = 1; dPigZombies = 2; dSlimes = 3; dMonsters = 4; dAngryWolves = 5; dGiants = 5; dGhasts = 5; }
|
||||
playerCount = arena.arenaPlayers.size();
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
// Clear out all dead monsters in the monster set.
|
||||
removeDeadMonsters();
|
||||
|
||||
// If there are no players in the arena, return.
|
||||
if (arena.arenaPlayers.isEmpty())
|
||||
return;
|
||||
|
||||
List<Entity> tmp = new LinkedList<Entity>(arena.monsters);
|
||||
for (Entity e : tmp)
|
||||
if (e.isDead())
|
||||
arena.monsters.remove(e);
|
||||
|
||||
// Check if wave needs to be cleared first. If so, return!
|
||||
if (arena.waveClear && wave > 1)
|
||||
{
|
||||
if (!arena.monsters.isEmpty())
|
||||
if (arena.waveClear && wave > 1 && !arena.monsters.isEmpty())
|
||||
return;
|
||||
|
||||
// Check if we're on a boss wave
|
||||
if (!arena.waveClear && arena.bossWave != null)
|
||||
return;
|
||||
|
||||
// Grant rewards (if any) for this wave
|
||||
grantRewards(wave);
|
||||
|
||||
// Detonate creepers if needed
|
||||
detonateCreepers(arena.detCreepers);
|
||||
|
||||
// Find the wave to spawn
|
||||
spawnWave(wave);
|
||||
|
||||
wave++;
|
||||
if (arena.monsters.isEmpty())
|
||||
arena.resetIdleTimer();
|
||||
}
|
||||
|
||||
// Check if we need to grant more rewards with the recurrent waves.
|
||||
private void removeDeadMonsters()
|
||||
{
|
||||
List<Entity> tmp = new LinkedList<Entity>(arena.monsters);
|
||||
for (Entity e : tmp)
|
||||
{
|
||||
if (e.isDead() || !arena.inRegion(e.getLocation()))
|
||||
{
|
||||
arena.monsters.remove(e);
|
||||
e.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void grantRewards(int wave)
|
||||
{
|
||||
for (Map.Entry<Integer,List<ItemStack>> entry : arena.everyWaveMap.entrySet())
|
||||
if (wave % entry.getKey() == 0)
|
||||
addReward(entry.getValue());
|
||||
|
||||
// Same deal, this time with the one-time waves.
|
||||
if (arena.afterWaveMap.containsKey(wave))
|
||||
addReward(arena.afterWaveMap.get(wave));
|
||||
}
|
||||
|
||||
// Check if this is a special wave.
|
||||
if (wave % modulo == 0)
|
||||
private void spawnWave(int wave)
|
||||
{
|
||||
MAUtils.tellAll(arena, MAMessages.get(Msg.WAVE_SPECIAL, ""+wave));
|
||||
detonateCreepers(arena.detCreepers);
|
||||
specialWave();
|
||||
Wave w = null;
|
||||
|
||||
// Notify listeners.
|
||||
for (MobArenaListener listener : plugin.getAM().listeners)
|
||||
listener.onSpecialWave(wave, wave/modulo);
|
||||
// Check the first element of the single waves.
|
||||
if (!singleWaves.isEmpty() && singleWaves.first().matches(wave))
|
||||
{
|
||||
w = singleWaves.pollFirst();
|
||||
}
|
||||
else
|
||||
{
|
||||
MAUtils.tellAll(arena, MAMessages.get(Msg.WAVE_DEFAULT, ""+wave));
|
||||
detonateCreepers(arena.detCreepers);
|
||||
defaultWave();
|
||||
SortedSet<Wave> matches = getMatchingRecurrentWaves(wave);
|
||||
w = matches.isEmpty() ? defaultWave : matches.last();
|
||||
}
|
||||
|
||||
// Notify listeners.
|
||||
for (MobArenaListener listener : plugin.getAM().listeners)
|
||||
listener.onDefaultWave(wave);
|
||||
listener.onWave(arena, wave, w.getName(), w.getBranch(), w.getType());
|
||||
|
||||
w.spawn(wave);
|
||||
}
|
||||
|
||||
wave++;
|
||||
if (arena.maxIdleTime > 0 && arena.monsters.isEmpty()) arena.resetIdleTimer();
|
||||
private SortedSet<Wave> getMatchingRecurrentWaves(int wave)
|
||||
{
|
||||
TreeSet<Wave> result = new TreeSet<Wave>(WaveUtils.getRecurrentComparator());
|
||||
|
||||
for (Wave w : recurrentWaves)
|
||||
{
|
||||
if (w.matches(wave))
|
||||
result.add(w);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Getters/setters
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
public int getWave()
|
||||
{
|
||||
return wave;
|
||||
}
|
||||
|
||||
public int getTaskId()
|
||||
{
|
||||
return taskId;
|
||||
}
|
||||
|
||||
public int getPreviousSize()
|
||||
{
|
||||
return previousSize;
|
||||
}
|
||||
|
||||
public int getPlayerCount()
|
||||
{
|
||||
return playerCount;
|
||||
}
|
||||
|
||||
public void setTaskId(int taskId)
|
||||
{
|
||||
this.taskId = taskId;
|
||||
}
|
||||
|
||||
public void setPreviousSize(int previousSize)
|
||||
{
|
||||
this.previousSize = previousSize;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,158 +185,30 @@ public class MASpawnThread implements Runnable
|
||||
{
|
||||
for (Player p : arena.arenaPlayers)
|
||||
{
|
||||
if (arena.rewardMap.get(p) == null)
|
||||
if (arena.log.players.get(p) == null)
|
||||
continue;
|
||||
|
||||
ItemStack reward = MAUtils.getRandomReward(rewards);
|
||||
arena.rewardMap.get(p).add(reward);
|
||||
arena.log.players.get(p).rewards.add(reward);
|
||||
|
||||
if (reward == null)
|
||||
{
|
||||
MAUtils.tellPlayer(p, "ERROR! Problem with economy rewards. Notify server host!");
|
||||
System.out.println("[MobArena] ERROR! Could not add null reward. Please check the config-file!");
|
||||
MobArena.warning("Could not add null reward. Please check the config-file!");
|
||||
}
|
||||
else if (reward.getTypeId() == MobArena.ECONOMY_MONEY_ID)
|
||||
{
|
||||
if (plugin.Methods.hasMethod())
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.WAVE_REWARD, plugin.Method.format(reward.getAmount())));
|
||||
else System.out.println("[MobArena] ERROR! No economy plugin detected!");
|
||||
MAUtils.tellPlayer(p, Msg.WAVE_REWARD, plugin.Method.format(reward.getAmount()));
|
||||
else MobArena.warning("Tried to add money, but no economy plugin detected!");
|
||||
}
|
||||
else
|
||||
{
|
||||
MAUtils.tellPlayer(p, MAMessages.get(Msg.WAVE_REWARD, MAUtils.toCamelCase(reward.getType().toString()) + ":" + reward.getAmount()));
|
||||
MAUtils.tellPlayer(p, Msg.WAVE_REWARD, MAUtils.toCamelCase(reward.getType().toString()) + ":" + reward.getAmount(), reward.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns a default wave of monsters.
|
||||
*/
|
||||
private void defaultWave()
|
||||
{
|
||||
Location loc;
|
||||
List<Location> spawnpoints = getValidSpawnpoints();
|
||||
int noOfSpawnpoints = spawnpoints.size();
|
||||
int count = wave + noOfPlayers;
|
||||
CreatureType mob;
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
loc = spawnpoints.get(i % noOfSpawnpoints);
|
||||
ran = random.nextInt(dWolves);
|
||||
|
||||
/* Because of the nature of the if-elseif-else statement,
|
||||
* we're able to evaluate the random number in this way.
|
||||
* If dSpiders = 0, then dSpiders = dSkeletons, which
|
||||
* means if the random number is below that value, we will
|
||||
* spawn a skeleton and break out of the statement. */
|
||||
if (ran < dZombies) mob = CreatureType.ZOMBIE;
|
||||
else if (ran < dSkeletons) mob = CreatureType.SKELETON;
|
||||
else if (ran < dSpiders) mob = CreatureType.SPIDER;
|
||||
else if (ran < dCreepers) mob = CreatureType.CREEPER;
|
||||
else if (ran < dWolves) mob = CreatureType.WOLF;
|
||||
else continue;
|
||||
|
||||
LivingEntity e = arena.world.spawnCreature(loc,mob);
|
||||
arena.monsters.add(e);
|
||||
|
||||
if (mob == CreatureType.WOLF)
|
||||
((Wolf)e).setOwner(null);
|
||||
|
||||
// Grab a random target.
|
||||
Creature c = (Creature) e;
|
||||
c.setTarget(getClosestPlayer(e));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns a special wave of monsters.
|
||||
*/
|
||||
private void specialWave()
|
||||
{
|
||||
Location loc;
|
||||
List<Location> spawnpoints = getValidSpawnpoints();
|
||||
int noOfSpawnpoints = spawnpoints.size();
|
||||
CreatureType mob;
|
||||
ran = random.nextInt(dGhasts);
|
||||
|
||||
int count;
|
||||
boolean slime = false;
|
||||
boolean wolf = false;
|
||||
boolean ghast = false;
|
||||
boolean creeper = false;
|
||||
|
||||
if (ran < dPoweredCreepers) mob = CreatureType.CREEPER;
|
||||
else if (ran < dPigZombies) mob = CreatureType.PIG_ZOMBIE;
|
||||
else if (ran < dSlimes) mob = CreatureType.SLIME;
|
||||
else if (ran < dMonsters) mob = CreatureType.MONSTER;
|
||||
else if (ran < dAngryWolves) mob = CreatureType.WOLF;
|
||||
else if (ran < dGiants) mob = CreatureType.GIANT;
|
||||
else if (ran < dGhasts) mob = CreatureType.GHAST;
|
||||
else return;
|
||||
|
||||
switch(mob)
|
||||
{
|
||||
case CREEPER:
|
||||
count = noOfPlayers * 3;
|
||||
creeper = true;
|
||||
break;
|
||||
case PIG_ZOMBIE:
|
||||
count = noOfPlayers * 2;
|
||||
break;
|
||||
case SLIME:
|
||||
count = noOfPlayers * 4;
|
||||
slime = true;
|
||||
break;
|
||||
case MONSTER:
|
||||
count = noOfPlayers + 1;
|
||||
break;
|
||||
case WOLF:
|
||||
count = noOfPlayers * 3;
|
||||
wolf = true;
|
||||
break;
|
||||
case GIANT:
|
||||
count = 1;
|
||||
break;
|
||||
case GHAST:
|
||||
count = 2;
|
||||
ghast = true;
|
||||
break;
|
||||
default:
|
||||
count = 50;
|
||||
break;
|
||||
}
|
||||
|
||||
// Spawn the hippie monsters.
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
loc = spawnpoints.get(i % noOfSpawnpoints);
|
||||
|
||||
LivingEntity e = arena.world.spawnCreature(loc,mob);
|
||||
arena.monsters.add(e);
|
||||
|
||||
if (slime) ((Slime)e).setSize(2);
|
||||
if (wolf) { ((Wolf)e).setAngry(true); ((Wolf)e).setOwner(null); }
|
||||
if (ghast) ((Ghast)e).setHealth(Math.min(noOfPlayers*25, 200));
|
||||
if (creeper) ((Creeper)e).setPowered(true);
|
||||
|
||||
// Slimes can't have targets, apparently.
|
||||
if (!(e instanceof Creature))
|
||||
continue;
|
||||
|
||||
// Grab a random target.
|
||||
Creature c = (Creature) e;
|
||||
c.setTarget(getClosestPlayer(e));
|
||||
}
|
||||
|
||||
if (!arena.lightning)
|
||||
return;
|
||||
|
||||
// Lightning, just for effect ;)
|
||||
for (Location spawn : arena.spawnpoints.values())
|
||||
arena.world.strikeLightningEffect(spawn);
|
||||
}
|
||||
|
||||
/**
|
||||
* "Detonates" all the Creepers in the monsterSet.
|
||||
*/
|
||||
@@ -312,74 +236,6 @@ public class MASpawnThread implements Runnable
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the spawnpoints that have players nearby.
|
||||
*/
|
||||
public List<Location> getValidSpawnpoints()
|
||||
{
|
||||
List<Location> result = new ArrayList<Location>();
|
||||
|
||||
for (Location s : arena.spawnpoints.values())
|
||||
{
|
||||
//for (Player p : arena.livePlayers)
|
||||
for (Player p : arena.arenaPlayers)
|
||||
{
|
||||
if (!arena.world.equals(p.getWorld()))
|
||||
{
|
||||
System.out.println("[MobArena] MASpawnThread:291: Player '" + p.getName() + "' is not in the right world. Force leaving...");
|
||||
arena.playerLeave(p);
|
||||
MAUtils.tellPlayer(p, "You warped out of the arena world.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (s.distanceSquared(p.getLocation()) > MobArena.MIN_PLAYER_DISTANCE)
|
||||
continue;
|
||||
|
||||
result.add(s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If no players are in range, just use all the spawnpoints.
|
||||
if (result.isEmpty())
|
||||
result.addAll(arena.spawnpoints.values());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player closest to the input entity.
|
||||
*/
|
||||
// TODO: Move this into MAUtils
|
||||
public Player getClosestPlayer(Entity e)
|
||||
{
|
||||
// Set up the comparison variable and the result.
|
||||
double dist = 0;
|
||||
double current = Double.POSITIVE_INFINITY;
|
||||
Player result = null;
|
||||
|
||||
/* Iterate through the ArrayList, and update current and result every
|
||||
* time a squared distance smaller than current is found. */
|
||||
//for (Player p : arena.livePlayers)
|
||||
for (Player p : arena.arenaPlayers)
|
||||
{
|
||||
if (!arena.world.equals(p.getWorld()))
|
||||
{
|
||||
System.out.println("[MobArena] MASpawnThread:329: Player '" + p.getName() + "' is not in the right world. Force leaving...");
|
||||
arena.playerLeave(p);
|
||||
MAUtils.tellPlayer(p, "You warped out of the arena world.");
|
||||
continue;
|
||||
}
|
||||
dist = p.getLocation().distanceSquared(e.getLocation());
|
||||
if (dist < current && dist < MobArena.MIN_PLAYER_DISTANCE)
|
||||
{
|
||||
current = dist;
|
||||
result = p;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the targets of all monsters, if their targets aren't alive.
|
||||
*/
|
||||
@@ -399,7 +255,7 @@ public class MASpawnThread implements Runnable
|
||||
if (target instanceof Player && arena.arenaPlayers.contains(target))
|
||||
continue;
|
||||
|
||||
c.setTarget(getClosestPlayer(e));
|
||||
c.setTarget(MAUtils.getClosestPlayer(e, arena));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -15,6 +16,8 @@ import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.server.WorldServer;
|
||||
|
||||
@@ -33,8 +36,19 @@ import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import com.garbagemule.MobArena.MAMessages.Msg;
|
||||
import com.garbagemule.MobArena.util.EntityPosition;
|
||||
import com.garbagemule.MobArena.util.InventoryItem;
|
||||
import com.garbagemule.MobArena.util.jnbt.ByteTag;
|
||||
import com.garbagemule.MobArena.util.jnbt.CompoundTag;
|
||||
import com.garbagemule.MobArena.util.jnbt.ListTag;
|
||||
import com.garbagemule.MobArena.util.jnbt.NBTInputStream;
|
||||
import com.garbagemule.MobArena.util.jnbt.NBTOutputStream;
|
||||
import com.garbagemule.MobArena.util.jnbt.ShortTag;
|
||||
import com.garbagemule.MobArena.util.jnbt.Tag;
|
||||
|
||||
public class MAUtils
|
||||
{
|
||||
@@ -131,6 +145,20 @@ public class MAUtils
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////// */
|
||||
|
||||
public static Map<String,Location> getArenaContainers(Configuration config, World world, String arena)
|
||||
{
|
||||
Map<String,Location> containers = new HashMap<String,Location>();
|
||||
String arenaPath = "arenas." + arena + ".coords.containers";
|
||||
|
||||
if (config.getKeys(arenaPath) == null)
|
||||
return containers;
|
||||
|
||||
for (String point : config.getKeys(arenaPath))
|
||||
containers.put(point, makeLocation(world, config.getString(arenaPath + "." + point)));
|
||||
|
||||
return containers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab all the spawnpoints for a specific arena.
|
||||
*/
|
||||
@@ -250,55 +278,6 @@ public class MAUtils
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the distribution coefficients from the config-file. If
|
||||
* no coefficients are found, defaults (10) are added.
|
||||
*/
|
||||
public static Map<String,Integer> getArenaDistributions(Configuration config, String arena, String wave)
|
||||
{
|
||||
String arenaPath = "arenas." + arena + ".waves." + wave;
|
||||
Map<String,Integer> result = new HashMap<String,Integer>();
|
||||
List<String> dists = (config.getKeys(arenaPath) != null) ? config.getKeys(arenaPath) : new LinkedList<String>();
|
||||
|
||||
String[] monsters = (wave.equals("default")) ? new String[]{"zombies", "skeletons", "spiders", "creepers", "wolves"}
|
||||
: new String[]{"powered-creepers", "zombie-pigmen", "slimes", "humans", "angry-wolves", "giants", "ghasts"};
|
||||
boolean update = false;
|
||||
for (String monster : monsters)
|
||||
{
|
||||
if (dists.contains(monster))
|
||||
continue;
|
||||
|
||||
//if (config.getInt(arenaPath + "." + m, -1) == -1)
|
||||
config.setProperty(arenaPath + "." + monster, (monster.equals("giants") || monster.equals("ghasts")) ? 0 : 10);
|
||||
update = true;
|
||||
}
|
||||
|
||||
if (update)
|
||||
{
|
||||
config.save();
|
||||
dists = config.getKeys(arenaPath);
|
||||
}
|
||||
|
||||
for (String monster : dists)
|
||||
{
|
||||
int value = config.getInt(arenaPath + "." + monster, -1);
|
||||
|
||||
// If no distribution value was found, set one.
|
||||
if (value == -1)
|
||||
{
|
||||
value = 10;
|
||||
if (monster.equals("giant") || monster.equals("ghast"))
|
||||
value = 0;
|
||||
|
||||
config.setProperty(arenaPath + "." + monster, value);
|
||||
}
|
||||
config.save();
|
||||
|
||||
result.put(monster, value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<String> getAllowedCommands(Configuration config)
|
||||
{
|
||||
String commands = config.getString("global-settings.allowed-commands");
|
||||
@@ -320,7 +299,6 @@ public class MAUtils
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////// */
|
||||
|
||||
/* Clears the players inventory and armor slots. */
|
||||
public static PlayerInventory clearInventory(Player p)
|
||||
{
|
||||
PlayerInventory inv = p.getInventory();
|
||||
@@ -334,26 +312,28 @@ public class MAUtils
|
||||
|
||||
public static boolean storeInventory(Player p)
|
||||
{
|
||||
// Grab the contents.
|
||||
ItemStack[] armor = p.getInventory().getArmorContents();
|
||||
ItemStack[] items = p.getInventory().getContents();
|
||||
|
||||
// Set up the files and paths
|
||||
String invPath = "plugins" + sep + "MobArena" + sep + "inventories";
|
||||
new File(invPath).mkdir();
|
||||
File backupFile = new File(invPath + sep + p.getName() + ".inv");
|
||||
|
||||
try
|
||||
{
|
||||
// If a backup file already exists, restore the inventory first
|
||||
if (backupFile.exists() && !restoreInventory(p))
|
||||
return false;
|
||||
|
||||
// Grab the inventory contents.
|
||||
ItemStack[] items = p.getInventory().getContents();
|
||||
ItemStack[] armor = p.getInventory().getArmorContents();
|
||||
|
||||
try
|
||||
{
|
||||
backupFile.createNewFile();
|
||||
|
||||
MAInventoryItem[] inv = new MAInventoryItem[armor.length + items.length];
|
||||
for (int i = 0; i < armor.length; i++)
|
||||
inv[i] = stackToItem(armor[i]);
|
||||
InventoryItem[] inv = new InventoryItem[items.length + armor.length];
|
||||
for (int i = 0; i < items.length; i++)
|
||||
inv[armor.length + i] = stackToItem(items[i]);
|
||||
inv[i] = InventoryItem.parseItemStack(items[i]);
|
||||
for (int i = 0; i < armor.length; i++)
|
||||
inv[i + items.length] = InventoryItem.parseItemStack(armor[i]);
|
||||
|
||||
FileOutputStream fos = new FileOutputStream(backupFile);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||
@@ -363,7 +343,7 @@ public class MAUtils
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
System.out.println("[MobArena] ERROR! Could not create backup file for " + p.getName() + ".");
|
||||
MobArena.warning("Could not create backup file for " + p.getName() + ".");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -372,6 +352,33 @@ public class MAUtils
|
||||
}
|
||||
|
||||
public static boolean restoreInventory(Player p)
|
||||
{
|
||||
// Grab the items from the MobArena .inv file
|
||||
ItemStack[] stacks = getInventoryFile(p);
|
||||
|
||||
// If the player isn't online, hack the playerName.dat file
|
||||
if (!p.isOnline())
|
||||
return writeInventoryData(p, stacks);
|
||||
|
||||
// Otherwise, restore the inventory directly
|
||||
ItemStack[] items = new ItemStack[stacks.length-4];
|
||||
ItemStack[] armor = new ItemStack[4];
|
||||
|
||||
for (int i = 0; i < stacks.length - 4; i++)
|
||||
items[i] = stacks[i];
|
||||
for (int i = 0; i < 4; i++)
|
||||
armor[i] = stacks[stacks.length - 4 + i];
|
||||
|
||||
// Restore the inventory.
|
||||
PlayerInventory inv = p.getInventory();
|
||||
inv.setArmorContents(armor);
|
||||
for (int i = 0; i < items.length; i++)
|
||||
inv.setItem(i, items[i]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static ItemStack[] getInventoryFile(Player p)
|
||||
{
|
||||
String invPath = "plugins" + sep + "MobArena" + sep + "inventories";
|
||||
File backupFile = new File(invPath + sep + p.getName() + ".inv");
|
||||
@@ -380,55 +387,111 @@ public class MAUtils
|
||||
{
|
||||
// If the backup-file couldn't be found, return.
|
||||
if (!backupFile.exists())
|
||||
return false;
|
||||
return null;
|
||||
|
||||
// Grab the MAInventoryItem array from the backup-file.
|
||||
FileInputStream fis = new FileInputStream(backupFile);
|
||||
ObjectInputStream ois = new ObjectInputStream(fis);
|
||||
MAInventoryItem[] fromFile = (MAInventoryItem[]) ois.readObject();
|
||||
InventoryItem[] fromFile = (InventoryItem[]) ois.readObject();
|
||||
ois.close();
|
||||
|
||||
// Split that shit.
|
||||
ItemStack[] armor = new ItemStack[4];
|
||||
ItemStack[] items = new ItemStack[fromFile.length-4];
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
armor[i] = itemToStack(fromFile[i]);
|
||||
for (int i = 4; i < fromFile.length; i++)
|
||||
items[i - 4] = itemToStack(fromFile[i]);
|
||||
|
||||
// Restore the inventory.
|
||||
PlayerInventory inv = p.getInventory();
|
||||
inv.setArmorContents(armor);
|
||||
for (ItemStack stack : items)
|
||||
if (stack != null)
|
||||
inv.addItem(stack);
|
||||
|
||||
// Remove the backup-file.
|
||||
// Delete the file
|
||||
backupFile.delete();
|
||||
|
||||
return InventoryItem.toItemStacks(fromFile);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
System.out.println("[MobArena] ERROR! Could not restore inventory for " + p.getName());
|
||||
return false;
|
||||
MobArena.warning("Could not restore inventory for " + p.getName());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack[] readInventoryData(Player p)
|
||||
{
|
||||
// Grab the data dir <world>/players/
|
||||
File playerDir = new File(Bukkit.getServer().getWorlds().get(0).getName(), "players");
|
||||
|
||||
try
|
||||
{
|
||||
NBTInputStream in = new NBTInputStream(new FileInputStream(new File(playerDir, p.getName() + ".dat")));
|
||||
CompoundTag tag = (CompoundTag) in.readTag();
|
||||
in.close();
|
||||
|
||||
ListTag inventory = (ListTag) tag.getValue().get("Inventory");
|
||||
|
||||
ItemStack[] stacks = new ItemStack[40];
|
||||
for (int i = 0; i < inventory.getValue().size(); i++)
|
||||
{
|
||||
CompoundTag item = (CompoundTag) inventory.getValue().get(i);
|
||||
byte count = ((ByteTag) item.getValue().get("Count")).getValue();
|
||||
byte slot = ((ByteTag) item.getValue().get("Slot")).getValue();
|
||||
short damage = ((ShortTag) item.getValue().get("Damage")).getValue();
|
||||
short id = ((ShortTag) item.getValue().get("id")).getValue();
|
||||
stacks[slot < 36 ? slot : 36 + 103-slot] = new ItemStack(id, count, damage);
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
MobArena.warning("Could not restore inventory for " + p.getName());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean writeInventoryData(Player p, ItemStack[] stacks)
|
||||
{
|
||||
// Abort if stacks is null
|
||||
if (stacks == null) return false;
|
||||
|
||||
// Grab the data dir <world>/players/
|
||||
File playerDir = new File(Bukkit.getServer().getWorlds().get(0).getName(), "players");
|
||||
|
||||
try
|
||||
{
|
||||
NBTInputStream in = new NBTInputStream(new FileInputStream(new File(playerDir, p.getName() + ".dat")));
|
||||
CompoundTag tag = (CompoundTag) in.readTag();
|
||||
in.close();
|
||||
|
||||
ArrayList<Tag> tagList = new ArrayList<Tag>();
|
||||
|
||||
for (int i = 0; i < stacks.length; i++)
|
||||
{
|
||||
if (stacks[i] == null) continue;
|
||||
|
||||
ByteTag count = new ByteTag("Count", (byte) stacks[i].getAmount());
|
||||
ByteTag slot = new ByteTag("Slot", (byte) (i < 36 ? i : 104-(stacks.length-i)));
|
||||
ShortTag damage = new ShortTag("Damage", stacks[i].getDurability());
|
||||
ShortTag id = new ShortTag("id", (short) stacks[i].getTypeId());
|
||||
|
||||
HashMap<String, Tag> tagMap = new HashMap<String, Tag>();
|
||||
tagMap.put("Count", count);
|
||||
tagMap.put("Slot", slot);
|
||||
tagMap.put("Damage", damage);
|
||||
tagMap.put("id", id);
|
||||
|
||||
tagList.add(new CompoundTag("", tagMap));
|
||||
}
|
||||
|
||||
ListTag inventory = new ListTag("Inventory", CompoundTag.class, tagList);
|
||||
|
||||
HashMap<String, Tag> tagCompound = new HashMap<String, Tag>(tag.getValue());
|
||||
tagCompound.put("Inventory", inventory);
|
||||
tag = new CompoundTag("Player", tagCompound);
|
||||
|
||||
NBTOutputStream out = new NBTOutputStream(new FileOutputStream(new File(playerDir, p.getName() + ".dat")));
|
||||
out.writeTag(tag);
|
||||
out.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static MAInventoryItem stackToItem(ItemStack stack)
|
||||
catch (Exception e)
|
||||
{
|
||||
if (stack == null)
|
||||
return new MAInventoryItem(-1, -1, (short)0);
|
||||
return new MAInventoryItem(stack.getTypeId(), stack.getAmount(), stack.getDurability());
|
||||
e.printStackTrace();
|
||||
MobArena.warning("Could not restore inventory for " + p.getName());
|
||||
return false;
|
||||
}
|
||||
|
||||
private static ItemStack itemToStack(MAInventoryItem item)
|
||||
{
|
||||
if (item.getTypeId() == -1)
|
||||
return null;
|
||||
return new ItemStack(item.getTypeId(), item.getAmount(), item.getDurability());
|
||||
}
|
||||
|
||||
/* Checks if all inventory and armor slots are empty. */
|
||||
@@ -456,6 +519,25 @@ public class MAUtils
|
||||
if (stacks == null)
|
||||
return;
|
||||
|
||||
if (!p.isOnline())
|
||||
{
|
||||
ItemStack[] items = readInventoryData(p);
|
||||
int currentSlot = 0;
|
||||
for (ItemStack stack : stacks)
|
||||
{
|
||||
while (currentSlot < items.length && items[currentSlot] != null)
|
||||
currentSlot++;
|
||||
|
||||
if (currentSlot >= items.length)
|
||||
break;
|
||||
|
||||
items[currentSlot] = stack;
|
||||
}
|
||||
|
||||
writeInventoryData(p, items);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerInventory inv = p.getInventory();
|
||||
for (ItemStack stack : stacks)
|
||||
{
|
||||
@@ -474,7 +556,8 @@ public class MAUtils
|
||||
// If these are rewards, don't tamper with them.
|
||||
if (rewards)
|
||||
{
|
||||
inv.addItem(stack);
|
||||
//inv.addItem(stack);
|
||||
giveItem(inv, stack);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -489,19 +572,36 @@ public class MAUtils
|
||||
if (WEAPONS_TYPE.contains(stack.getType()))
|
||||
stack.setDurability((short) -32768);
|
||||
|
||||
inv.addItem(stack);
|
||||
giveItem(inv, stack);
|
||||
//inv.addItem(stack);
|
||||
}
|
||||
}
|
||||
public static void giveRewards(Player p, List<ItemStack> stacks, MobArena plugin)
|
||||
{
|
||||
giveItems(p, stacks, false, true, plugin);
|
||||
}
|
||||
|
||||
public static void giveItems(Player p, List<ItemStack> stacks, boolean autoEquip, MobArena plugin)
|
||||
{
|
||||
giveItems(p, stacks, autoEquip, false, plugin);
|
||||
}
|
||||
|
||||
public static void giveItem(PlayerInventory inv, ItemStack stack)
|
||||
{
|
||||
int id = stack.getTypeId();
|
||||
int amount = stack.getAmount();
|
||||
|
||||
int times = amount / 64;
|
||||
int remainder = amount % 64;
|
||||
|
||||
for (int i = 0; i < times; i++)
|
||||
inv.addItem(new ItemStack(id, 64));
|
||||
|
||||
if (remainder > 0)
|
||||
inv.addItem(new ItemStack(id, remainder));
|
||||
}
|
||||
|
||||
public static void giveRewards(Player p, List<ItemStack> stacks, MobArena plugin)
|
||||
{
|
||||
giveItems(p, stacks, false, true, plugin);
|
||||
}
|
||||
|
||||
public static int getPetAmount(Player p)
|
||||
{
|
||||
int result = 0;
|
||||
@@ -559,7 +659,7 @@ public class MAUtils
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("[MobArena] ERROR! Could not create item \"" + name + "\". Check config.yml");
|
||||
MobArena.warning("Could not create item \"" + name + "\". Check config.yml");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -592,10 +692,7 @@ public class MAUtils
|
||||
public static void sitPets(Player p)
|
||||
{
|
||||
if (p == null)
|
||||
{
|
||||
System.out.println("Player is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
List<Entity> entities = p.getNearbyEntities(80, 40, 80);
|
||||
for (Entity e : entities)
|
||||
@@ -609,18 +706,6 @@ public class MAUtils
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all the pets belonging to this player.
|
||||
*//*
|
||||
public static void clearPets(Arena arena, Player p)
|
||||
{
|
||||
for (Wolf w : arena.pets)
|
||||
{
|
||||
if (w.getOwner().equals(p))
|
||||
w.remove();
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
/* ///////////////////////////////////////////////////////////////////// //
|
||||
@@ -629,6 +714,20 @@ public class MAUtils
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////// */
|
||||
|
||||
/**
|
||||
* Check if a Location is inside two points (x1,y1,z1) (x2,y2,z2)
|
||||
*/
|
||||
public static boolean inRegion(Location loc, double x1, double y1, double z1, double x2, double y2, double z2)
|
||||
{
|
||||
double x = loc.getBlockX();
|
||||
double y = loc.getBlockY();
|
||||
double z = loc.getBlockZ();
|
||||
|
||||
return x >= x1 && x <= x2 &&
|
||||
y >= y1 && y <= y2 &&
|
||||
z >= z1 && z <= z2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a frame spanned by the two input coordinates.
|
||||
* @return An int arry holding x,y,z and the original type IDs of each block.
|
||||
@@ -780,6 +879,10 @@ public class MAUtils
|
||||
arena.p1.setY(arena.p2.getY());
|
||||
arena.p2.setY(tmp);
|
||||
}
|
||||
|
||||
if (!arena.world.getName().equals(world.getName()))
|
||||
arena.world = world;
|
||||
|
||||
arena.serializeConfig();
|
||||
arena.load(config);
|
||||
}
|
||||
@@ -885,23 +988,84 @@ public class MAUtils
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////// */
|
||||
|
||||
/**
|
||||
* Sends a message to a player.
|
||||
*/
|
||||
public static boolean tellSpoutPlayer(Player p, Msg msg, String s, Material logo)
|
||||
{
|
||||
// Grab the SpoutPlayer.
|
||||
SpoutPlayer sp = MobArena.hasSpout ? SpoutManager.getPlayer(p) : null;
|
||||
|
||||
if (msg.hasSpoutMsg() && sp != null && sp.isSpoutCraftEnabled())
|
||||
{
|
||||
// Grab the message text.
|
||||
String text = msg.getSpout(s);
|
||||
|
||||
// If more than 26 characters, truncate.
|
||||
if (text.length() > 26)
|
||||
text = text.substring(0, 26);
|
||||
|
||||
// If the logo is null, use an iron sword.
|
||||
if (logo == null)
|
||||
logo = msg.getLogo();
|
||||
|
||||
// Send the notification.
|
||||
sp.sendNotification("MobArena", text, logo, (short) 0, 2000);
|
||||
return true;
|
||||
}
|
||||
else return tellPlayer(p, msg.get(s));
|
||||
}
|
||||
|
||||
public static boolean tellSpoutPlayer(Player p, Msg msg, Material logo)
|
||||
{
|
||||
return tellSpoutPlayer(p, msg, null, logo);
|
||||
}
|
||||
|
||||
public static boolean tellSpoutPlayer(Player p, Msg msg, String s)
|
||||
{
|
||||
return tellSpoutPlayer(p, msg, s, null);
|
||||
}
|
||||
|
||||
public static boolean tellSpoutPlayer(Player p, Msg msg)
|
||||
{
|
||||
return tellSpoutPlayer(p, msg, null, null);
|
||||
}
|
||||
|
||||
public static boolean tellPlayer(CommandSender p, String msg)
|
||||
{
|
||||
if (p == null)
|
||||
// If the input sender is null or the string is empty, return.
|
||||
if (p == null || msg.equals(" "))
|
||||
return false;
|
||||
|
||||
// Otherwise, send the message with the [MobArena] tag.
|
||||
p.sendMessage(ChatColor.GREEN + "[MobArena] " + ChatColor.WHITE + msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean tellPlayer(CommandSender p, Msg msg, String s, boolean spout, Material logo)
|
||||
{
|
||||
if (spout && p instanceof Player)
|
||||
return tellSpoutPlayer((Player) p, msg, s, logo);
|
||||
|
||||
return tellPlayer(p, msg.get(s));
|
||||
}
|
||||
|
||||
public static boolean tellPlayer(CommandSender p, Msg msg, String s, Material logo)
|
||||
{
|
||||
return tellPlayer(p, msg, s, MobArena.hasSpout, logo);
|
||||
}
|
||||
|
||||
public static boolean tellPlayer(CommandSender p, Msg msg, String s)
|
||||
{
|
||||
return tellPlayer(p, msg, s, MobArena.hasSpout, null);
|
||||
}
|
||||
|
||||
public static boolean tellPlayer(CommandSender p, Msg msg)
|
||||
{
|
||||
return tellPlayer(p, msg, null, MobArena.hasSpout, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to all players in and around the arena.
|
||||
*/
|
||||
public static void tellAll(Arena arena, String msg) { tellAll(arena, msg, false); }
|
||||
public static void tellAll(Arena arena, String msg, boolean notifyPlayers)
|
||||
public static void tellAll(Arena arena, Msg msg, String s, boolean notifyPlayers)
|
||||
{
|
||||
Set<Player> tmp = new HashSet<Player>();
|
||||
tmp.addAll(arena.arenaPlayers);
|
||||
@@ -911,7 +1075,22 @@ public class MAUtils
|
||||
tmp.addAll(arena.specPlayers);
|
||||
if (notifyPlayers) tmp.addAll(arena.notifyPlayers);
|
||||
for (Player p : tmp)
|
||||
tellPlayer(p, msg);
|
||||
tellPlayer(p, msg, s);
|
||||
}
|
||||
|
||||
public static void tellAll(Arena arena, Msg msg, String s)
|
||||
{
|
||||
tellAll(arena, msg, s, false);
|
||||
}
|
||||
|
||||
public static void tellAll(Arena arena, Msg msg, boolean notifyPlayers)
|
||||
{
|
||||
tellAll(arena, msg, null, notifyPlayers);
|
||||
}
|
||||
|
||||
public static void tellAll(Arena arena, Msg msg)
|
||||
{
|
||||
tellAll(arena, msg, null, false);
|
||||
}
|
||||
|
||||
public static Player getClosestPlayer(Entity e, Arena arena)
|
||||
@@ -927,8 +1106,8 @@ public class MAUtils
|
||||
{
|
||||
if (!arena.world.equals(p.getWorld()))
|
||||
{
|
||||
System.out.println("[MobArena] MAUtils:908: Player '" + p.getName() + "' is not in the right world. Force leaving...");
|
||||
arena.playerLeave(p);
|
||||
MobArena.info("Player '" + p.getName() + "' is not in the right world. Kicking...");
|
||||
p.kickPlayer("[MobArena] Cheater! (Warped out of the arena world.)");
|
||||
tellPlayer(p, "You warped out of the arena world.");
|
||||
continue;
|
||||
}
|
||||
@@ -994,7 +1173,7 @@ public class MAUtils
|
||||
if (list == null || list.isEmpty())
|
||||
{
|
||||
if (none)
|
||||
return MAMessages.get(Msg.MISC_NONE);
|
||||
return Msg.MISC_NONE.get();
|
||||
else
|
||||
return "";
|
||||
}
|
||||
@@ -1045,6 +1224,7 @@ public class MAUtils
|
||||
return buffy.toString().substring(0, buffy.length() - trimLength);
|
||||
}
|
||||
public static <E> String listToString(List<E> list, MobArena plugin) { return listToString(list, true, plugin); }
|
||||
public static <E> String listToString(List<E> list) { return listToString(list, true, (MobArena) Bukkit.getServer().getPluginManager().getPlugin("MobArena")); }
|
||||
|
||||
/**
|
||||
* Returns a String-list version of a comma-separated list.
|
||||
@@ -1095,6 +1275,24 @@ public class MAUtils
|
||||
(arena.l2 != null));
|
||||
}
|
||||
|
||||
public static void checkData(Arena arena, CommandSender p)
|
||||
{
|
||||
if (arena.arenaLoc == null)
|
||||
tellPlayer(p, "Missing warp: arena");
|
||||
if (arena.lobbyLoc == null)
|
||||
tellPlayer(p, "Missing warp: lobby");
|
||||
if (arena.spectatorLoc == null)
|
||||
tellPlayer(p, "Missing warp: spectator");
|
||||
if (arena.p1 == null)
|
||||
tellPlayer(p, "Missing region point: p1");
|
||||
if (arena.p2 == null)
|
||||
tellPlayer(p, "Missing region point: p2");
|
||||
if (arena.spawnpoints.size() <= 0)
|
||||
tellPlayer(p, "Missing spawnpoints");
|
||||
if (arena.setup)
|
||||
tellPlayer(p, "Arena is ready to be used!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there is a new update of MobArena and notifies the
|
||||
* player if the boolean specified is true
|
||||
@@ -1109,6 +1307,7 @@ public class MAUtils
|
||||
|
||||
// Open the connection and don't redirect.
|
||||
HttpURLConnection con = (HttpURLConnection) baseURI.toURL().openConnection();
|
||||
con.setConnectTimeout(5000);
|
||||
con.setInstanceFollowRedirects(false);
|
||||
|
||||
String header = con.getHeaderField("Location");
|
||||
@@ -1123,18 +1322,27 @@ public class MAUtils
|
||||
// Otherwise, grab the location header to get the real URI.
|
||||
String url = new URI(con.getHeaderField("Location")).toString();
|
||||
|
||||
// If the current version is the same as the thread version.
|
||||
if (url.contains(plugin.getDescription().getVersion().replace(".", "-")))
|
||||
{
|
||||
if (!response)
|
||||
// Set up the regex and matcher
|
||||
Pattern regex = Pattern.compile("v([0-9]+-)*[0-9]+");
|
||||
Matcher matcher = regex.matcher(url);
|
||||
if (!matcher.find())
|
||||
return;
|
||||
|
||||
tellPlayer(p, "Your version of MobArena is up to date!");
|
||||
// Split the version strings
|
||||
String[] forumVersion = matcher.group().substring(1).split("-");
|
||||
String[] thisVersion = plugin.getDescription().getVersion().split("\\.");
|
||||
|
||||
// If the current version is older than the forum version, notify.
|
||||
for (int i = 0; i < Math.min(forumVersion.length, thisVersion.length); i++)
|
||||
{
|
||||
if (Integer.parseInt(forumVersion[i]) > Integer.parseInt(thisVersion[i]))
|
||||
{
|
||||
tellPlayer(p, "There is a new version of MobArena available!");;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, notify the player that there is a new version.
|
||||
tellPlayer(p, "There is a new version of MobArena available!");;
|
||||
if (response) tellPlayer(p, "Your version of MobArena is up to date!");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -1163,27 +1371,16 @@ public class MAUtils
|
||||
return hrs + ":" + ((mins < 10) ? "0" + mins : mins) + ":" + ((secs < 10) ? "0" + secs : secs);
|
||||
}
|
||||
|
||||
public static String padRight(String s, int length) { return padRight(s, length, ' '); }
|
||||
public static String padRight(String s, int length, char pad)
|
||||
public static long parseDuration(String duration)
|
||||
{
|
||||
StringBuffer buffy = new StringBuffer();
|
||||
buffy.append(s);
|
||||
for (int i = s.length(); i < length; i++)
|
||||
buffy.append(pad);
|
||||
return buffy.toString();
|
||||
}
|
||||
String[] elements = duration.split(":");
|
||||
long hrs = Long.parseLong(elements[0]) * 60 * 60;
|
||||
long mins = Long.parseLong(elements[1]) * 60;
|
||||
long secs = Long.parseLong(elements[2]);
|
||||
|
||||
public static String padLeft(String s, int length) { return padLeft(s, length, ' '); }
|
||||
public static String padLeft(String s, int length, char pad)
|
||||
{
|
||||
StringBuffer buffy = new StringBuffer();
|
||||
for (int i = 0; i < length - s.length(); i++)
|
||||
buffy.append(pad);
|
||||
buffy.append(s);
|
||||
return buffy.toString();
|
||||
return (hrs + mins + secs) * 1000;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stand back, I'm going to try science!
|
||||
*/
|
||||
@@ -1243,7 +1440,7 @@ public class MAUtils
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
System.out.println("[MobArena] ERROR! Couldn't create backup file. Aborting auto-generate...");
|
||||
MobArena.warning("Couldn't create backup file. Aborting auto-generate...");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1376,7 +1573,7 @@ public class MAUtils
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (error) System.out.println("[MobArena] ERROR! Couldn't find backup file for arena '" + name + "'");
|
||||
if (error) MobArena.warning("Couldn't find backup file for arena '" + name + "'");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.garbagemule.MobArena;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
@@ -16,14 +18,17 @@ import org.bukkit.util.config.Configuration;
|
||||
|
||||
import com.nijiko.permissions.PermissionHandler;
|
||||
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||
import com.garbagemule.MobArena.util.FileUtils;
|
||||
import com.garbagemule.register.payment.Method;
|
||||
import com.garbagemule.register.payment.Methods;
|
||||
//import com.garbagemule.ArenaPlugin.ArenaPlugin;
|
||||
//import com.garbagemule.ArenaPlugin.Master;
|
||||
|
||||
/**
|
||||
* MobArena
|
||||
* @author garbagemule
|
||||
*/
|
||||
public class MobArena extends JavaPlugin
|
||||
public class MobArena extends JavaPlugin// implements ArenaPlugin
|
||||
{
|
||||
private Configuration config;
|
||||
private ArenaMaster am;
|
||||
@@ -36,34 +41,74 @@ public class MobArena extends JavaPlugin
|
||||
protected Method Method;
|
||||
|
||||
// Global variables
|
||||
protected static final double MIN_PLAYER_DISTANCE = 256.0;
|
||||
protected static final int ECONOMY_MONEY_ID = -29;
|
||||
public static PluginDescriptionFile desc;
|
||||
public static File dir, arenaDir;
|
||||
public static final double MIN_PLAYER_DISTANCE = 15.0;
|
||||
public static final double MIN_PLAYER_DISTANCE_SQUARED = MIN_PLAYER_DISTANCE * MIN_PLAYER_DISTANCE;
|
||||
public static final int ECONOMY_MONEY_ID = -29;
|
||||
public static boolean hasSpout;
|
||||
public static Random random = new Random();
|
||||
|
||||
public void onEnable()
|
||||
{
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
// Description file and data folders
|
||||
desc = getDescription();
|
||||
dir = getDataFolder();
|
||||
arenaDir = new File(dir, "arenas");
|
||||
if (!dir.exists()) dir.mkdir();
|
||||
if (!arenaDir.exists()) arenaDir.mkdir();
|
||||
|
||||
// Config, messages and ArenaMaster initialization
|
||||
// Create default files and initialize config-file
|
||||
FileUtils.extractDefaults("config.yml");
|
||||
loadConfig();
|
||||
MAMessages.init(this);
|
||||
|
||||
// Download external libraries if needed.
|
||||
FileUtils.fetchLibs(config);
|
||||
|
||||
// Set up permissions and economy
|
||||
setupPermissions();
|
||||
setupRegister();
|
||||
setupSpout();
|
||||
|
||||
// Set up the ArenaMaster and the announcements
|
||||
am = new ArenaMaster(this);
|
||||
am.initialize();
|
||||
MAMessages.init(this);
|
||||
|
||||
// Permissions
|
||||
setupPermissions();
|
||||
// Register event listeners
|
||||
registerListeners();
|
||||
|
||||
// Economy
|
||||
Methods = new Methods();
|
||||
if (!Methods.hasMethod() && Methods.setMethod(this))
|
||||
{
|
||||
Method = Methods.getMethod();
|
||||
System.out.println("[MobArena] Payment method found (" + Method.getName() + " version: " + Method.getVersion() + ")");
|
||||
// Announce enable!
|
||||
info("v" + desc.getVersion() + " enabled.");
|
||||
}
|
||||
|
||||
// Bind the /ma, /marena, and /mobarena commands to MACommands.
|
||||
public void onDisable()
|
||||
{
|
||||
// Disable Spout features.
|
||||
hasSpout = false;
|
||||
|
||||
// Force all arenas to end.
|
||||
if (am == null) return;
|
||||
for (Arena arena : am.arenas)
|
||||
arena.forceEnd();
|
||||
am.arenaMap.clear();
|
||||
|
||||
info("disabled.");
|
||||
}
|
||||
|
||||
private void loadConfig()
|
||||
{
|
||||
File file = new File(dir, "config.yml");
|
||||
config = new Configuration(file);
|
||||
config.load();
|
||||
config.setHeader(getHeader());
|
||||
}
|
||||
|
||||
private void registerListeners()
|
||||
{
|
||||
// Bind the /ma, /mobarena commands to MACommands.
|
||||
MACommands commandExecutor = new MACommands(this, am);
|
||||
getCommand("ma").setExecutor(commandExecutor);
|
||||
getCommand("marena").setExecutor(commandExecutor);
|
||||
getCommand("mobarena").setExecutor(commandExecutor);
|
||||
|
||||
// Create event listeners.
|
||||
@@ -73,6 +118,11 @@ public class MobArena extends JavaPlugin
|
||||
BlockListener blockListener = new MABlockListener(am);
|
||||
|
||||
// Register events.
|
||||
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Highest, this);
|
||||
pm.registerEvent(Event.Type.BLOCK_BURN, blockListener, Priority.Highest, this);
|
||||
pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Priority.Highest, this);
|
||||
pm.registerEvent(Event.Type.BLOCK_PHYSICS, blockListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.BLOCK_IGNITE, blockListener, Priority.Highest, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_BUCKET_EMPTY, playerListener, Priority.Normal, this);
|
||||
@@ -80,8 +130,7 @@ public class MobArena extends JavaPlugin
|
||||
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_KICK, playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Highest, this);
|
||||
pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Priority.Highest, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_ANIMATION, playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Priority.High, this); // mcMMO is "Highest"
|
||||
pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Lowest, this); // Lowest because of Tombstone
|
||||
pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, entityListener, Priority.Normal, this);
|
||||
@@ -89,93 +138,28 @@ public class MobArena extends JavaPlugin
|
||||
pm.registerEvent(Event.Type.ENTITY_COMBUST, entityListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.ENTITY_TARGET, entityListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.CREATURE_SPAWN, entityListener, Priority.Highest, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Priority.Monitor, this);
|
||||
|
||||
System.out.println("[MobArena] v" + pdfFile.getVersion() + " enabled." );
|
||||
}
|
||||
|
||||
public void onDisable()
|
||||
{
|
||||
// Force all arenas to end.
|
||||
for (Arena arena : am.arenas)
|
||||
arena.forceEnd();
|
||||
am.arenaMap.clear();
|
||||
|
||||
// Permissions & Economy
|
||||
permissionHandler = null;
|
||||
if (Methods != null && Methods.hasMethod())
|
||||
{
|
||||
Methods = null;
|
||||
System.out.println("[MobArena] Payment method was disabled. No longer accepting payments.");
|
||||
}
|
||||
|
||||
System.out.println("[MobArena] disabled.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the config-file and initialize the Configuration object.
|
||||
*/
|
||||
private void loadConfig()
|
||||
{
|
||||
File file = new File(this.getDataFolder(), "config.yml");
|
||||
if (!file.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
this.getDataFolder().mkdir();
|
||||
file.createNewFile();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// TODO: Remove in v1.0
|
||||
else
|
||||
{
|
||||
Configuration tmp = new Configuration(file);
|
||||
tmp.load();
|
||||
if (tmp.getKeys("global-settings") == null)
|
||||
{
|
||||
file.renameTo(new File(this.getDataFolder(), "config_OLD.yml"));
|
||||
file = new File(this.getDataFolder(), "config.yml");
|
||||
try
|
||||
{
|
||||
this.getDataFolder().mkdir();
|
||||
file.createNewFile();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
config = new Configuration(file);
|
||||
config.load();
|
||||
fixConfig();
|
||||
config.setHeader("# MobArena Configuration-file\r\n# Please go to https://github.com/garbagemule/MobArena/wiki/Installing-MobArena for more details.");
|
||||
config.save();
|
||||
}
|
||||
}
|
||||
|
||||
config = new Configuration(file);
|
||||
config.load();
|
||||
config.setHeader("# MobArena Configuration-file\r\n# Please go to https://github.com/garbagemule/MobArena/wiki/Installing-MobArena for more details.");
|
||||
config.save();
|
||||
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Priority.Monitor, this); // I know Monitor is bad, but other plugins suck! :(
|
||||
}
|
||||
|
||||
// Permissions stuff
|
||||
public boolean has(Player p, String s)
|
||||
{
|
||||
//return (permissionHandler != null && permissionHandler.has(p, s));
|
||||
return (permissionHandler == null || permissionHandler.has(p, s));
|
||||
// First check for NijikoPerms
|
||||
if (permissionHandler != null)
|
||||
return permissionHandler.has(p, s);
|
||||
|
||||
// If the permission is set, check if player has permission
|
||||
if (p.isPermissionSet(s))
|
||||
return p.hasPermission(s);
|
||||
|
||||
// Otherwise, only allow commands that aren't admin/setup commands.
|
||||
return !s.matches("^.*\\.setup\\..*$") && !s.matches("^.*\\.admin\\..*$");
|
||||
}
|
||||
|
||||
public boolean hasDefTrue(Player p, String s)
|
||||
{
|
||||
return (permissionHandler == null || permissionHandler.has(p, s));
|
||||
}
|
||||
// Console printing
|
||||
public static void info(String msg) { Bukkit.getServer().getLogger().info("[MobArena] " + msg); }
|
||||
public static void warning(String msg) { Bukkit.getServer().getLogger().warning("[MobArena] " + msg); }
|
||||
public static void error(String msg) { Bukkit.getServer().getLogger().severe("[MobArena] " + msg); }
|
||||
|
||||
private void setupPermissions()
|
||||
{
|
||||
@@ -188,89 +172,34 @@ public class MobArena extends JavaPlugin
|
||||
permissionHandler = ((Permissions) permissionsPlugin).getHandler();
|
||||
}
|
||||
|
||||
private void setupRegister()
|
||||
{
|
||||
Methods = new Methods();
|
||||
if (!Methods.hasMethod() && Methods.setMethod(this))
|
||||
{
|
||||
Method = Methods.getMethod();
|
||||
info("Payment method found (" + Method.getName() + " version: " + Method.getVersion() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
private void setupSpout()
|
||||
{
|
||||
if (hasSpout)
|
||||
return;
|
||||
|
||||
Plugin spoutPlugin = this.getServer().getPluginManager().getPlugin("Spout");
|
||||
hasSpout = spoutPlugin != null;
|
||||
}
|
||||
|
||||
public Configuration getConfig() { return config; }
|
||||
public ArenaMaster getAM() { return am; } // More convenient.
|
||||
public ArenaMaster getArenaMaster() { return am; }
|
||||
|
||||
// TODO: Remove in v1.0
|
||||
private void fixConfig()
|
||||
private String getHeader()
|
||||
{
|
||||
// If global-settings is sorted, don't do anything.
|
||||
if (config.getKeys("global-settings") != null)
|
||||
return;
|
||||
|
||||
File oldFile = new File(this.getDataFolder(), "config_OLD.yml");
|
||||
if (!oldFile.exists())
|
||||
return;
|
||||
|
||||
System.out.println("[MobArena] Config-file appears to be old. Trying to fix it...");
|
||||
|
||||
Configuration oldConfig = new Configuration(oldFile);
|
||||
oldConfig.load();
|
||||
|
||||
config.setProperty("global-settings.enabled", true);
|
||||
config.save();
|
||||
config.load();
|
||||
config.setProperty("global-settings.update-notification", true);
|
||||
config.save();
|
||||
config.load();
|
||||
|
||||
// Copy classes
|
||||
for (String s : oldConfig.getKeys("classes"))
|
||||
{
|
||||
config.setProperty("classes." + s + ".items", oldConfig.getString("classes." + s + ".items"));
|
||||
config.setProperty("classes." + s + ".armor", oldConfig.getString("classes." + s + ".armor"));
|
||||
}
|
||||
config.save();
|
||||
|
||||
// Make the default arena node.
|
||||
config.setProperty("arenas.default.settings.enabled", true);
|
||||
config.save();
|
||||
config.load();
|
||||
config.setProperty("arenas.default.settings.world", oldConfig.getString("settings.world"));
|
||||
config.save();
|
||||
config.load();
|
||||
|
||||
// Copy the coords.
|
||||
for (String s : oldConfig.getKeys("coords"))
|
||||
{
|
||||
if (s.equals("spawnpoints"))
|
||||
continue;
|
||||
|
||||
StringBuffer buffy = new StringBuffer();
|
||||
buffy.append(oldConfig.getString("coords." + s + ".x"));
|
||||
buffy.append(",");
|
||||
buffy.append(oldConfig.getString("coords." + s + ".y"));
|
||||
buffy.append(",");
|
||||
buffy.append(oldConfig.getString("coords." + s + ".z"));
|
||||
buffy.append(",");
|
||||
buffy.append(oldConfig.getString("coords." + s + ".yaw"));
|
||||
buffy.append(",");
|
||||
buffy.append(oldConfig.getString("coords." + s + ".pitch"));
|
||||
|
||||
config.setProperty("arenas.default.coords." + s, buffy.toString());
|
||||
}
|
||||
config.save();
|
||||
config.load();
|
||||
|
||||
for (String s : oldConfig.getKeys("coords.spawnpoints"))
|
||||
{
|
||||
StringBuffer buffy = new StringBuffer();
|
||||
buffy.append(oldConfig.getString("coords.spawnpoints." + s + ".x"));
|
||||
buffy.append(",");
|
||||
buffy.append(oldConfig.getString("coords.spawnpoints." + s + ".y"));
|
||||
buffy.append(",");
|
||||
buffy.append(oldConfig.getString("coords.spawnpoints." + s + ".z"));
|
||||
buffy.append(",");
|
||||
buffy.append(oldConfig.getString("coords.spawnpoints." + s + ".yaw"));
|
||||
buffy.append(",");
|
||||
buffy.append(oldConfig.getString("coords.spawnpoints." + s + ".pitch"));
|
||||
|
||||
config.setProperty("arenas.default.coords.spawnpoints." + s, buffy.toString());
|
||||
}
|
||||
config.save();
|
||||
config.load();
|
||||
|
||||
System.out.println("[MobArena] Updated the config-file!");
|
||||
String sep = System.getProperty("line.separator");
|
||||
return "# MobArena v" + desc.getVersion() + " - Config-file" + sep +
|
||||
"# Read the Wiki for details on how to set up this file: http://goo.gl/F5TTc" + sep +
|
||||
"# Note: You -must- use spaces instead of tabs!";
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,12 @@ package com.garbagemule.MobArena;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class MobArenaHandler
|
||||
{
|
||||
MobArena plugin;
|
||||
boolean ma = false;
|
||||
private MobArena plugin;
|
||||
|
||||
/**
|
||||
* Primary constructor.
|
||||
@@ -17,26 +16,24 @@ public class MobArenaHandler
|
||||
*/
|
||||
public MobArenaHandler()
|
||||
{
|
||||
Plugin maPlugin = (MobArena) Bukkit.getServer().getPluginManager().getPlugin("MobArena");
|
||||
|
||||
if (maPlugin == null)
|
||||
return;
|
||||
|
||||
ma = true;
|
||||
plugin = (MobArena) maPlugin;
|
||||
plugin = (MobArena) Bukkit.getServer().getPluginManager().getPlugin("MobArena");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////
|
||||
|
||||
REGION/LOCATION METHODS
|
||||
|
||||
//////////////////////////////////////////////////////////////////*/
|
||||
|
||||
/**
|
||||
* Check if a Location is inside of an arena region.
|
||||
* Check if a Location is inside of any arena region.
|
||||
* @param loc A location.
|
||||
* @return true, if the Location is inside of any arena region.
|
||||
*/
|
||||
public boolean inRegion(Location loc)
|
||||
{
|
||||
// If the plugin doesn't exist, always return false.
|
||||
if (!ma || plugin.getAM() == null) return false;
|
||||
|
||||
// Return true if location is within just one arena's region.
|
||||
for (Arena arena : plugin.getAM().arenas)
|
||||
if (arena.inRegion(loc))
|
||||
return true;
|
||||
@@ -45,26 +42,50 @@ public class MobArenaHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a Location is inside of a specific arena region.
|
||||
* Check if a Location is inside of a specific arena region (by arena object).
|
||||
* @param arena An Arena object
|
||||
* @param loc A location
|
||||
* @return true, if the Location is inside of the arena region.
|
||||
*/
|
||||
public boolean inRegion(Arena arena, Location loc) { return (ma && arena != null && arena.inRegion(loc)); }
|
||||
public boolean inRegion(Arena arena, Location loc)
|
||||
{
|
||||
return (arena != null && arena.inRegion(loc));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a Location is inside of a specific arena region (by arena name).
|
||||
* @param arenaName The name of an arena
|
||||
* @param loc A location
|
||||
* @return true, if the Location is inside of the arena region.
|
||||
*/
|
||||
public boolean inRegion(String arenaName, Location loc)
|
||||
{
|
||||
Arena arena = plugin.getAM().getArenaWithName(arenaName);
|
||||
if (arena == null)
|
||||
throw new NullPointerException("There is no arena with that name");
|
||||
|
||||
return arena.inRegion(loc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a Location is inside of the region of an arena that is currently running.
|
||||
* @param loc A location.
|
||||
* @return true, if the Location is inside of the region of an arena that is currently running.
|
||||
*/
|
||||
public boolean inRunningRegion(Location loc) { return inRegion(loc, false, true); }
|
||||
public boolean inRunningRegion(Location loc)
|
||||
{
|
||||
return inRegion(loc, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a Location is inside of the region of an arena that is currently enabled.
|
||||
* @param loc A location.
|
||||
* @return true, if the Location is inside of the region of an arena that is currently enabled.
|
||||
*/
|
||||
public boolean inEnabledRegion(Location loc) { return inRegion(loc, true, false); }
|
||||
public boolean inEnabledRegion(Location loc)
|
||||
{
|
||||
return inRegion(loc, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Private helper method for inRunningRegion and inEnabledRegion
|
||||
@@ -76,7 +97,7 @@ public class MobArenaHandler
|
||||
private boolean inRegion(Location loc, boolean enabled, boolean running)
|
||||
{
|
||||
// If the plugin doesn't exist, always return false.
|
||||
if (!ma || plugin.getAM() == null) return false;
|
||||
if (plugin.getAM() == null) return false;
|
||||
|
||||
// Return true if location is within just one arena's region.
|
||||
for (Arena arena : plugin.getAM().arenas)
|
||||
@@ -87,40 +108,124 @@ public class MobArenaHandler
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////
|
||||
|
||||
PLAYER/MONSTER/PET METHODS
|
||||
|
||||
//////////////////////////////////////////////////////////////////*/
|
||||
|
||||
/**
|
||||
* Check if a player is in a MobArena arena (by Player).
|
||||
* @param player The player
|
||||
* @return true, if the player is in an arena
|
||||
*/
|
||||
public boolean isPlayerInArena(Player player)
|
||||
{
|
||||
return (plugin.getAM().getArenaWithPlayer(player) != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player is in a MobArena arena (by name).
|
||||
* @param playerName The name of the player
|
||||
* @return true, if the player is in an arena
|
||||
*/
|
||||
public boolean isPlayerInArena(String playerName)
|
||||
{
|
||||
return (plugin.getAM().getArenaWithPlayer(playerName) != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MobArena class of a given player.
|
||||
* @param player The player
|
||||
* @return The class name of the player if the player is in the arena, null otherwise
|
||||
*/
|
||||
public String getPlayerClass(Player player)
|
||||
{
|
||||
Arena arena = plugin.getAM().getArenaWithPlayer(player);
|
||||
if (arena == null) return null;
|
||||
|
||||
return arena.classMap.get(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MobArena class of a given player in a given arena.
|
||||
* This method is faster than the above method, granted the Arena object is known.
|
||||
* @param arena The MobArena arena to check in
|
||||
* @param player The player to look up
|
||||
* @return The class name of the player, if the player is in the arena, null otherwise
|
||||
*/
|
||||
public String getPlayerClass(Arena arena, Player player)
|
||||
{
|
||||
return arena.classMap.get(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a monster is in a MobArena arena.
|
||||
* @param entity The monster entity
|
||||
* @return true, if the monster is in an arena
|
||||
*/
|
||||
public boolean isMonsterInArena(LivingEntity entity)
|
||||
{
|
||||
return plugin.getAM().getArenaWithMonster(entity) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a pet is in a MobArena arena.
|
||||
* @param wolf The pet wolf
|
||||
* @return true, if the pet is in an arena
|
||||
*/
|
||||
public boolean isPetInArena(LivingEntity wolf)
|
||||
{
|
||||
return plugin.getAM().getArenaWithPet(wolf) != null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////
|
||||
|
||||
ARENA GETTERS
|
||||
|
||||
//////////////////////////////////////////////////////////////////*/
|
||||
|
||||
/**
|
||||
* Get an Arena object at the given location.
|
||||
* @param loc A location
|
||||
* @return an Arena object, or null
|
||||
*/
|
||||
public Arena getArenaAtLocation(Location loc) { return (ma) ? plugin.getAM().getArenaAtLocation(loc) : null; }
|
||||
public Arena getArenaAtLocation(Location loc)
|
||||
{
|
||||
return plugin.getAM().getArenaAtLocation(loc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Arena object that the given player is currently in.
|
||||
* @param p A player
|
||||
* @return an Arena object, or null
|
||||
*/
|
||||
public Arena getArenaWithPlayer(Player p) { return (ma) ? plugin.getAM().getArenaWithPlayer(p) : null; }
|
||||
public Arena getArenaWithPlayer(Player p)
|
||||
{
|
||||
return plugin.getAM().getArenaWithPlayer(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Arena object that the given pet is currently in.
|
||||
* @param wolf A pet wolf
|
||||
* @return an Arena object, or null
|
||||
*/
|
||||
public Arena getArenaWithPet(Entity wolf) { return (ma) ? plugin.getAM().getArenaWithPet(wolf) : null; }
|
||||
public Arena getArenaWithPet(Entity wolf)
|
||||
{
|
||||
return plugin.getAM().getArenaWithPet(wolf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Arena object that the given monster is currently in.
|
||||
* @param monster A monster
|
||||
* @return an Arena object, or null
|
||||
*/
|
||||
public Arena getArenaWithMonster(Entity monster) { return (ma) ? plugin.getAM().getArenaWithMonster(monster) : null; }
|
||||
|
||||
/**
|
||||
* Check if the server is running MobArena.
|
||||
* @return true, if MobArena exists on the server.
|
||||
*/
|
||||
public boolean hasMA()
|
||||
public Arena getArenaWithMonster(Entity monster)
|
||||
{
|
||||
return ma;
|
||||
return plugin.getAM().getArenaWithMonster(monster);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ package com.garbagemule.MobArena;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.garbagemule.MobArena.waves.Wave.WaveBranch;
|
||||
import com.garbagemule.MobArena.waves.Wave.WaveType;
|
||||
|
||||
public class MobArenaListener
|
||||
{
|
||||
protected MobArena plugin;
|
||||
@@ -13,11 +16,10 @@ public class MobArenaListener
|
||||
plugin.getAM().listeners.add(this);
|
||||
}
|
||||
|
||||
public void onArenaStart() {}
|
||||
public void onArenaEnd() {}
|
||||
public void onDefaultWave(int waveNumber) {}
|
||||
public void onSpecialWave(int waveNumber, int specialwaveNumber) {}
|
||||
public void onPlayerJoin(Player p) {}
|
||||
public void onPlayerLeave(Player p) {}
|
||||
public void onPlayerDeath(Player p) {}
|
||||
public void onArenaStart(Arena arena) {}
|
||||
public void onArenaEnd(Arena arena) {}
|
||||
public void onWave(Arena arena, int waveNumber, String waveName, WaveBranch waveBranch, WaveType waveType) {}
|
||||
public void onPlayerJoin(Arena arena, Player p) {}
|
||||
public void onPlayerLeave(Arena arena, Player p) {}
|
||||
public void onPlayerDeath(Arena arena, Player p) {}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.garbagemule.MobArena.repairable;
|
||||
|
||||
//import java.io.Serializable;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
public interface Repairable// extends Serializable
|
||||
{
|
||||
public void repair();
|
||||
|
||||
public BlockState getState();
|
||||
|
||||
public Material getType();
|
||||
public int getId();
|
||||
public byte getData();
|
||||
|
||||
public World getWorld();
|
||||
public int getX();
|
||||
public int getY();
|
||||
public int getZ();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.garbagemule.MobArena.repairable;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.material.Attachable;
|
||||
|
||||
public class RepairableAttachable extends RepairableBlock
|
||||
{
|
||||
private int x, y, z;
|
||||
|
||||
public RepairableAttachable(BlockState state)
|
||||
{
|
||||
super(state);
|
||||
|
||||
BlockState attached;
|
||||
if (state.getData() instanceof Attachable)
|
||||
attached = state.getBlock().getRelative(((Attachable) state.getData()).getAttachedFace()).getState();
|
||||
else
|
||||
attached = state.getBlock().getRelative(BlockFace.DOWN).getState();
|
||||
|
||||
x = attached.getX();
|
||||
y = attached.getY();
|
||||
z = attached.getZ();
|
||||
}
|
||||
|
||||
public void repair()
|
||||
{
|
||||
Block b = getWorld().getBlockAt(x,y,z);
|
||||
if (b.getTypeId() == 0)
|
||||
b.setTypeId(1);
|
||||
|
||||
super.repair();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.garbagemule.MobArena.repairable;
|
||||
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.material.Bed;
|
||||
|
||||
public class RepairableBed extends RepairableBlock
|
||||
{
|
||||
private BlockState other;
|
||||
|
||||
public RepairableBed(BlockState state)
|
||||
{
|
||||
super(state);
|
||||
other = state.getBlock().getRelative(((Bed) state.getData()).getFacing()).getState();
|
||||
}
|
||||
|
||||
public void repair()
|
||||
{
|
||||
if (getWorld().getBlockAt(getX(), getY(), getZ()).getState().getData() instanceof Bed)
|
||||
return;
|
||||
|
||||
super.repair();
|
||||
other.getBlock().setTypeIdAndData(getId(), (byte) (getData() + 8), false);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user