Merge remote-tracking branch 'remotes/origin/spigot-1.9'

# Conflicts:
#	pom.xml
#	src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureMetrics.java
#	src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/LCEditSession_LogBlock.java
#	src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/PlayerListener.java
This commit is contained in:
Norbi Peti 2018-06-27 13:42:29 +02:00
commit b8d21657ce
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
39 changed files with 495 additions and 772 deletions

4
.gitignore vendored
View file

@ -1,11 +1,13 @@
/bin /bin
# Eclipse stuff # IDE stuff
/.project /.project
/.classpath /.classpath
/.settings /.settings
/.buildpath /.buildpath
/.checkstyle /.checkstyle
/.idea
/LimitedCreative.iml
# maven # maven
/target /target

11
pom.xml
View file

@ -9,7 +9,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<plib.version>1.7.0</plib.version> <plib.version>1.7.0</plib.version>
<bukkit.version>1.7.2-R0.1-SNAPSHOT</bukkit.version> <bukkit.version>1.9.4-R0.1-SNAPSHOT</bukkit.version>
</properties> </properties>
<scm> <scm>
@ -123,12 +123,6 @@
<artifactId>xauth</artifactId> <artifactId>xauth</artifactId>
<version>2.0.26</version> <version>2.0.26</version>
</dependency> </dependency>
<dependency>
<!-- http://dev.bukkit.org/bukkit-plugins/logblock/ -->
<groupId>de.diddiz</groupId>
<artifactId>logblock</artifactId>
<version>dev-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<!-- http://dev.bukkit.org/bukkit-plugins/coreprotect/ --> <!-- http://dev.bukkit.org/bukkit-plugins/coreprotect/ -->
<groupId>net.coreprotect</groupId> <groupId>net.coreprotect</groupId>
@ -178,7 +172,6 @@
<param>MultiInv</param> <param>MultiInv</param>
<param>Multiverse-Inventories</param> <param>Multiverse-Inventories</param>
<param>Vault</param> <param>Vault</param>
<param>LogBlock</param>
<param>CoreProtect</param> <param>CoreProtect</param>
</softdepend> </softdepend>
<custom> <custom>
@ -256,7 +249,7 @@
<extension> <extension>
<groupId>org.apache.maven.wagon</groupId> <groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId> <artifactId>wagon-ssh</artifactId>
<version>1.0</version> <version>2.1</version>
</extension> </extension>
</extensions> </extensions>
</build> </build>

View file

