• Es freut uns dass du in unser Minecraft Forum gefunden hast. Hier kannst du mit über 130.000 Minecraft Fans über Minecraft diskutieren, Fragen stellen und anderen helfen. In diesem Minecraft Forum kannst du auch nach Teammitgliedern, Administratoren, Moderatoren , Supporter oder Sponsoren suchen. Gerne kannst du im Offtopic Bereich unseres Minecraft Forums auch über nicht Minecraft spezifische Themen reden. Wir hoffen dir gefällt es in unserem Minecraft Forum!

Regions abbauen vermeiden

ThrustLP

Redstoneengineer
Registriert
3 April 2013
Beiträge
35
Diamanten
0
Ich weiß einen ähnlichen Thread hatte ich bereits, aber dieser hier ist aufgeräumter. Der andere Beitrag kann gelöscht werden (wenn nötig)! Also:

Ich habe die HashMap:

Code:
public HashMap<String, Region> regions = new HashMap<String, Region>();

In dieser sind Regionen gespeichert die im onEnable Teil aus einer Yaml Datei geladen werden. Hier mal mein onEnable:

Code:
	@Override
	public void onEnable(){
		System.out.println("[Jumper] GELADEN");
		this.getCommand("jumper").setExecutor(new InfoCommand());
		this.getCommand("jarena").setExecutor(new RegionCommand(this));
		
		PluginManager pm = this.getServer().getPluginManager();
		pm.registerEvents(new RegionListener(this), this);
		
		
		
		File file = new File("plugins/Jumper", "arenas.yml");
		FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
		for(String region : cfg.getConfigurationSection("").getKeys(false)){
			
			this.getConfig().addDefault("allgemein.consolemessagestart", new String[]{
					"§aGELADEN"
					
			});
			this.getConfig().options().copyDefaults(true);
			this.saveConfig();
			
			String world = cfg.getString(region + ".world");
			
			World w = Bukkit.getWorld(world);
			
			if(w != null){
				
				int minx = cfg.getInt(region + ".minx");
				int miny = cfg.getInt(region + ".miny");
				int minz = cfg.getInt(region + ".minz");
				
				int maxx = cfg.getInt(region + ".maxx");
				int maxy = cfg.getInt(region + ".maxy");
				int maxz = cfg.getInt(region + ".maxz");
			
				this.regions.put(region.toLowerCase(), new Region(new Location(w, minx, miny, minz), new Location(w, maxx, maxy, maxz)));
			}
			
			
			
		}
	}

Nun möchte ich in einem BlockBreakEvent folgendes:

Wenn ein Player einen Block der sich innerhalb einer dieser Regionen befindet abbaut soll die Aktion zurückgesetzt werden. Achtung: Auch wenn er außerhalb der Region steht soll er die Blöcke innen nicht abbauen können.

Kann mir jemand einen Code dazu geben? Ich bin noch Anfänger, und habe mir da wohl etwas zu viel vorgenommen, aber den weitern Teil des Plugins schaffe ich dann wieder ;)

Vielen Dank!

Hier meine Klasse Region:

Code:
package me.thrustlp.jumper.region;

import java.util.HashMap;
import java.util.Map;

import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.serialization.ConfigurationSerializable;

public class Region implements ConfigurationSerializable{

	private int minx, miny, minz;
	private int maxx, maxy, maxz;
	private World world;
	public Region(Location loc1, Location loc2){
		
		this.minx = Math.min(loc1.getBlockX(), loc2.getBlockX());
		this.miny = Math.min(loc1.getBlockY(), loc2.getBlockY());
		this.minz = Math.min(loc1.getBlockZ(), loc2.getBlockZ());
		
		this.maxx = Math.max(loc1.getBlockX(), loc2.getBlockX());
		this.maxy = Math.max(loc1.getBlockY(), loc2.getBlockY());
		this.maxz = Math.max(loc1.getBlockZ(), loc2.getBlockZ());
		
		this.world = loc1.getWorld();
		
	}
	public boolean isInside(Location loc){
		if(loc.getWorld() != this.world){
			return false;
		}
		if(loc.getBlockX() < this.minx || loc.getBlockX() > this.maxx || loc.getBlockY() < this.miny || loc.getBlockY() > this.maxy || loc.getBlockZ() < this.minz || loc.getBlockZ() > this.maxz){
			return false;
		}
		
		return true;
	}
	
	@Override
	public Map<String, Object> serialize() {
		Map<String, Object> o = new HashMap<String, Object>();
		
		o.put("minx", this.minx);
		o.put("miny", this.miny);
		o.put("minz", this.minz);
		
		o.put("maxx", this.maxx);
		o.put("maxy", this.maxy);
		o.put("maxz", this.maxz);
		
		o.put("world", this.world.getName());
		return o;
	}
	
	
	
}
 
Zuletzt bearbeitet von einem Moderator:
Oben