Skip to content

Commit

Permalink
Merge pull request #205 from net/master
Browse files Browse the repository at this point in the history
Merge Net's fork into the main repository
  • Loading branch information
net committed Jan 2, 2016
2 parents 3af3c96 + 1d04b7e commit f7a70c5
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 27 deletions.
13 changes: 7 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

<groupId>org.mctourney.autoreferee</groupId>
<artifactId>AutoReferee</artifactId>
<version>2.6-SNAPSHOT</version>
<version>2.8</version>
<name>AutoReferee Core Plugin</name>
<url>http://www.reddit.com/r/mctourney</url>
<url>https://www.reddit.com/r/mctourney</url>
<description>Bukkit plugin for automatically refereeing competitive Minecraft matches.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<bukkit.version>1.5.1-R0.2</bukkit.version>
<bukkit.version>1.8.8-R0.1-SNAPSHOT</bukkit.version>
<java.target.version>1.6</java.target.version>
</properties>

Expand All @@ -28,8 +28,8 @@

<repositories>
<repository>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public/</url>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sk89q-mvn2</id>
Expand Down Expand Up @@ -64,6 +64,7 @@
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>${bukkit.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
Expand Down Expand Up @@ -189,7 +190,7 @@
<configuration>
<mainClass>org.mctourney.autoreferee.AutoRefereeTools</mainClass>
<arguments>
<argument></argument>
<argument/>
</arguments>
</configuration>
</plugin>
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/mctourney/autoreferee/AutoRefMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,10 @@ public MatchStatus getCurrentState()
* @param status new match status
*/
public void setCurrentState(MatchStatus status)
{ this.currentState = status; this.setupSpectators(); }
{
this.currentState = status;
if (!status.isBeforeMatch()) this.setupSpectators();
}

// custom scoreboard
protected final Scoreboard scoreboard;
Expand Down Expand Up @@ -1691,7 +1694,7 @@ private void updateRefereePlayerInfo(Player ref, AutoRefPlayer apl)
Player pl = apl.getPlayer();
if (pl != null)
{
messageReferee(ref, "player", apl.getName(), "hp", Integer.toString(pl.getHealth()));
messageReferee(ref, "player", apl.getName(), "hp", Integer.toString((int) pl.getHealth()));
messageReferee(ref, "player", apl.getName(), "armor", Integer.toString(ArmorPoints.fromPlayer(pl)));
}

Expand Down Expand Up @@ -2337,6 +2340,13 @@ protected void _startMatch()
}
}

// reset enderchests and bed spawns
for (AutoRefPlayer apl : getPlayers()) {
Player player = apl.getPlayer();
PlayerUtil.clearEnderChest(player);
PlayerUtil.clearBedSpawn(player);
}

// set teams as started
for (AutoRefTeam team : getTeams())
team.startMatch();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/mctourney/autoreferee/AutoRefPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ public AutoRefPlayer(Player player, AutoRefTeam team)
this(player.getName(), team);

// setup base health and armor level
this.currentHealth = player.getHealth();
this.currentHealth = (int) player.getHealth();
this.currentArmor = ArmorPoints.fromPlayerInventory(player.getInventory());
}

Expand Down Expand Up @@ -908,7 +908,7 @@ public void updateHealthArmor()
Player player = this.getPlayer();
if (player == null) return;

int newHealth = Math.max(0, player.getHealth());
int newHealth = (int) Math.max(0, player.getHealth());
int newArmor = ArmorPoints.fromPlayerInventory(player.getInventory());

