Fixed Factions Support, removed the framework

This commit is contained in:
Niels Vergucht 2019-01-12 01:28:39 +01:00
parent 5857dda523
commit e1cfc2f86a
7 changed files with 138 additions and 22 deletions

View File

@ -2,7 +2,7 @@
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>EpicBuckets</artifactId> <artifactId>EpicBuckets</artifactId>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<version>1.4.2</version> <version>1.4.3</version>
<build> <build>
<defaultGoal>clean package</defaultGoal> <defaultGoal>clean package</defaultGoal>
<plugins> <plugins>

View File

@ -0,0 +1,51 @@
package com.songoda.epicbuckets.event;
import com.songoda.epicbuckets.genbucket.Genbucket;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class GenbucketPlaceEvent extends Event implements Cancellable {
private final Player player;
private final Genbucket genbucket;
private boolean isCancelled;
public GenbucketPlaceEvent(Player player, Genbucket genbucket) {
this.player = player;
this.genbucket = genbucket;
this.isCancelled = false;
}
public Player getPlayer() {
return this.player;
}
public Genbucket getGenbucket() {
return this.genbucket;
}
/*
Needed for the event
*/
private static final HandlerList HANDLERS = new HandlerList();
public HandlerList getHandlers() {
return HANDLERS;
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
@Override
public boolean isCancelled() {
return this.isCancelled;
}
@Override
public void setCancelled(boolean b) {
this.isCancelled = b;
}
}

View File

@ -2,6 +2,7 @@ package com.songoda.epicbuckets.listener;
import com.songoda.epicbuckets.EpicBuckets; import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.event.GenbucketPlaceEvent;
import com.songoda.epicbuckets.genbucket.Genbucket; import com.songoda.epicbuckets.genbucket.Genbucket;
import com.songoda.epicbuckets.genbucket.GenbucketType; import com.songoda.epicbuckets.genbucket.GenbucketType;
import com.songoda.epicbuckets.genbucket.types.Horizontal; import com.songoda.epicbuckets.genbucket.types.Horizontal;
@ -39,6 +40,9 @@ public class GenbucketPlaceListener implements Listener {
e.setCancelled(true); e.setCancelled(true);
boolean isInfiniteUse = EpicBuckets.getInstance().getConfigManager().isInfiniteUse();
boolean isInfiniteUseCharge = EpicBuckets.getInstance().getConfigManager().isChargeInfiniteUse();
if (!e.getPlayer().hasPermission("epicbuckets.place")) { if (!e.getPlayer().hasPermission("epicbuckets.place")) {
e.getPlayer().sendMessage(EpicBuckets.getInstance().getLocale().getMessage("event.place.nothere")); e.getPlayer().sendMessage(EpicBuckets.getInstance().getLocale().getMessage("event.place.nothere"));
return; return;
@ -62,7 +66,7 @@ public class GenbucketPlaceListener implements Listener {
Genbucket genbucket = null; Genbucket genbucket = null;
switch(GenbucketType.valueOf(nbtItem.getString("Type"))) { switch (GenbucketType.valueOf(nbtItem.getString("Type"))) {
case PSUEDO: case PSUEDO:
genbucket = new PsuedoVertical(e.getPlayer(), e.getClickedBlock(), e.getBlockFace(), EpicBuckets.getInstance().getShopManager().getShop(nbtItem.getString("Shop")).getSubShop(nbtItem.getString("SubShop"))); genbucket = new PsuedoVertical(e.getPlayer(), e.getClickedBlock(), e.getBlockFace(), EpicBuckets.getInstance().getShopManager().getShop(nbtItem.getString("Shop")).getSubShop(nbtItem.getString("SubShop")));
break; break;
@ -85,7 +89,24 @@ public class GenbucketPlaceListener implements Listener {
return; return;
} }
if (e.getPlayer().getGameMode() != GameMode.CREATIVE && !EpicBuckets.getInstance().getConfigManager().isInfiniteUse()) { double infiniteUseCost = EpicBuckets.getInstance().getConfigManager().getInfiniteUseCostForGenbucketType(genbucket.getGenbucketType(), genbucket.getGenItem());
if (isInfiniteUse && isInfiniteUseCharge && EpicBuckets.getInstance().getEcon().getBalance(Bukkit.getOfflinePlayer(e.getPlayer().getUniqueId())) < infiniteUseCost) {
e.getPlayer().sendMessage(EpicBuckets.getInstance().getLocale().getMessage("event.genbucket.infiniteuse.notenough"));
return;
}
/*
Call event and check if cancelled before proceeding to start the gen and charging the player
*/
GenbucketPlaceEvent placeEvent = new GenbucketPlaceEvent(e.getPlayer(), genbucket);
Bukkit.getPluginManager().callEvent(placeEvent);
if (placeEvent.isCancelled()) return;
/*
Subtract bucket from players inventory
*/
if (e.getPlayer().getGameMode() != GameMode.CREATIVE && !isInfiniteUse) {
if (e.getItem().getAmount() > 1) { if (e.getItem().getAmount() > 1) {
e.getItem().setAmount(e.getItem().getAmount() - 1); e.getItem().setAmount(e.getItem().getAmount() - 1);
} else { } else {
@ -93,15 +114,12 @@ public class GenbucketPlaceListener implements Listener {
} }
} }
if (EpicBuckets.getInstance().getConfigManager().isInfiniteUse() && EpicBuckets.getInstance().getConfigManager().isChargeInfiniteUse()) { /*
if (EpicBuckets.getInstance().getEcon().getBalance(Bukkit.getOfflinePlayer(e.getPlayer().getUniqueId())) < EpicBuckets.getInstance().getConfigManager().getInfiniteUseCostForGenbucketType(genbucket.getGenbucketType(), genbucket.getGenItem())) { Charge for infinite use placement
e.getPlayer().sendMessage(EpicBuckets.getInstance().getLocale().getMessage("event.genbucket.infiniteuse.notenough")); */
return; if (isInfiniteUse && isInfiniteUseCharge && infiniteUseCost > 0) {
} EpicBuckets.getInstance().getEcon().withdrawPlayer(Bukkit.getOfflinePlayer(e.getPlayer().getUniqueId()), infiniteUseCost);
if (EpicBuckets.getInstance().getConfigManager().getInfiniteUseCostForGenbucketType(genbucket.getGenbucketType(), genbucket.getGenItem()) > 0) { e.getPlayer().sendMessage(EpicBuckets.getInstance().getLocale().getMessage("event.genbucket.infiniteuse.charge").replace("%charge%", infiniteUseCost + ""));
EpicBuckets.getInstance().getEcon().withdrawPlayer(Bukkit.getOfflinePlayer(e.getPlayer().getUniqueId()), EpicBuckets.getInstance().getConfigManager().getInfiniteUseCostForGenbucketType(genbucket.getGenbucketType(), genbucket.getGenItem()));
e.getPlayer().sendMessage(EpicBuckets.getInstance().getLocale().getMessage("event.genbucket.infiniteuse.charge").replace("%charge%", EpicBuckets.getInstance().getConfigManager().getInfiniteUseCostForGenbucketType(genbucket.getGenbucketType(), genbucket.getGenItem()) + ""));
}
} }
EpicBuckets.getInstance().getGenbucketManager().registerGenbucketForPlayer(e.getPlayer(), genbucket); EpicBuckets.getInstance().getGenbucketManager().registerGenbucketForPlayer(e.getPlayer(), genbucket);

View File

@ -0,0 +1,22 @@
package com.songoda.epicbuckets.regionhandler;
import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.FactionColl;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.ps.PS;
import com.songoda.epicbuckets.EpicBuckets;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class FactionsMassive {
public static boolean check(Player player, Location location) {
/*
If wilderness
*/
if (BoardColl.get().getFactionAt(PS.valueOf(location)) == FactionColl.get().getNone()) return EpicBuckets.getInstance().getConfigManager().isGensInWilderness();
return MPlayer.get(player).isInOwnTerritory();
}
}

View File

@ -0,0 +1,23 @@
package com.songoda.epicbuckets.regionhandler;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.songoda.epicbuckets.EpicBuckets;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class FactionsSavage {
public static boolean check(Player player, Location location) {
Faction f;
f = Board.getInstance().getFactionAt(new FLocation(location));
if (f == null) return EpicBuckets.getInstance().getConfigManager().isGensInWilderness();
if (FPlayers.getInstance().getByPlayer(player).getFaction() == null) return false;
return FPlayers.getInstance().getByPlayer(player).getFaction().getTag().equals(f.getTag());
}
}

View File

@ -1,9 +1,6 @@
package com.songoda.epicbuckets.regionhandler; package com.songoda.epicbuckets.regionhandler;
import com.songoda.epicbuckets.EpicBuckets; import com.songoda.epicbuckets.EpicBuckets;
import me.markeh.factionsframework.entities.FPlayers;
import me.markeh.factionsframework.entities.Faction;
import me.markeh.factionsframework.entities.Factions;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -12,13 +9,18 @@ public class RegionFactions {
public static boolean canBuild(Player player, Location location) { public static boolean canBuild(Player player, Location location) {
if (!EpicBuckets.getInstance().getConfigManager().isSupportFactions()) return true; if (!EpicBuckets.getInstance().getConfigManager().isSupportFactions()) return true;
Faction f = Factions.getFactionAt(location); if (EpicBuckets.getInstance().getDescription().getAuthors().contains("Drtshock")) {
/*
FactionsUUID and his clones/forks/whatever
*/
return FactionsSavage.check(player, location);
} else {
/*
Massive
*/
return FactionsMassive.check(player, location);
}
if (f.isNone()) return EpicBuckets.getInstance().getConfigManager().isGensInWilderness();
if (FPlayers.getBySender(player).getFaction().isNone()) return false;
if (FPlayers.getBySender(player).getFaction().getId().equals(f.getId())) return true;
return false;
} }
} }

View File

@ -1,5 +1,5 @@
name: EpicBuckets name: EpicBuckets
version: 1.4.2 version: 1.4.3
description: Generate walls fast and efficient with beautiful guis! description: Generate walls fast and efficient with beautiful guis!
author: Songoda author: Songoda
main: com.songoda.epicbuckets.EpicBuckets main: com.songoda.epicbuckets.EpicBuckets