@ -4,17 +4,16 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import de.jaschastarke.bukkit.lib.CoreModule; import de.jaschastarke.bukkit.lib.CoreModule;
@ -47,7 +46,7 @@ public class FeatureBlockItemSpawn extends CoreModule<LimitedCreative> implement
private void scheduleCleanUp() { private void scheduleCleanUp() {
if (cleanup.maxTime == 0) { // if not scheduled yet if (cleanup.maxTime == 0) { // if not scheduled yet
cleanup.maxTime = System.currentTimeMillis(); cleanup.maxTime = System.currentTimeMillis();
plugin.getServer().getScheduler().runTaskLater(plugin, cleanup, TICK_OFFSET); Bukkit.getScheduler().runTaskLater(plugin, cleanup, TICK_OFFSET);
} }
} }
@ -75,11 +74,11 @@ public class FeatureBlockItemSpawn extends CoreModule<LimitedCreative> implement
} }
public void block(Block block, Player player) { public void block(Block block, Player player) {
if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) { if (player.getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
block(block.getLocation(), block.getType()); block(block.getLocation(), block.getType());
} else { } else {
// doesn't include silktouch // doesn't include silktouch
for (ItemStack i : block.getDrops(player.getItemInHand())) { for (ItemStack i : block.getDrops(player.getInventory().getItemInMainHand())) {
block(block.getLocation(), i.getType()); block(block.getLocation(), i.getType());
} }
} }
@ -96,11 +95,15 @@ public class FeatureBlockItemSpawn extends CoreModule<LimitedCreative> implement
list.add(new BlockItemDrop(l, type)); list.add(new BlockItemDrop(l, type));
scheduleCleanUp(); scheduleCleanUp();
} }
public void block(Location l, ItemStack item) {
if (item != null)
block(l, item.getType());
}
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onItemSpawn(ItemSpawnEvent event) { public void onItemSpawn(ItemSpawnEvent event) {
if (event.getEntity() instanceof Item) { if (event.getEntity() != null) {
if (this.isBlocked(event.getLocation().getBlock().getLocation(), ((Item) event.getEntity()).getItemStack().getType())) { if (this.isBlocked(event.getLocation().getBlock().getLocation(), event.getEntity().getItemStack().getType())) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -113,8 +116,9 @@ public class FeatureBlockItemSpawn extends CoreModule<LimitedCreative> implement
return debug; return debug;
} }
private class CleanUp extends BukkitRunnable { private class CleanUp implements Runnable {
public long maxTime = 0; public long maxTime = 0;
@Override @Override
public void run() { public void run() {
if (plugin.isDebug()) if (plugin.isDebug())

View file

@ -69,6 +69,7 @@ public class FeatureSwitchGameMode extends CoreModule<LimitedCreative> {
return SwitchGameModePermissions.ALL.getPermission(subPerm); return SwitchGameModePermissions.ALL.getPermission(subPerm);
} }
@SuppressWarnings("deprecation")
protected boolean changeGameMode(CommandContext context, String player, GameMode tgm, IAbstractPermission permission) throws MissingPermissionCommandException, CommandException { protected boolean changeGameMode(CommandContext context, String player, GameMode tgm, IAbstractPermission permission) throws MissingPermissionCommandException, CommandException {
Player target = null; Player target = null;
if (player != null && !player.isEmpty()) { if (player != null && !player.isEmpty()) {
@ -137,6 +138,14 @@ public class FeatureSwitchGameMode extends CoreModule<LimitedCreative> {
public boolean adventure(CommandContext context, String player) throws MissingPermissionCommandException, CommandException { public boolean adventure(CommandContext context, String player) throws MissingPermissionCommandException, CommandException {
return changeGameMode(context, player, GameMode.ADVENTURE, SwitchGameModePermissions.ADVENTURE); return changeGameMode(context, player, GameMode.ADVENTURE, SwitchGameModePermissions.ADVENTURE);
} }
@IsCommand("spectator")
@Alias("sp")
@Description(value = "command.switch.spectator", translate = true)
@NeedsPermission(value={"spectator", "backonly"}, optional = true)
@Usages("[player]")
public boolean spectator(CommandContext context, String player) throws MissingPermissionCommandException, CommandException {
return changeGameMode(context, player, GameMode.SPECTATOR, SwitchGameModePermissions.SPECTATOR);
}
@Override @Override
public List<TabCompletion> getTabCompleter(MethodCommand cmd) { public List<TabCompletion> getTabCompleter(MethodCommand cmd) {

View file

@ -4,7 +4,6 @@ import org.bukkit.Bukkit;
import de.jaschastarke.hooking.BooleanHooker; import de.jaschastarke.hooking.BooleanHooker;
import de.jaschastarke.hooking.GetHooker; import de.jaschastarke.hooking.GetHooker;
import de.jaschastarke.minecraft.limitedcreative.hooks.AuthMeHooks;
import de.jaschastarke.minecraft.limitedcreative.hooks.MultiVerseHooks; import de.jaschastarke.minecraft.limitedcreative.hooks.MultiVerseHooks;
import de.jaschastarke.minecraft.limitedcreative.hooks.PlayerCheckHooker; import de.jaschastarke.minecraft.limitedcreative.hooks.PlayerCheckHooker;
import de.jaschastarke.minecraft.limitedcreative.hooks.WorldTypeHooker; import de.jaschastarke.minecraft.limitedcreative.hooks.WorldTypeHooker;
@ -20,6 +19,7 @@ public final class Hooks {
return Bukkit.getServer().getPluginManager().isPluginEnabled(pluginName); return Bukkit.getServer().getPluginManager().isPluginEnabled(pluginName);
} }
@SuppressWarnings("deprecation")
public static void inizializeHooks(LimitedCreative plugin) { public static void inizializeHooks(LimitedCreative plugin) {
IsLoggedIn.clearHooks(); IsLoggedIn.clearHooks();
DefaultWorldGameMode.clearHooks(); DefaultWorldGameMode.clearHooks();
@ -27,7 +27,7 @@ public final class Hooks {
InventoryIncompatible.clearHooks(); InventoryIncompatible.clearHooks();
if (isAuthMePresent()) { if (isAuthMePresent()) {
new AuthMeHooks(plugin); new de.jaschastarke.minecraft.limitedcreative.hooks.AuthMeHooks(plugin);
} }
if (isXAuth20Present()) { if (isXAuth20Present()) {
new xAuthHooks(plugin); new xAuthHooks(plugin);

View file

@ -1,8 +1,11 @@
package de.jaschastarke.minecraft.limitedcreative; package de.jaschastarke.minecraft.limitedcreative;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.sk89q.worldedit.WorldEdit;
import de.jaschastarke.bukkit.lib.CoreModule; import de.jaschastarke.bukkit.lib.CoreModule;
import de.jaschastarke.bukkit.lib.commands.AliasHelpedCommand; import de.jaschastarke.bukkit.lib.commands.AliasHelpedCommand;
import de.jaschastarke.bukkit.lib.modules.AdditionalBlockBreaks; import de.jaschastarke.bukkit.lib.modules.AdditionalBlockBreaks;
@ -12,12 +15,11 @@ import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockListener;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateCommand; import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateCommand;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateConfig; import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockStateConfig;
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel; import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel;
import de.jaschastarke.minecraft.limitedcreative.blockstate.DependencyListener; import de.jaschastarke.minecraft.limitedcreative.blockstate.HangingStandingListener;
import de.jaschastarke.minecraft.limitedcreative.blockstate.HangingListener;
import de.jaschastarke.minecraft.limitedcreative.blockstate.PlayerListener; import de.jaschastarke.minecraft.limitedcreative.blockstate.PlayerListener;
import de.jaschastarke.minecraft.limitedcreative.blockstate.SyncronizedModel; import de.jaschastarke.minecraft.limitedcreative.blockstate.SyncronizedModel;
import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel; import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel;
import de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSessionFactory; import de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.EditSessionListener;
import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.IModule;
import de.jaschastarke.modularize.ModuleEntry; import de.jaschastarke.modularize.ModuleEntry;
@ -48,9 +50,8 @@ public class ModBlockStates extends CoreModule<LimitedCreative> {
this.addModule(new BlockFall(plugin)); this.addModule(new BlockFall(plugin));
listeners.addListener(new BlockListener(this)); listeners.addListener(new BlockListener(this));
listeners.addListener(new HangingListener(this)); listeners.addListener(new HangingStandingListener(this));
listeners.addListener(new PlayerListener(this)); listeners.addListener(new PlayerListener(this));
listeners.addListener(new DependencyListener(this));
command = new BlockStateCommand(this); command = new BlockStateCommand(this);
} }
@ -78,7 +79,7 @@ public class ModBlockStates extends CoreModule<LimitedCreative> {
@Override @Override
public void run() { public void run() {
try { try {
LCEditSessionFactory.initFactory(ModBlockStates.this); WorldEdit.getInstance().getEventBus().register(new EditSessionListener(ModBlockStates.this));
} catch (Exception e) { } catch (Exception e) {
getLog().warn(plugin.getLocale().trans("block_state.warning.worldedit_sessionfactory_failed", e.getMessage())); getLog().warn(plugin.getLocale().trans("block_state.warning.worldedit_sessionfactory_failed", e.getMessage()));
} }

View file

@ -10,7 +10,6 @@ import org.bukkit.inventory.ItemStack;
import de.jaschastarke.bukkit.lib.CoreModule; import de.jaschastarke.bukkit.lib.CoreModule;
import de.jaschastarke.minecraft.limitedcreative.inventories.ArmoryConfig; import de.jaschastarke.minecraft.limitedcreative.inventories.ArmoryConfig;
import de.jaschastarke.minecraft.limitedcreative.inventories.AuthMeInventories;
import de.jaschastarke.minecraft.limitedcreative.inventories.Inventory; import de.jaschastarke.minecraft.limitedcreative.inventories.Inventory;
import de.jaschastarke.minecraft.limitedcreative.inventories.InventoryConfig; import de.jaschastarke.minecraft.limitedcreative.inventories.InventoryConfig;
import de.jaschastarke.minecraft.limitedcreative.inventories.InventoryPermissions; import de.jaschastarke.minecraft.limitedcreative.inventories.InventoryPermissions;
@ -34,6 +33,7 @@ public class ModInventories extends CoreModule<LimitedCreative> {
return "Inventory"; return "Inventory";
} }
@SuppressWarnings("deprecation")
@Override @Override
public void initialize(ModuleEntry<IModule> entry) { public void initialize(ModuleEntry<IModule> entry) {
super.initialize(entry); super.initialize(entry);
@ -42,7 +42,7 @@ public class ModInventories extends CoreModule<LimitedCreative> {
armor_config = config.registerSection(new ArmoryConfig(this)); armor_config = config.registerSection(new ArmoryConfig(this));
if (Hooks.isAuthMePresent()) { if (Hooks.isAuthMePresent()) {
addModule(new AuthMeInventories(plugin, this)); addModule(new de.jaschastarke.minecraft.limitedcreative.inventories.AuthMeInventories(plugin, this));
} }
String incomp = Hooks.InventoryIncompatible.test(); String incomp = Hooks.InventoryIncompatible.test();
if (config.getEnabled() && incomp != null) { if (config.getEnabled() && incomp != null) {
@ -90,8 +90,12 @@ public class ModInventories extends CoreModule<LimitedCreative> {
GameMode cgm = player.getGameMode(); GameMode cgm = player.getGameMode();
if (gm == GameMode.ADVENTURE && !config.getSeparateAdventure()) if (gm == GameMode.ADVENTURE && !config.getSeparateAdventure())
gm = GameMode.SURVIVAL; gm = GameMode.SURVIVAL;
else if (gm == GameMode.SPECTATOR)
gm = GameMode.CREATIVE;
if (cgm == GameMode.ADVENTURE && !config.getSeparateAdventure()) if (cgm == GameMode.ADVENTURE && !config.getSeparateAdventure())
cgm = GameMode.SURVIVAL; cgm = GameMode.SURVIVAL;
else if (cgm == GameMode.SPECTATOR)
cgm = GameMode.CREATIVE;
if (gm != cgm) { if (gm != cgm) {
if (gm != GameMode.CREATIVE || config.getStoreCreative()) { if (gm != GameMode.CREATIVE || config.getStoreCreative()) {

View file

@ -46,6 +46,11 @@ public class SwitchGameModePermissions extends ParentPermissionContainerNode {
*/ */
@IsChildPermission @IsChildPermission
public final static BasicPermission ADVENTURE = new BasicPermission(ALL, "adventure", PermissionDefault.FALSE); public final static BasicPermission ADVENTURE = new BasicPermission(ALL, "adventure", PermissionDefault.FALSE);
/**
* Allows switching of own game mode to spectator, but not to creative/survival/adventure
*/
@IsChildPermission
public final static BasicPermission SPECTATOR = new BasicPermission(ALL, "spectator", PermissionDefault.FALSE);
/** /**
* Allows switching of other users game mode * Allows switching of other users game mode

View file

@ -1,6 +1,5 @@
package de.jaschastarke.minecraft.limitedcreative.blockstate; package de.jaschastarke.minecraft.limitedcreative.blockstate;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -144,19 +143,15 @@ public class BlockListener implements Listener {
return; return;
event.getBlock().setMetadata("LCBS_pistonIsAlreadyExtended", blockAlreadExtended); event.getBlock().setMetadata("LCBS_pistonIsAlreadyExtended", blockAlreadExtended);
Block source = event.getBlock().getRelative(event.getDirection());
/*if (mod.isDebug()) /*if (mod.isDebug())
mod.getLog().debug("PistonExtend "+source.getType()+" "+source.getLocation()+" "+event.getDirection());*/ mod.getLog().debug("PistonExtend "+source.getType()+" "+source.getLocation()+" "+event.getDirection());*/
List<Block> movedBlocks = new ArrayList<Block>(); List<Block> movedBlocks = event.getBlocks();
while (source != null && source.getType() != Material.AIR) {
movedBlocks.add(0, source); // put on top, so iterating the
source = source.getRelative(event.getDirection());
}
if (movedBlocks.size() > 0) { if (movedBlocks.size() > 0) {
DBTransaction update = mod.getModel().groupUpdate(); DBTransaction update = mod.getModel().groupUpdate();
for (Block sblock : movedBlocks) { for(int count = movedBlocks.size()-1; count >= 0; count--){
Block sblock = movedBlocks.get(count);
Block dest = sblock.getRelative(event.getDirection()); Block dest = sblock.getRelative(event.getDirection());
if (mod.isDebug()) if (mod.isDebug())
mod.getLog().debug("PistionExtend moves "+sblock.getType()+"-Block from "+sblock.getLocation()+" to "+dest.getLocation()); mod.getLog().debug("PistionExtend moves "+sblock.getType()+"-Block from "+sblock.getLocation()+" to "+dest.getLocation());
@ -173,12 +168,19 @@ public class BlockListener implements Listener {
return; return;
event.getBlock().removeMetadata("LCBS_pistonIsAlreadyExtended", mod.getPlugin()); event.getBlock().removeMetadata("LCBS_pistonIsAlreadyExtended", mod.getPlugin());
Block dest = event.getBlock().getRelative(event.getDirection()); List<Block> movedBlocks = event.getBlocks();
Block source = dest.getRelative(event.getDirection()); if(movedBlocks.size() > 0)
if (event.isSticky() && source.getType() != Material.AIR) { {
if (mod.isDebug()) DBTransaction update = mod.getModel().groupUpdate();
mod.getLog().debug("PistionRetract moves "+source.getType()+"-Block from "+source.getLocation()+" to "+dest.getLocation()); for(int count = movedBlocks.size()-1; count >= 0; count--){
mod.getModel().moveState(source, source.getRelative(event.getDirection().getOppositeFace())); Block sblock = movedBlocks.get(count);
Block dest = sblock.getRelative(event.getDirection());
if (mod.isDebug())
mod.getLog().debug("PistionRetract moves "+sblock.getType()+"-Block from "+sblock.getLocation()+" to "+dest.getLocation());
update.moveState(sblock, dest);
}
update.finish();
} }
} }
} }

View file

@ -1,6 +1,7 @@
package de.jaschastarke.minecraft.limitedcreative.blockstate; package de.jaschastarke.minecraft.limitedcreative.blockstate;
import java.util.Date; import java.util.Date;
import java.util.UUID;
import javax.persistence.Column; import javax.persistence.Column;
//import javax.persistence.EmbeddedId; //import javax.persistence.EmbeddedId;
@ -37,7 +38,7 @@ public class BlockState {
private GameMode gameMode; private GameMode gameMode;
@Column(name = "player") @Column(name = "player")
private String playerName; private UUID uuid;
@NotNull @NotNull
@Column(name = "cdate") @Column(name = "cdate")
@ -51,7 +52,7 @@ public class BlockState {
public BlockState(BlockState copy) { public BlockState(BlockState copy) {
this.location = copy.location; this.location = copy.location;
this.gameMode = copy.gameMode; this.gameMode = copy.gameMode;
this.playerName = copy.playerName; this.uuid = copy.uuid;
this.date = copy.date; this.date = copy.date;
this.source = copy.source; this.source = copy.source;
} }
@ -72,24 +73,29 @@ public class BlockState {
this.gameMode = gm; this.gameMode = gm;
} }
public String getPlayerName() { public UUID getPlayerUUID() {
return playerName; return uuid;
} }
public String getPlayerName() {
return Bukkit.getOfflinePlayer(uuid).getName();
}
//TODO Rename
public void setPlayerName(String s) { public void setPlayerName(String s) {
playerName = s; uuid = UUID.fromString(s);
} }
public OfflinePlayer getPlayer() { public OfflinePlayer getPlayer() {
OfflinePlayer p = Bukkit.getPlayerExact(playerName); OfflinePlayer p = Bukkit.getPlayer(uuid);
if (p == null) if (p == null)
p = Bukkit.getOfflinePlayer(playerName); p = Bukkit.getOfflinePlayer(uuid);
return p; return p;
} }
public void setPlayer(OfflinePlayer player) { public void setPlayer(OfflinePlayer player) {
setSource(Source.PLAYER); setSource(Source.PLAYER);
this.playerName = player.getName(); this.uuid = player.getUniqueId();
if (player instanceof Player) { if (player instanceof Player) {
setGameMode(((Player) player).getGameMode()); setGameMode(((Player) player).getGameMode());
} }
@ -119,6 +125,7 @@ public class BlockState {
@Override @Override
public String toString() { public String toString() {
String playerName = Bukkit.getOfflinePlayer(uuid).getName();
//return blockLocation.toString() + " by " + //return blockLocation.toString() + " by " +
return location.toString() + " by " + return location.toString() + " by " +
(source == Source.PLAYER ? playerName : (source.toString() + (playerName != null ? "(" + playerName + ")" : ""))) + (source == Source.PLAYER ? playerName : (source.toString() + (playerName != null ? "(" + playerName + ")" : ""))) +

View file

@ -7,8 +7,6 @@ import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.scheduler.BukkitRunnable;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.selections.Selection; import com.sk89q.worldedit.bukkit.selections.Selection;
@ -105,7 +103,7 @@ public class BlockStateCommand extends BukkitCommand implements IHelpDescribed {
if (mod.getConfig().getLogSurvival()) { if (mod.getConfig().getLogSurvival()) {
context.responseFormatted(ChatFormattings.INFO, L("command.blockstate.nothing_to_cleanup")); context.responseFormatted(ChatFormattings.INFO, L("command.blockstate.nothing_to_cleanup"));
} else { } else {
mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new BukkitRunnable() { mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
int countDeleted = mod.getModel().cleanUp(DBModel.Cleanup.SURVIVAL); int countDeleted = mod.getModel().cleanUp(DBModel.Cleanup.SURVIVAL);
@ -168,7 +166,7 @@ public class BlockStateCommand extends BukkitCommand implements IHelpDescribed {
final Location min = selection.getMinimumPoint(); final Location min = selection.getMinimumPoint();
final Location max = selection.getMaximumPoint(); final Location max = selection.getMaximumPoint();
mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new BukkitRunnable() { mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
if (mod.isDebug()) if (mod.isDebug())

View file

@ -93,11 +93,11 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub
* *
* Without threading, huge WorldEdits becomes much noticeable slower. * Without threading, huge WorldEdits becomes much noticeable slower.
* *
* default: false * default: true
*/ */
@IsConfigurationNode(order = 150) @IsConfigurationNode(order = 150)
public boolean getUseThreading() { public boolean getUseThreading() {
return config.getBoolean("useThreading", false); return config.getBoolean("useThreading", true);
} }
/** /**

View file

@ -138,7 +138,7 @@ public class DBQueries {
update.setString(1, s.getGameMode().name()); update.setString(1, s.getGameMode().name());
else else
update.setInt(1, s.getGameMode().getValue()); update.setInt(1, s.getGameMode().getValue());
update.setString(2, s.getPlayerName()); update.setString(2, s.getPlayerUUID().toString());
update.setTimestamp(3, new java.sql.Timestamp(s.getDate().getTime())); update.setTimestamp(3, new java.sql.Timestamp(s.getDate().getTime()));
if (db.getType() == Type.MySQL) if (db.getType() == Type.MySQL)
update.setString(4, s.getSource().name()); update.setString(4, s.getSource().name());
@ -207,7 +207,7 @@ public class DBQueries {
insert.setString(5, s.getGameMode().name()); insert.setString(5, s.getGameMode().name());
else else
insert.setInt(5, s.getGameMode().getValue()); insert.setInt(5, s.getGameMode().getValue());
insert.setString(6, s.getPlayerName()); insert.setString(6, s.getPlayerUUID().toString());
insert.setTimestamp(7, new java.sql.Timestamp(s.getDate().getTime())); insert.setTimestamp(7, new java.sql.Timestamp(s.getDate().getTime()));
if (db.getType() == Type.MySQL) if (db.getType() == Type.MySQL)
insert.setString(8, s.getSource().name()); insert.setString(8, s.getSource().name());

View file

@ -1,28 +0,0 @@
package de.jaschastarke.minecraft.limitedcreative.blockstate;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginEnableEvent;
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
import de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSessionFactory;
public class DependencyListener implements Listener {
private ModBlockStates mod;
public DependencyListener(ModBlockStates mod) {
this.mod = mod;
}
@EventHandler
public void onPluginLoaded(PluginEnableEvent event) {
if (event.getPlugin().getName().equals("LogBlock") || event.getPlugin().getName().equals("WorldEdit")) {
try {
if (mod.getPlugin().getServer().getPluginManager().isPluginEnabled("WorldEdit"))
LCEditSessionFactory.initFactory(mod);
} catch (Exception e) {
mod.getLog().warn(mod.getPlugin().getLocale().trans("block_state.warning.worldedit_sessionfactory_failed", e.getMessage()));
}
}
}
}

View file

@ -4,21 +4,26 @@ import java.util.Date;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates; import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
public class HangingListener implements Listener { public class HangingStandingListener implements Listener {
private ModBlockStates mod; private ModBlockStates mod;
public HangingListener(ModBlockStates mod) { public HangingStandingListener(ModBlockStates mod) {
this.mod = mod; this.mod = mod;
} }
@ -35,7 +40,27 @@ public class HangingListener implements Listener {
if (mod.isDebug()) if (mod.isDebug())
mod.getLog().debug("... was placed by creative. Modify prevented"); mod.getLog().debug("... was placed by creative. Modify prevented");
event.setCancelled(true); event.setCancelled(true);
return; }
} else {
BlockState s = new BlockState();
s.setLocation(event.getRightClicked().getLocation().getBlock().getLocation());
s.setPlayer(event.getPlayer());
s.setDate(new Date());
if (mod.isDebug())
mod.getLog().debug("Saving BlockState: " + s.toString());
mod.getModel().setState(s);
}
} else if (event.getRightClicked() instanceof ArmorStand) {
if (mod.getModel().isRestricted(event.getRightClicked().getLocation().getBlock())) {
if (mod.isDebug())
mod.getLog().debug("Modifying standing: " + event.getRightClicked().getLocation().toString());
if (event.getPlayer().getGameMode() != GameMode.CREATIVE) {
if (mod.isDebug())
mod.getLog().debug("... was placed by creative. Modify prevented");
event.setCancelled(true);
} }
} else { } else {
BlockState s = new BlockState(); BlockState s = new BlockState();
@ -50,6 +75,15 @@ public class HangingListener implements Listener {
} }
} }
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
onPlayerInteractEntity(event);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onArmorStandManipulateEvent(PlayerArmorStandManipulateEvent event) {
onPlayerInteractEntity(event);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerLeftInteractEntity(EntityDamageByEntityEvent event) { public void onPlayerLeftInteractEntity(EntityDamageByEntityEvent event) {
if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName())) if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName()))
@ -63,7 +97,6 @@ public class HangingListener implements Listener {
if (mod.isDebug()) if (mod.isDebug())
mod.getLog().debug("... was placed by creative. Modify prevented"); mod.getLog().debug("... was placed by creative. Modify prevented");
event.setCancelled(true); event.setCancelled(true);
return;
} }
} else { } else {
BlockState s = new BlockState(); BlockState s = new BlockState();
@ -99,6 +132,61 @@ public class HangingListener implements Listener {
} }
} }
protected void checkArmoryDestroy(ArmorStand entity, boolean deRemove) {
if (mod.isDebug())
mod.getLog().debug("Breaking standing: " + entity.getLocation().toString());
if (mod.getModel().isRestricted(entity.getLocation().getBlock())) {
if (mod.isDebug())
mod.getLog().debug("... was placed by creative. Drop prevented");
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), Material.ARMOR_STAND);
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), Material.ARMOR_STAND);
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getHelmet());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getChestplate());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getBoots());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getItemInHand());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getLocation(), entity.getLeggings());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getHelmet());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getChestplate());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getBoots());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getItemInHand());
mod.getBlockSpawn().block(entity.getLocation().getBlock().getRelative(BlockFace.UP).getLocation(), entity.getLeggings());
/*entity.setBoots(null);
entity.setChestplate(null);
entity.setHelmet(null);
entity.setItemInHand(null);
entity.setLeggings(null);*/
}
if (deRemove)
mod.getModel().removeState(entity.getLocation().getBlock());
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onStandingBreak(EntityDeathEvent event) {
if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName()))
return;
if (event.getEntity() instanceof ArmorStand) {
checkArmoryDestroy((ArmorStand) event.getEntity(), true);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onStandingBreaking(EntityDamageByEntityEvent event) {
if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName()))
return;
if (event.getEntity() instanceof ArmorStand) {
// TODO: Bug in Spigot, we can not check for destroying yet. so the block state stays in DB :(
//if (event.getEntity().isDead() || ((ArmorStand) event.getEntity()).getHealth() <= event.getFinalDamage()) {
checkArmoryDestroy((ArmorStand) event.getEntity(), false);
//}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onHangingPlace(HangingPlaceEvent event) { public void onHangingPlace(HangingPlaceEvent event) {
if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName())) if (mod.getConfig().getIgnoredWorlds().contains(event.getEntity().getWorld().getName()))

View file

@ -29,7 +29,7 @@ public class PlayerListener implements Listener {
public void onInteract(PlayerInteractEvent event) { public void onInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Block b = event.getClickedBlock(); Block b = event.getClickedBlock();
if (b != null && event.getPlayer().getItemInHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) { if (b != null && event.getPlayer().getInventory().getItemInMainHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) {
if (mod.getConfig().getIgnoredWorlds().contains(event.getClickedBlock().getWorld().getName())) { if (mod.getConfig().getIgnoredWorlds().contains(event.getClickedBlock().getWorld().getName())) {
event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("command.blockstate.world_ignored", event.getClickedBlock().getWorld().getName())); event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("command.blockstate.world_ignored", event.getClickedBlock().getWorld().getName()));
} else { } else {
@ -41,7 +41,7 @@ public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onInteractEntity(PlayerInteractEntityEvent event) { public void onInteractEntity(PlayerInteractEntityEvent event) {
Entity e = event.getRightClicked(); Entity e = event.getRightClicked();
if (e != null && e instanceof ItemFrame && event.getPlayer().getItemInHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) { if (e != null && e instanceof ItemFrame && event.getPlayer().getInventory().getItemInMainHand().getType().equals(mod.getConfig().getTool()) && mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), BlockStatePermissions.TOOL)) {
if (mod.getConfig().getIgnoredWorlds().contains(e.getWorld().getName())) { if (mod.getConfig().getIgnoredWorlds().contains(e.getWorld().getName())) {
event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("command.blockstate.world_ignored", e.getWorld().getName())); event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("command.blockstate.world_ignored", e.getWorld().getName()));
} else { } else {

View file

@ -0,0 +1,58 @@
package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit;
import java.util.Date;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.logging.AbstractLoggingExtent;
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState.Source;
public class EditSessionExtent extends AbstractLoggingExtent {
private ModBlockStates mod;
private Player player = null;
private World world;
public EditSessionExtent(Extent extent, ModBlockStates mod, Player player, World world) {
super(extent);
this.mod = mod;
this.player = player;
this.world = world;
}
/**
* Called when a block is being changed.
*
* @param position the position
* @param newBlock the new block to replace the old one
*/
protected void onBlockChange(Vector pt, BaseBlock newBlock) {
if (mod.isDebug())
mod.getLog().debug("WorldEdit-Integration: BlockChange: "+pt.toString()+" BB: " + newBlock.toString());
Location loc = new Location(world, pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (newBlock.getType() == 0) {
mod.getModel().removeState(loc.getBlock());
} else {
BlockState s = mod.getModel().getState(loc.getBlock());
if (s == null) {
s = new BlockState();
s.setLocation(loc);
}
s.setGameMode(null);
s.setPlayerName(player.getUniqueId().toString());
s.setDate(new Date());
s.setSource(Source.EDIT);
if (mod.isDebug())
mod.getLog().debug("WorldEdit-Integration: Saving BlockState: " + s.toString());
mod.getModel().setState(s);
}
}
}

View file

@ -0,0 +1,38 @@
package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.EditSession.Stage;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.eventbus.Subscribe;
import com.sk89q.worldedit.world.World;
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
public class EditSessionListener {
private ModBlockStates mod;
public EditSessionListener(ModBlockStates mod) {
this.mod = mod;
}
@Subscribe
public void onEditSession(EditSessionEvent event) {
if (mod.getConfig().getWorldeditIntegration()) {
if (event.getStage() == Stage.BEFORE_CHANGE) {
if (mod.isDebug())
mod.getLog().debug("WorldEdit-Integration: New EditSession: "+event.getActor().getName()+" in World "+event.getWorld().getName()); // + " (" + event.getStage() + ")");
Actor actor = event.getActor();
World world = event.getWorld();
if (actor != null && actor.isPlayer() && world != null && world instanceof BukkitWorld) {
Player player = Bukkit.getPlayer(actor.getUniqueId());
event.setExtent(new EditSessionExtent(event.getExtent(), mod, player, ((BukkitWorld) event.getWorld()).getWorld()));
}
}
}
}
}

View file

@ -1,97 +0,0 @@
package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.regions.Region;
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.DBTransaction;
public class LCEditSession extends EditSession {
private LCEditSessionFactory factory;
private LocalPlayer player;
public LCEditSession(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
super(world, maxBlocks, blockBag);
this.factory = factory;
this.player = player;
}
public LCEditSession(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, LocalPlayer player) {
super(world, maxBlocks);
this.factory = factory;
this.player = player;
}
private DBTransaction transaction;
@Override
public void flushQueue() {
transaction = factory.getModel().groupUpdate();
super.flushQueue();
if (transaction != null) {
transaction.finish();
transaction = null;
}
}
@Override
public int setBlocks(Region region, BaseBlock block) throws MaxChangedBlocksException {
boolean useTransaction = false;
if (transaction == null) {
transaction = factory.getModel().groupUpdate();
useTransaction = true;
}
int ret;
try {
ret = super.setBlocks(region, block);
} catch (MaxChangedBlocksException e) {
transaction = null;
throw e;
}
if (transaction != null && useTransaction) {
transaction.finish();
transaction = null;
}
return ret;
}
@Override
public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
boolean useTransaction = false;
if (transaction == null) {
transaction = factory.getModel().groupUpdate();
useTransaction = true;
}
int ret;
try {
ret = super.setBlocks(region, pattern);
} catch (MaxChangedBlocksException e) {
transaction = null;
throw e;
}
if (transaction != null && useTransaction) {
transaction.finish();
transaction = null;
}
return ret;
}
@Override
public boolean rawSetBlock(Vector pt, BaseBlock block) {
boolean success = super.rawSetBlock(pt, block);
if (success) {
if (transaction != null) {
factory.onTransactionBlockEdit(transaction, player, pt, block);
} else {
factory.onBlockEdit(player, pt, block);
}
}
return success;
}
}

View file

@ -1,216 +0,0 @@
package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import org.bukkit.Location;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.EditSessionFactory;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState.Source;
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel;
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.DBTransaction;
public class LCEditSessionFactory extends EditSessionFactory {
private ModBlockStates mod;
private EditSessionParent parent;
static enum EditSessionParent {
WORLDEDIT,
LOGBLOCK("de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSession_LogBlock"),
COREPROTECT("de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSession_CoreProtect");
private String cls = null;
EditSessionParent() {
}
EditSessionParent(String cls) {
this.cls = cls;
}
public EditSession createInstance(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, LocalPlayer player) {
if (this.cls != null) {
try {
@SuppressWarnings("unchecked")
Class<EditSession> sessClass = (Class<EditSession>) Class.forName(cls);
return sessClass.getConstructor(LCEditSessionFactory.class, LocalWorld.class, int.class, LocalPlayer.class)
.newInstance(factory, world, maxBlocks, player);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
}
}
return new LCEditSession(factory, world, maxBlocks, player);
}
public EditSession createInstance(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
if (this.cls != null) {
try {
@SuppressWarnings("unchecked")
Class<EditSession> sessClass = (Class<EditSession>) Class.forName(cls);
return sessClass.getConstructor(LCEditSessionFactory.class, LocalWorld.class, int.class, LocalPlayer.class)
.newInstance(factory, world, maxBlocks, player);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
}
}
return new LCEditSession(factory, world, maxBlocks, player);
}
}
public ModBlockStates getLimitedCreativeModule() {
return mod;
}
public LCEditSessionFactory(ModBlockStates mod, EditSessionParent parent) {
this.mod = mod;
this.parent = parent;
}
@Override
public EditSession getEditSession(LocalWorld world, int maxBlocks, LocalPlayer player) {
return parent.createInstance(this, world, maxBlocks, player);
/*switch (parent) {
case LOGBLOCK:
return new LCEditSession_LogBlock(this, world, maxBlocks, player);
default:
return new LCEditSession(this, world, maxBlocks, player);
}*/
}
// Without Player, the world isn't know, so we can't opporate
/*@Override
public EditSession getEditSession(LocalWorld world, int maxBlocks) {
return new LCEditSession(this, world, maxBlocks, null);
}*/
@Override
public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
return parent.createInstance(this, world, maxBlocks, blockBag, player);
/*switch (parent) {
case LOGBLOCK:
return new LCEditSession_LogBlock(this, world, maxBlocks, blockBag, player);
default:
return new LCEditSession(this, world, maxBlocks, blockBag, player);
}*/
}
/*@Override
public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag) {
return new LCEditSession(this, world, maxBlocks, blockBag, null);
}*/
public static void initFactory(ModBlockStates mod) throws Exception {
EditSessionFactory currentEditSessionFactory = WorldEdit.getInstance().getEditSessionFactory();
if (currentEditSessionFactory instanceof LCEditSessionFactory) {
if (mod.isDebug())
mod.getLog().debug("WorlEdit-SessionFactory is already hooked");
} else if (currentEditSessionFactory.getClass().equals(EditSessionFactory.class)) { // not overridden
if (mod.isDebug())
mod.getLog().debug("Replacing WorldEdits SessionFactory");
WorldEdit.getInstance().setEditSessionFactory(new LCEditSessionFactory(mod, EditSessionParent.WORLDEDIT));
} else if (currentEditSessionFactory.getClass().getName().equals("de.diddiz.worldedit.LogBlockEditSessionFactory")) {
if (mod.isDebug())
mod.getLog().debug("Replacing LogBlocks WorldEdit-SessionFactory");
WorldEdit.getInstance().setEditSessionFactory(new LCEditSessionFactory(mod, EditSessionParent.LOGBLOCK));
} else if (currentEditSessionFactory.getClass().getName().equals("net.coreprotect.worldedit.CoreProtectEditSessionFactory")) {
if (mod.isDebug())
mod.getLog().debug("Replacing CoreProtects WorldEdit-SessionFactory");
WorldEdit.getInstance().setEditSessionFactory(new LCEditSessionFactory(mod, EditSessionParent.COREPROTECT));
} else {
throw new Exception("WorldEdit-SessionFactory is hooked by an unknown another Plugin (" + currentEditSessionFactory.getClass().getName() + ").");
}
}
/*public void onBlockEdit(Vector pt, BaseBlock block) {
this.onBlockEdit(null, pt, block);
}*/
public DBModel getModel() {
return mod.getModel();
}
public boolean onBlockEdit(LocalPlayer player, Vector pt, BaseBlock block) {
if (player != null) {
Location loc = new Location(((BukkitWorld) player.getWorld()).getWorld(), pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (block.getType() == 0) {
mod.getModel().removeState(loc.getBlock());
} else {
BlockState s = mod.getModel().getState(loc.getBlock());
if (s == null) {
s = new BlockState();
s.setLocation(loc);
}
s.setGameMode(null);
s.setPlayerName(player.getName());
s.setDate(new Date());
s.setSource(Source.EDIT);
if (mod.isDebug())
mod.getLog().debug("Saving BlockState: " + s.toString());
mod.getModel().setState(s);
}
return true;
} else {
return false;
}
}
public boolean onTransactionBlockEdit(DBTransaction transaction, LocalPlayer player, Vector pt, BaseBlock block) {
if (player != null) {
Location loc = new Location(((BukkitWorld) player.getWorld()).getWorld(), pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (block.getType() == 0) {
transaction.removeState(loc.getBlock());
} else {
BlockState s = mod.getModel().getState(loc.getBlock());
if (s == null) {
s = new BlockState();
s.setLocation(loc);
}
s.setGameMode(null);
s.setPlayerName(player.getName());
s.setDate(new Date());
s.setSource(Source.EDIT);
if (mod.isDebug())
mod.getLog().debug("Saving BlockState: " + s.toString());
transaction.setState(s);
}
return true;
} else {
return false;
}
}
}

View file

@ -1,99 +0,0 @@
package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit;
import net.coreprotect.CoreProtect;
import net.coreprotect.worldedit.CoreProtectEditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.regions.Region;
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.DBTransaction;
public class LCEditSession_CoreProtect extends CoreProtectEditSession {
private LCEditSessionFactory factory;
private LocalPlayer player;
public LCEditSession_CoreProtect(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
super(world, maxBlocks, blockBag, player, CoreProtect.getInstance());
this.factory = factory;
this.player = player;
}
public LCEditSession_CoreProtect(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, LocalPlayer player) {
super(world, maxBlocks, player, CoreProtect.getInstance());
this.factory = factory;
this.player = player;
}
private DBTransaction transaction;
@Override
public void flushQueue() {
transaction = factory.getModel().groupUpdate();
super.flushQueue();
if (transaction != null) {
transaction.finish();
transaction = null;
}
}
@Override
public int setBlocks(Region region, BaseBlock block) throws MaxChangedBlocksException {
boolean useTransaction = false;
if (transaction == null) {
transaction = factory.getModel().groupUpdate();
useTransaction = true;
}
int ret;
try {
ret = super.setBlocks(region, block);
} catch (MaxChangedBlocksException e) {
transaction = null;
throw e;
}
if (transaction != null && useTransaction) {
transaction.finish();
transaction = null;
}
return ret;
}
@Override
public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
boolean useTransaction = false;
if (transaction == null) {
transaction = factory.getModel().groupUpdate();
useTransaction = true;
}
int ret;
try {
ret = super.setBlocks(region, pattern);
} catch (MaxChangedBlocksException e) {
transaction = null;
throw e;
}
if (transaction != null && useTransaction) {
transaction.finish();
transaction = null;
}
return ret;
}
@Override
public boolean rawSetBlock(Vector pt, BaseBlock block) {
boolean success = super.rawSetBlock(pt, block);
if (success) {
if (transaction != null) {
factory.onTransactionBlockEdit(transaction, player, pt, block);
} else {
factory.onBlockEdit(player, pt, block);
}
}
return success;
}
}

View file

@ -1,97 +0,0 @@
package de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.regions.Region;
import de.diddiz.LogBlock.LogBlock;
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.DBTransaction;
public class LCEditSession_LogBlock { //The superclass got deleted at: https://github.com/LogBlock/LogBlock/commit/fa1e1b777a9da062d10d7c3c1906520e4d39eba8
/* private LCEditSessionFactory factory;
private LocalPlayer player;
public LCEditSession_LogBlock(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
super(world, maxBlocks, blockBag, player, LogBlock.getInstance());
this.factory = factory;
this.player = player;
}
public LCEditSession_LogBlock(LCEditSessionFactory factory, LocalWorld world, int maxBlocks, LocalPlayer player) {
super(world, maxBlocks, player, LogBlock.getInstance());
this.factory = factory;
this.player = player;
}
private DBTransaction transaction;
@Override
public void flushQueue() {
transaction = factory.getModel().groupUpdate();
super.flushQueue();
if (transaction != null) {
transaction.finish();
transaction = null;
}
}
@Override
public int setBlocks(Region region, BaseBlock block) throws MaxChangedBlocksException {
boolean useTransaction = false;
if (transaction == null) {
transaction = factory.getModel().groupUpdate();
useTransaction = true;
}
int ret;
try {
ret = super.setBlocks(region, block);
} catch (MaxChangedBlocksException e) {
transaction = null;
throw e;
}
if (transaction != null && useTransaction) {
transaction.finish();
transaction = null;
}
return ret;
}
@Override
public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
boolean useTransaction = false;
if (transaction == null) {
transaction = factory.getModel().groupUpdate();
useTransaction = true;
}
int ret;
try {
ret = super.setBlocks(region, pattern);
} catch (MaxChangedBlocksException e) {
transaction = null;
throw e;
}
if (transaction != null && useTransaction) {
transaction.finish();
transaction = null;
}
return ret;
}
@Override
public boolean rawSetBlock(Vector pt, BaseBlock block) {
boolean success = super.rawSetBlock(pt, block);
if (success) {
if (transaction != null) {
factory.onTransactionBlockEdit(transaction, player, pt, block);
} else {
factory.onBlockEdit(player, pt, block);
}
}
return success;
}*/
}

View file

@ -31,7 +31,8 @@ public class Inventory {
public enum Target { public enum Target {
SURVIVAL, SURVIVAL,
CREATIVE, CREATIVE,
ADVENTURE; ADVENTURE,
SPECTATOR;
public static Target getTarget(GameMode gm) { public static Target getTarget(GameMode gm) {
return Target.valueOf(gm.name()); return Target.valueOf(gm.name());

View file

@ -47,7 +47,7 @@ public class Fallback {
@Override @Override
public void store(ConfigurationSection section) { public void store(ConfigurationSection section) {
for (int i = 0; i < inv.getSize(); i++) { for (int i = 0; i < inv.getSize(); i++) {
if (inv.getItem(i) != null && inv.getItem(i).getTypeId() != 0) if (inv.getItem(i) != null && !inv.getItem(i).getType().equals(Material.AIR))
sectionSetItem(section, String.valueOf(i), inv.getItem(i)); sectionSetItem(section, String.valueOf(i), inv.getItem(i));
} }
} }
@ -97,7 +97,7 @@ public class Fallback {
public static Map<Integer, ItemStack> storeInventory(PlayerInventory inv) { public static Map<Integer, ItemStack> storeInventory(PlayerInventory inv) {
Map<Integer, ItemStack> map = new HashMap<Integer, ItemStack>(); Map<Integer, ItemStack> map = new HashMap<Integer, ItemStack>();
for (int i = 0; i < inv.getSize(); i++) { for (int i = 0; i < inv.getSize(); i++) {
if (inv.getItem(i) != null && inv.getItem(i).getTypeId() != 0) { if (inv.getItem(i) != null && !inv.getItem(i).getType().equals(Material.AIR)) {
map.put(i, inv.getItem(i)); map.put(i, inv.getItem(i));
} }
} }
@ -133,13 +133,13 @@ public class Fallback {
@Override @Override
public void store(ConfigurationSection section) { public void store(ConfigurationSection section) {
if (inv.getHelmet() != null && inv.getHelmet().getTypeId() != 0) if (inv.getHelmet() != null && !inv.getHelmet().getType().equals(Material.AIR))
Items.sectionSetItem(section, "helmet", inv.getHelmet()); Items.sectionSetItem(section, "helmet", inv.getHelmet());
if (inv.getChestplate() != null && inv.getChestplate().getTypeId() != 0) if (inv.getChestplate() != null && !inv.getChestplate().getType().equals(Material.AIR))
Items.sectionSetItem(section, "chestplate", inv.getChestplate()); Items.sectionSetItem(section, "chestplate", inv.getChestplate());
if (inv.getLeggings() != null && inv.getLeggings().getTypeId() != 0) if (inv.getLeggings() != null && !inv.getLeggings().getType().equals(Material.AIR))
Items.sectionSetItem(section, "leggins", inv.getLeggings()); Items.sectionSetItem(section, "leggins", inv.getLeggings());
if (inv.getBoots() != null && inv.getBoots().getTypeId() != 0) if (inv.getBoots() != null && !inv.getBoots().getType().equals(Material.AIR))
Items.sectionSetItem(section, "boots", inv.getBoots()); Items.sectionSetItem(section, "boots", inv.getBoots());
} }

View file

@ -71,9 +71,9 @@ public class InvYamlStorage extends InvConfStorage {
protected File getFile(Inventory pinv, Target target) { protected File getFile(Inventory pinv, Target target) {
if (target != default_target) { if (target != default_target) {
return new File(dir, pinv.getPlayer().getName() + "_" + target.toString().toLowerCase() + SUFFIX); return new File(dir, pinv.getPlayer().getUniqueId() + "_" + target.toString().toLowerCase() + SUFFIX);
} else { } else {
return new File(dir, pinv.getPlayer().getName() + SUFFIX); return new File(dir, pinv.getPlayer().getUniqueId() + SUFFIX);
} }
} }
} }

View file

@ -55,7 +55,7 @@ public class BlackList extends ArrayList<BlackList.Blacklisted> implements Confi
} }
public boolean matches(Block block) { public boolean matches(Block block) {
if (hasData) { if (hasData) {
return md.equals(new MaterialData(block.getType(), block.getData())); return md.equals(block.getState().getData());
} else { } else {
return block.getType().equals(md.getItemType()); return block.getType().equals(md.getItemType());
} }

View file

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import de.jaschastarke.bukkit.lib.configuration.command.ITabComplete;
import de.jaschastarke.bukkit.lib.configuration.command.ListConfigValue;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
@ -11,9 +13,32 @@ import de.jaschastarke.bukkit.lib.configuration.ConfigurableList;
import de.jaschastarke.bukkit.lib.configuration.IToGeneric; import de.jaschastarke.bukkit.lib.configuration.IToGeneric;
import de.jaschastarke.configuration.InvalidValueException; import de.jaschastarke.configuration.InvalidValueException;
public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> implements ConfigurableList<BlackListEntity.Blacklisted>, IToGeneric { public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> implements ConfigurableList<BlackListEntity.Blacklisted>, IToGeneric, ITabComplete {
private static final long serialVersionUID = 6150727863411513873L; private static final long serialVersionUID = 6150727863411513873L;
@Override
public List<String> tabComplete(String[] args, String[] chain) {
if (args.length > 0 && chain.length > 0) {
List<String> hints = new ArrayList<String>();
String action = chain[chain.length - 1];
if (action.equalsIgnoreCase(ListConfigValue.ADD)) {
for (EntityType m : EntityType.values()) {
if (m.name().toLowerCase().startsWith(args[0].toLowerCase())) {
hints.add(m.name());
}
}
} else if (action.equalsIgnoreCase(ListConfigValue.REMOVE)) {
for (Blacklisted bl : this) {
if (bl.toString().toLowerCase().startsWith(args[0].toLowerCase())) {
hints.add(bl.toString());
}
}
}
return hints;
}
return null;
}
public static class Blacklisted { public static class Blacklisted {
private String stringRep; private String stringRep;
private EntityType type; private EntityType type;
@ -27,7 +52,7 @@ public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> impl
type = null; type = null;
} }
if (type == null) if (type == null)
type = EntityType.fromName(rep); type = EntityType.valueOf(rep);
try { try {
if (type == null) if (type == null)
type = EntityType.valueOf(rep); type = EntityType.valueOf(rep);
@ -36,7 +61,7 @@ public class BlackListEntity extends ArrayList<BlackListEntity.Blacklisted> impl
} }
if (type == null) if (type == null)
throw new InvalidValueException("Entity '" + stringRep + "' not found"); throw new InvalidValueException("Entity '" + rep + "' not found");
stringRep = rep; stringRep = rep;
} }
public Blacklisted(EntityType et) { public Blacklisted(EntityType et) {

View file

@ -19,7 +19,6 @@ package de.jaschastarke.minecraft.limitedcreative.limits;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Creature; import org.bukkit.entity.Creature;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -53,7 +52,7 @@ public class EntityListener implements Listener {
@EventHandler @EventHandler
public void onEntityDeath(EntityDeathEvent event) { public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntity() instanceof LivingEntity && event.getDroppedExp() > 0) { if (event.getEntity() != null && event.getDroppedExp() > 0) {
if (mod.getNoDropMobs().isXPPrevented(event.getEntity())) { if (mod.getNoDropMobs().isXPPrevented(event.getEntity())) {
event.setDroppedExp(0); event.setDroppedExp(0);
event.getDrops().clear(); event.getDrops().clear();

View file

@ -125,7 +125,7 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
} }
public static enum BlockPickup implements IToGeneric { public enum BlockPickup implements IToGeneric {
PREVENT, PREVENT,
REMOVE; REMOVE;
@ -289,7 +289,7 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
public Object getValue(final IConfigurationNode node) { public Object getValue(final IConfigurationNode node) {
Object val = super.getValue(node); Object val = super.getValue(node);
if (node.getName().equals("pickup") && val == null) { if (node.getName().equals("pickup") && val == null) {
return new Boolean(false); return false;
} else { } else {
return val; return val;
} }

View file

@ -118,16 +118,16 @@ public class NoLimitPermissions extends SimplePermissionContainerNode {
return new InventoryPermission(CHEST, invtype); return new InventoryPermission(CHEST, invtype);
} }
public static IDynamicPermission INTERACT(Block block) { public static IDynamicPermission INTERACT(Block block) {
return new MaterialPermission(BASE_INTERACT, new MaterialData(block.getType(), block.getData())); return new MaterialPermission(BASE_INTERACT, block.getState().getData());
} }
public static IDynamicPermission USE(Block block) { public static IDynamicPermission USE(Block block) {
return new MaterialPermission(BASE_USE, new MaterialData(block.getType(), block.getData())); return new MaterialPermission(BASE_USE, block.getState().getData());
} }
public static IDynamicPermission USE(MaterialData m) { public static IDynamicPermission USE(MaterialData m) {
return new MaterialPermission(BASE_USE, m); return new MaterialPermission(BASE_USE, m);
} }
public static IDynamicPermission BREAK(Block block) { public static IDynamicPermission BREAK(Block block) {
return new MaterialPermission(BASE_BREAK, new MaterialData(block.getType(), block.getData())); return new MaterialPermission(BASE_BREAK, block.getState().getData());
} }

View file

@ -35,13 +35,7 @@ import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.*;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerExpChangeEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.bukkit.material.DirectionalContainer; import org.bukkit.material.DirectionalContainer;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
@ -84,10 +78,12 @@ public class PlayerListener implements Listener {
public void onInventoryOpen(InventoryOpenEvent event) { public void onInventoryOpen(InventoryOpenEvent event) {
if (event.getPlayer() instanceof Player) { if (event.getPlayer() instanceof Player) {
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
if (checkPermission((Player) event.getPlayer(), NoLimitPermissions.INVENTORY(event.getInventory()))) if (!mod.getConfig().getBlockChestInteraction()) {
return; if (checkPermission((Player) event.getPlayer(), NoLimitPermissions.INVENTORY(event.getInventory())))
event.setCancelled(true); return;
((Player) event.getPlayer()).sendMessage(mod.getPlugin().getLocale().trans("blocked.inventory")); event.setCancelled(true);
((Player) event.getPlayer()).sendMessage(mod.getPlugin().getLocale().trans("blocked.inventory"));
}
} }
} }
} }
@ -184,13 +180,11 @@ public class PlayerListener implements Listener {
if (!checkPermission(event, NoLimitPermissions.CHEST)) { if (!checkPermission(event, NoLimitPermissions.CHEST)) {
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.chest")); event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.chest"));
return;
} }
} else if (mod.getConfig().getBlockInteraction().isListed(block)) { } else if (mod.getConfig().getBlockInteraction().isListed(block)) {
if (!checkPermission(event, NoLimitPermissions.INTERACT(block))) { if (!checkPermission(event, NoLimitPermissions.INTERACT(block))) {
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.interact")); event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.interact"));
return;
} }
} }
} }
@ -200,8 +194,8 @@ public class PlayerListener implements Listener {
@EventHandler @EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (!event.isCancelled() && event.getPlayer().getGameMode() == GameMode.CREATIVE) { if (!event.isCancelled() && event.getPlayer().getGameMode() == GameMode.CREATIVE) {
if (mod.getConfig().getBlockUse().isListed(event.getPlayer().getItemInHand())) { if (mod.getConfig().getBlockUse().isListed(event.getPlayer().getInventory().getItemInMainHand())) {
if (!checkPermission(event, NoLimitPermissions.USE(event.getPlayer().getItemInHand().getData()))) { if (!checkPermission(event, NoLimitPermissions.USE(event.getPlayer().getInventory().getItemInMainHand().getData()))) {
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.use")); event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.use"));
return; return;
@ -212,12 +206,16 @@ public class PlayerListener implements Listener {
if (!checkPermission(event, NoLimitPermissions.BASE_INTERACT)) { if (!checkPermission(event, NoLimitPermissions.BASE_INTERACT)) {
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.entity")); event.getPlayer().sendMessage(mod.getPlugin().getLocale().trans("blocked.entity"));
return;
} }
} }
} }
} }
@EventHandler
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
onPlayerInteractEntity(event);
}
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onEntityDamageByEntity(EntityDamageEvent rawevent) { public void onEntityDamageByEntity(EntityDamageEvent rawevent) {
if (rawevent instanceof EntityDamageByEntityEvent && !rawevent.isCancelled()) { if (rawevent instanceof EntityDamageByEntityEvent && !rawevent.isCancelled()) {

View file

@ -82,7 +82,7 @@ public class BlockListener extends Listener {
} }
} else if (diffrent_region) { } else if (diffrent_region) {
// do not build inside of "survial-region in creative world" when outside // do not build inside of "survial-region in creative world" when outside
if (getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE) != null && getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) { if (/*getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE) != null && */getRM().getRegionSet(event.getBlock()).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) {
event.getPlayer().sendMessage(L("blocked.inside_place")); event.getPlayer().sendMessage(L("blocked.inside_place"));
event.setCancelled(true); event.setCancelled(true);
} }

View file

@ -10,7 +10,9 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent; import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
@ -48,7 +50,7 @@ public class PlayerListener extends Listener {
} }
} else if (diffrent_region) { } else if (diffrent_region) {
// do not break inside of "survial-region in creative world" when outside // do not break inside of "survial-region in creative world" when outside
if (getRM().getRegionSet(block).getFlag(Flags.GAMEMODE) != null && getRM().getRegionSet(block).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) { // TODO: Rework if (getRM().getRegionSet(block).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) {
event.getPlayer().sendMessage(L("blocked.inside_interact")); event.getPlayer().sendMessage(L("blocked.inside_interact"));
event.setCancelled(true); event.setCancelled(true);
} }
@ -69,13 +71,41 @@ public class PlayerListener extends Listener {
} }
} else if (diffrent_region) { } else if (diffrent_region) {
// do not break inside of "survial-region in creative world" when outside // do not break inside of "survial-region in creative world" when outside
if (getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE) != null && getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) { if (getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE, event.getPlayer()) != event.getPlayer().getGameMode()) {
event.getPlayer().sendMessage(L("blocked.inside_interact_entity")); event.getPlayer().sendMessage(L("blocked.inside_interact_entity"));
event.setCancelled(true); event.setCancelled(true);
} }
} }
} }
@EventHandler(ignoreCancelled = true)
public void onPlayerDamange(EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof Player) {
PlayerMeta pmeta = new PlayerMeta((Player) event.getDamager());
Location loc = event.getEntity().getLocation();
boolean diffrent_region = getRM().isDiffrentRegion((Player) event.getDamager(), loc);
if (pmeta.isActiveRegionGameMode() && diffrent_region) {
// do not break outside of "gamemod-change-region" when in the region
if (getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE, (Player) event.getDamager()) != pmeta.getActiveRegionGameMode()) {
event.getDamager().sendMessage(L("blocked.outside_interact_entity"));
event.setCancelled(true);
}
} else if (diffrent_region) {
// do not break inside of "survial-region in creative world" when outside
if (getRM().getRegionSet(loc).getFlag(Flags.GAMEMODE, (Player) event.getDamager()) != ((Player) event.getDamager()).getGameMode()) {
event.getDamager().sendMessage(L("blocked.inside_interact_entity"));
event.setCancelled(true);
}
}
}
}
@EventHandler(ignoreCancelled = true)
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
onPlayerInteractEntity(event);
}
private boolean isRegionOptional(Player player) { private boolean isRegionOptional(Player player) {
return mod.getRegionManager().getRegionSet(player.getLocation()).allows(Flags.GAMEMODE_OPTIONAL); return mod.getRegionManager().getRegionSet(player.getLocation()).allows(Flags.GAMEMODE_OPTIONAL);
} }

View file

@ -138,7 +138,7 @@ public class RegionsCommand extends BukkitCommand implements IHelpDescribed {
if (idx > -1 && context.getArgument(idx) != null) if (idx > -1 && context.getArgument(idx) != null)
w = Bukkit.getWorld(context.getArgument(idx)); w = Bukkit.getWorld(context.getArgument(idx));
if (w != null) { if (w != null) {
RegionManager mgr = getWorldGuard().getGlobalRegionManager().get(w); RegionManager mgr = getWorldGuard().getRegionManager(w);
if (mgr != null) { if (mgr != null) {
List<String> hints = new ArrayList<String>(); List<String> hints = new ArrayList<String>();
for (String rId : mgr.getRegions().keySet()) { for (String rId : mgr.getRegions().keySet()) {
@ -174,7 +174,7 @@ public class RegionsCommand extends BukkitCommand implements IHelpDescribed {
if (w == null) if (w == null)
throw new CommandException(L("command.worldguard.world_not_found")); throw new CommandException(L("command.worldguard.world_not_found"));
RegionManager mgr = getWorldGuard().getGlobalRegionManager().get(w); RegionManager mgr = getWorldGuard().getRegionManager(w);
ProtectedRegion region = mgr.getRegion(params.getArgument(0)); ProtectedRegion region = mgr.getRegion(params.getArgument(0));
if (region == null && params.getArgument(0).equalsIgnoreCase("__global__")) { if (region == null && params.getArgument(0).equalsIgnoreCase("__global__")) {
region = new GlobalProtectedRegion(params.getArgument(0)); region = new GlobalProtectedRegion(params.getArgument(0));
@ -247,7 +247,7 @@ public class RegionsCommand extends BukkitCommand implements IHelpDescribed {
} }
} else { } else {
int rpc = params.getArgumentCount() > 1 ? 1 : 0; int rpc = params.getArgumentCount() > 1 ? 1 : 0;
RegionManager mgr = getWorldGuard().getGlobalRegionManager().get(w); RegionManager mgr = getWorldGuard().getRegionManager(w);
region = mgr.getRegion(params.getArgument(rpc)); region = mgr.getRegion(params.getArgument(rpc));
if (region == null && params.getArgument(rpc).equalsIgnoreCase(GLOBAL_REGION)) { if (region == null && params.getArgument(rpc).equalsIgnoreCase(GLOBAL_REGION)) {
region = new GlobalProtectedRegion(params.getArgument(rpc)); region = new GlobalProtectedRegion(params.getArgument(rpc));

View file

@ -22,6 +22,7 @@ import org.bukkit.entity.Player;
import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
public class ApplicableRegions { public class ApplicableRegions {
@ -36,28 +37,28 @@ public class ApplicableRegions {
public boolean allows(StateFlag flag) { public boolean allows(StateFlag flag) {
extendRegionFlags(); extendRegionFlags();
boolean r = regions.allows(flag); boolean r = regions.queryState(null, flag).equals(State.ALLOW);
contractRegionFlags(); contractRegionFlags();
return r; return r;
} }
public boolean allows(StateFlag flag, Player player) { public boolean allows(StateFlag flag, Player player) {
extendRegionFlags(); extendRegionFlags();
boolean r = regions.allows(flag, mgr.getWorldGuard().wrapPlayer(player)); boolean r = regions.queryState(mgr.getWorldGuard().wrapPlayer(player), flag).equals(State.ALLOW);
contractRegionFlags(); contractRegionFlags();
return r; return r;
} }
public <T extends Flag<V>, V> V getFlag(T flag) { public <T extends Flag<V>, V> V getFlag(T flag) {
extendRegionFlags(); extendRegionFlags();
V r = regions.getFlag(flag); V r = regions.queryValue(null, flag);
contractRegionFlags(); contractRegionFlags();
return r; return r;
} }
public <T extends Flag<V>, V> V getFlag(T flag, Player player) { public <T extends Flag<V>, V> V getFlag(T flag, Player player) {
extendRegionFlags(); extendRegionFlags();
V r = regions.getFlag(flag, mgr.getWorldGuard().wrapPlayer(player)); V r = regions.queryValue(mgr.getWorldGuard().wrapPlayer(player), flag);
contractRegionFlags(); contractRegionFlags();
return r; return r;
} }

View file

@ -34,7 +34,6 @@ import org.bukkit.entity.Player;
import com.sk89q.worldguard.bukkit.BukkitUtil; import com.sk89q.worldguard.bukkit.BukkitUtil;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.GlobalRegionManager;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
@ -161,9 +160,6 @@ public class CustomRegionManager {
return ((WorldGuardPlugin) mod.getPlugin().getServer().getPluginManager().getPlugin(WorldGuardIntegration.PLUGIN_NAME)); return ((WorldGuardPlugin) mod.getPlugin().getServer().getPluginManager().getPlugin(WorldGuardIntegration.PLUGIN_NAME));
} }
public GlobalRegionManager getWGGlobalManager() {
return getWorldGuard().getGlobalRegionManager();
}
public RegionManager getWGManager(World world) { public RegionManager getWGManager(World world) {
return getWorldGuard().getRegionManager(world); return getWorldGuard().getRegionManager(world);
} }

View file

@ -17,7 +17,6 @@
*/ */
package de.jaschastarke.minecraft.limitedcreative.regions.worldguard.events; package de.jaschastarke.minecraft.limitedcreative.regions.worldguard.events;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -25,11 +24,11 @@ import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.ApplicableRe
import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.CustomRegionManager; import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.CustomRegionManager;
public class PlayerUpdateAreaEvent extends PlayerAreaEvent { public class PlayerUpdateAreaEvent extends PlayerAreaEvent {
private String player; private Player player;
private String hash; private String hash;
protected CustomRegionManager mgr; protected CustomRegionManager mgr;
public PlayerUpdateAreaEvent(CustomRegionManager mgr, String player, String hash) { public PlayerUpdateAreaEvent(CustomRegionManager mgr, Player player, String hash) {
this.mgr = mgr; this.mgr = mgr;
this.player = player; this.player = player;
this.hash = hash; this.hash = hash;
@ -46,7 +45,7 @@ public class PlayerUpdateAreaEvent extends PlayerAreaEvent {
@Override @Override
public Player getPlayer() { public Player getPlayer() {
return Bukkit.getServer().getPlayerExact(player); return player;
} }
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();

View file

@ -11,6 +11,7 @@ command.regions: LimitedCreative-Region-Command: configure creative regions
command.switch.survival: Changes the game mode of a player to survival command.switch.survival: Changes the game mode of a player to survival
command.switch.creative: Changes the game mode of a player to creative command.switch.creative: Changes the game mode of a player to creative
command.switch.adventure: Changes the game mode of a player to adventure command.switch.adventure: Changes the game mode of a player to adventure
command.switch.spectator: Changes the game mode of a player to spectator
command.config.reload: Reloads configuration and re-initializes all active modules. command.config.reload: Reloads configuration and re-initializes all active modules.
command.config.reload.success: The plugin was successfully reloaded. command.config.reload.success: The plugin was successfully reloaded.
command.gamemode.changed: {0}''s game mode has been changed command.gamemode.changed: {0}''s game mode has been changed

View file

@ -11,6 +11,7 @@ command.regions: LimitedCreative-Region-Kommando: Kreativ-Regionen konfigurieren
command.switch.survival: Ändert den Spielmodus des Spielers zu Überleben command.switch.survival: Ändert den Spielmodus des Spielers zu Überleben
command.switch.creative: Ändert den Spielmodus des Spielers zu Kreativ command.switch.creative: Ändert den Spielmodus des Spielers zu Kreativ
command.switch.adventure: Ändert den Spielmodus des Spielers zu Abenteuer command.switch.adventure: Ändert den Spielmodus des Spielers zu Abenteuer
command.switch.spectator: Ändert den Spielmodus des Spielers zu Beobachter
command.config.reload: Lädt die Konfiguration neu und initialisiert alle Module neu command.config.reload: Lädt die Konfiguration neu und initialisiert alle Module neu
command.config.reload.success: Das Plugin wurde erfolgreich neu geladen command.config.reload.success: Das Plugin wurde erfolgreich neu geladen
command.gamemode.changed: {0}''s GameMode wurde geändert command.gamemode.changed: {0}''s GameMode wurde geändert