if (getTeam() != null) getTeam().updateHealthArmor(this,
Expand Down Expand Up @@ -1001,7 +1001,7 @@ public Inventory getInventoryView(String name)

// SLOT 8: PLAYER HEALTH
{
ItemStack health = new ItemStack(Material.APPLE, player.getHealth());
ItemStack health = new ItemStack(Material.APPLE, (int) player.getHealth());
ItemMeta meta = health.getItemMeta();

meta.setDisplayName(ChatColor.RED + "" + ChatColor.ITALIC + "Player Health");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.entity.minecart.CommandMinecart;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.Plugin;

import org.apache.commons.lang.StringUtils;

import org.mctourney.autoreferee.AutoRefMap;
import org.mctourney.autoreferee.AutoRefMatch;
import org.mctourney.autoreferee.AutoRefTeam;
Expand All @@ -24,7 +24,6 @@
import org.mctourney.autoreferee.util.commands.AutoRefCommand;
import org.mctourney.autoreferee.util.commands.AutoRefPermission;
import org.mctourney.autoreferee.util.commands.CommandHandler;

import org.apache.commons.cli.CommandLine;

import com.google.common.collect.Lists;
Expand Down Expand Up @@ -274,4 +273,65 @@ public boolean sendPluginMessage(CommandSender sender, AutoRefMatch match, Strin

return true;
}


/*
* Replaces the vanilla /time command so time is set only in the sender's world.
*/

@AutoRefCommand(name={"time"}, argmin=2,
description="Set the world time.",
usage="§cUsage: /time <set|add> <value>")
@AutoRefPermission(console=false, nodes={"bukkit.command.time"})

public boolean setTime(CommandSender sender, AutoRefMatch match, String[] args, CommandLine options)
{
if (args[0].equalsIgnoreCase("set")) {
int time = 0;

if (args[1].equalsIgnoreCase("day")) {
time = 1000;
} else if (args[1].equalsIgnoreCase("night")) {
time = 13000;
} else if (args[1].matches("\\d+")) {
time = Integer.parseInt(args[1]);
} else {
sender.sendMessage(ChatColor.RED + "'" + args[1] +"' is not a valid number");
return true;
}

if (sender instanceof Player) {
((Player) sender).getWorld().setTime(time);
sender.sendMessage("Set the time to " + time);
} else if (sender instanceof BlockCommandSender) {
((BlockCommandSender) sender).getBlock().getWorld().setTime(time);
} else if (sender instanceof CommandMinecart) {
((CommandMinecart) sender).getWorld().setTime(time);
}
}

if (args[0].equalsIgnoreCase("add")) {
if (args[1].matches("\\d+")) {
int time = Integer.parseInt(args[1]);

if (sender instanceof Player) {
World world = ((Player) sender).getWorld();
world.setTime(time + world.getTime());
sender.sendMessage("Added " + time + " to the time");
} else if (sender instanceof BlockCommandSender) {
World world = ((BlockCommandSender) sender).getBlock().getWorld();
world.setTime(time + world.getTime());
} else if (sender instanceof CommandMinecart) {
World world = ((CommandMinecart) sender).getWorld();
world.setTime(time + world.getTime());
}

} else {
sender.sendMessage(ChatColor.RED + "'" + args[1] +"' is not a valid number");
return true;
}
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public static Player entityToPlayer(Entity e)
// damaging entity is an arrow, then who was bow?
if ((e instanceof Projectile))
{
LivingEntity shooter = ((Projectile) e).getShooter();
LivingEntity shooter = (LivingEntity) ((Projectile) e).getShooter();
if ((shooter instanceof Player)) return (Player) shooter;
}
return null;
Expand Down Expand Up @@ -194,7 +194,7 @@ public void damageDealt(EntityDamageEvent event)
if (apl != null) apl.incrementShotsHit();

Arrow arrow = (Arrow) ed.getDamager();
if (arrow.getShooter().getType() == EntityType.PLAYER)
if (((LivingEntity)arrow.getShooter()).getType() == EntityType.PLAYER)
{
AutoRefPlayer shooter = match.getPlayer((Player) arrow.getShooter());
Location shotFrom = shotArrows.get(arrow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public void foreignInventoryEvent(InventoryClickEvent event)
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void projectileLaunch(ProjectileLaunchEvent event)
{
LivingEntity entity = event.getEntity().getShooter();
LivingEntity entity = (LivingEntity) event.getEntity().getShooter();
AutoRefMatch match = plugin.getMatch(event.getEntity().getWorld());
if (!(entity instanceof Player) || match == null) return;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.mctourney.autoreferee.listeners;
package org.mctourney.autoreferee.listeners;

import java.util.Iterator;
import java.util.Map;
Expand All @@ -18,6 +18,7 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
Expand All @@ -37,7 +38,6 @@
import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.plugin.Plugin;

import org.mctourney.autoreferee.AutoRefMatch;
import org.mctourney.autoreferee.AutoRefPlayer;
import org.mctourney.autoreferee.AutoRefTeam;
Expand Down Expand Up @@ -87,8 +87,8 @@ public void playerMove(PlayerMoveEvent event)
AutoRefPlayer apl = match.getPlayer(player);
if (apl == null)
{
// if the player is not on a team and has left the start area, teleport back
if (!match.isSpectator(player) && !match.inStartRegion(event.getTo()) && onGround)
// if the player is not on a team and has left the start area and is not in creative, teleport back
if (!match.isSpectator(player) && !match.inStartRegion(event.getTo()) && onGround && player.getGameMode() != GameMode.CREATIVE)
{
player.teleport(match.getWorldSpawn());
player.setFallDistance(0.0f);
Expand Down Expand Up @@ -318,6 +318,19 @@ public void blockInteract(PlayerInteractEvent event)
}
}

/*
* Prevents liquids from flowing in regions flagged with NO_FLOW
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockFromTo(BlockFromToEvent event) {
Block block = event.getToBlock();
AutoRefMatch match = plugin.getMatch(block.getWorld());

if (match != null && match.hasFlag(block.getLocation().add(0d, 0d, 0.5), AutoRefRegion.Flag.NO_FLOW)) {
event.setCancelled(true);
}
}

@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void entityInteract(PlayerInteractEntityEvent event)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void creatureSpawn(CreatureSpawnEvent event)
@EventHandler(priority= EventPriority.HIGHEST)
public void projectileLaunch(ProjectileLaunchEvent event)
{
LivingEntity shooter = event.getEntity().getShooter();
LivingEntity shooter = (LivingEntity) event.getEntity().getShooter();
if (shooter != null && checkAdminPrivilege(shooter)) return;

if (event.getEntity().getWorld() == plugin.getLobbyWorld())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ public static enum Flag
NO_EXPLOSIONS (1 << 3, false, 'e', "noexplosion"),
NO_ACCESS (1 << 4, false, 'a', "noaccess"),
NO_TELEPORT (1 << 5, false, 't', "noteleport"),
SPAWNERS_ONLY (1 << 6, false, 'w', "spawnersonly");
SPAWNERS_ONLY (1 << 6, false, 'w', "spawnersonly"),
NO_FLOW (1 << 7, true, 'f', "noflow");

// generated from above values
public static final String OPTIONS = "abenstw";
public static final String OPTIONS = "abenstwf";

private int value;
private String name;
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/org/mctourney/autoreferee/util/PlayerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
Expand Down Expand Up @@ -78,6 +79,24 @@ public static void removeStatusEffects(Player player)
for (PotionEffect effect : player.getActivePotionEffects())
player.removePotionEffect(effect.getType());
}

/**
* Clears player's ender chest
*/
public static void clearEnderChest(Player player)
{
// clear the ender chest
Inventory enderChest = player.getEnderChest();
enderChest.clear();
}

/**
* Clears player's bed spawn
*/
public static void clearBedSpawn(Player player)
{
player.setBedSpawnLocation(null, true);
}

/**
* Performs all PlayerUtil actions on this player.
Expand Down Expand Up @@ -157,7 +176,7 @@ public static void setGameMode(Player player, GameMode gamemode, boolean flight)
public static void setSpectatorSettings(Player player, boolean spec, GameMode pgm)
{
// gamemode is the obvious issue
PlayerUtil.setGameMode(player, spec ? GameMode.CREATIVE : pgm);
PlayerUtil.setGameMode(player, spec ? GameMode.SPECTATOR : pgm);

// basic player settings depending on role
player.setAllowFlight(spec);
Expand Down
7 changes: 5 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: AutoReferee
main: org.mctourney.autoreferee.AutoReferee
version: 2.6-SNAPSHOT
author: authorblues
version: 2.8
author: "authorblues, net"
load: startup

softdepend:
Expand Down Expand Up @@ -70,6 +70,9 @@ commands:
scoreboard:
description: Replacement for Bukkit's /scoreboard command
usage: /<command> ...
time:
description: Replacement for Minecraft's /time command
usage: /<command> [set, add] <value>

permissions:
autoreferee.*:
Expand Down

0 comments on commit f7a70c5

Please sign in to comment.