some metadata implementation for blocking drops of creative placed

blocks
This commit is contained in:
Jascha Starke 2012-03-03 11:02:15 +01:00
parent 69786772f7
commit ba44d72609
6 changed files with 198 additions and 3 deletions

View file

@ -121,6 +121,9 @@ limit:
break:
- bedrock
blocks:
enabled: true
region:
# RegionsEnabled
# Enables the Feature for "creative-regions". This Feature is automatically disabled, if the required plugin

View file

@ -25,8 +25,10 @@ import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import de.jaschastarke.minecraft.integration.Communicator;
import de.jaschastarke.minecraft.limitedcreative.listeners.CreativeBlockListener;
import de.jaschastarke.minecraft.limitedcreative.listeners.GenericListener;
import de.jaschastarke.minecraft.limitedcreative.listeners.LimitListener;
import de.jaschastarke.minecraft.limitedcreative.listeners.MainListener;
import de.jaschastarke.minecraft.limitedcreative.listeners.InventoryStoreListener;
import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration;
import de.jaschastarke.minecraft.utils.Locale;
import de.jaschastarke.minecraft.utils.Permissions;
@ -73,7 +75,9 @@ public class Core extends JavaPlugin {
warn(L("basic.conflict", "MultiInv", L("basic.feature.store")));
config.setTempStoreEnabled(false);
}
getServer().getPluginManager().registerEvents(new MainListener(this), this);
getServer().getPluginManager().registerEvents(new InventoryStoreListener(this), this);
getServer().getPluginManager().registerEvents(new GenericListener(this), this);
getServer().getPluginManager().registerEvents(new CreativeBlockListener(this), this);
// 2nd Feature: Creative Limitations (Restrictions)
if (config.getLimitEnabled())

View file

@ -0,0 +1,66 @@
/*
* Limited Creative - (Bukkit Plugin)
* Copyright (C) 2012 jascha@ja-s.de
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.jaschastarke.minecraft.limitedcreative.listeners;
import java.util.List;
import org.bukkit.GameMode;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import de.jaschastarke.minecraft.limitedcreative.Core;
public class CreativeBlockListener implements Listener {
private Core plugin;
public CreativeBlockListener(Core plugin) {
this.plugin = plugin;
}
@EventHandler(ignoreCancelled=true)
public void onBlockBreak(BlockBreakEvent event) {
if (event.getPlayer().getGameMode() != GameMode.CREATIVE) {
if (event.getBlock().hasMetadata("created_gamemode")) {
List<MetadataValue> metadata = event.getBlock().getMetadata("created_gamemode");
for (MetadataValue m : metadata) {
if (m.getOwningPlugin().equals(plugin)) {
if (GameMode.valueOf(m.asString()) == GameMode.CREATIVE) {
plugin.spawnblock.block(event.getBlock());
}
}
}
}
}
}
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onBlockPlace(BlockPlaceEvent event) {
MetadataValue test = new FixedMetadataValue(plugin, event.getPlayer().getGameMode().name());
Core.debug("test: " + test.value().toString() + " - " + test.asString());
event.getBlock().setMetadata("created_by", new FixedMetadataValue(plugin, event.getPlayer().getName()));
event.getBlock().setMetadata("created_gamemode", new FixedMetadataValue(plugin, event.getPlayer().getGameMode().name()));
event.getBlock().setMetadata("created_at", new FixedMetadataValue(plugin, System.currentTimeMillis()));
Core.debug(event.getBlock() + ": metadata created_gamemode: " + event.getBlock().getMetadata("created_gamemode").get(0).value().toString());
}
}

View file

@ -0,0 +1,68 @@
/*
* Limited Creative - (Bukkit Plugin)
* Copyright (C) 2012 jascha@ja-s.de
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.jaschastarke.minecraft.limitedcreative.listeners;
import org.bukkit.entity.Item;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import de.jaschastarke.minecraft.limitedcreative.Core;
import de.jaschastarke.minecraft.limitedcreative.Players;
public class GenericListener implements Listener {
private Core plugin;
public GenericListener(Core plugin) {
this.plugin = plugin;
}
/**
* Needed by 3 of 4 features.
* - Creative Limits
* - Creative Blocks in Survival
* - Regions
*/
@EventHandler
public void onItemSpawn(ItemSpawnEvent event) {
if (event.isCancelled())
return;
if (event.getEntity() instanceof Item) {
if (plugin.spawnblock.isBlocked(event.getLocation().getBlock().getLocation(), ((Item) event.getEntity()).getItemStack().getType())) {
event.setCancelled(true);
}
}
}
public void onLogout(PlayerQuitEvent event) {
// what? i can't cancel a logout event? but how to chain the user to the server than? xD
Players.remove(event.getPlayer().getName());
}
/**
* The isCancelled in PlayerInteractEvent doesn't check useItemInHand, even this decides (when clicking on
* entity with e.g. a bucket)
* @param event
* @return The relevant "isCancelled"
*/
public static boolean isCancelled(PlayerInteractEvent event) {
return event.useInteractedBlock() == Event.Result.DENY && event.useItemInHand() == Event.Result.DENY;
}
}

View file

@ -0,0 +1,54 @@
/*
* Limited Creative - (Bukkit Plugin)
* Copyright (C) 2012 jascha@ja-s.de
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.jaschastarke.minecraft.limitedcreative.listeners;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import de.jaschastarke.minecraft.limitedcreative.Core;
import de.jaschastarke.minecraft.limitedcreative.Players;
public class InventoryStoreListener implements Listener {
private Core plugin;
public InventoryStoreListener(Core plugin) {
this.plugin = plugin;
}
@EventHandler
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
if (Core.isDebug()) {
Core.debug("onPlayerGameModeChange: "+event.getPlayer().getName());
Core.debug("Current GameMode: "+event.getPlayer().getGameMode());
Core.debug("New GameMode: "+event.getNewGameMode());
Core.debug("isLoggedin: "+plugin.com.isLoggedIn(event.getPlayer()));
Core.debug("isCancelled: "+event.isCancelled());
}
if (!plugin.com.isLoggedIn(event.getPlayer()))
return;
if (!Players.get(event.getPlayer()).onSetGameMode(event.getNewGameMode()))
event.setCancelled(true);
}
@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent event) {
Players.get(event.getPlayer()).onRevive();
}
}

View file

@ -72,7 +72,7 @@ public class LimitListener implements Listener {
@EventHandler(priority=EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent event) {
if (MainListener.isCancelled(event) || event.getPlayer().getGameMode() != GameMode.CREATIVE)
if (GenericListener.isCancelled(event) || event.getPlayer().getGameMode() != GameMode.CREATIVE)
return;
LCPlayer player = Players.get(event.getPlayer());